Repository navigation
Support the openapi-3.0 target in Schema.toStandardJSONSchemaV1 - #11355
Open
MichaelDeBoey wants to merge 3 commits into
Open
MichaelDeBoey wants to merge 3 commits into
MichaelDeBoey wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: ce2bdbd The changes in this PR will be included in the next version bump. This PR includes changesets to release 43 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
UI Bundle SizeVite 8.4.0/Rolldown, production, default Oxc minification, es2023, ES modules, gzip level 9 per chunk. effect 4.2.0, Node v26.12.1. Effect-only client: 27325 B gzip (Δ 0 B vs base).
|
effect-bot
force-pushed
the
v4/next-minor
branch
from
December 2, 2026 19:38
210ffce to
f4a9b34
Compare
effect-bot
force-pushed
the
v4/next-minor
branch
26 times, most recently
from
December 3, 2026 02:10
6c238bc to
7d60609
Compare
effect-bot
force-pushed
the
v4/next-minor
branch
21 times, most recently
from
December 3, 2026 08:30
53431e4 to
8a22a76
Compare
Co-authored-by: Effect Bot <tech-ops@effectful.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
effect-bot
force-pushed
the
v4/next-minor
branch
from
December 3, 2026 10:00
8a22a76 to
3706211
Compare
MichaelDeBoey
force-pushed
the
feat/openapi-3-0-standard-json-schema
branch
2 times, most recently
from
December 3, 2026 10:59
511d3a4 to
ce2bdbd
Compare
effect-bot
force-pushed
the
v4/next-minor
branch
2 times, most recently
from
December 3, 2026 14:35
c1d5e42 to
3149d8e
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #10123, now with a consumer that handles referenced schemas.
Schema.toStandardJSONSchemaV1throwsUnsupported target: openapi-3.0for the third target the Standard JSON Schema spec names.toBaseStandardJSONSchemaV1now converts the draft 2020-12 document to an OpenAPI 3.0.3 Schema Object for this target, for bothinputandoutput:Why it's worth having
#10123 was declined because the integration it showed only covered inline schemas, and references needed consumer changes.
@nestjs/swaggeralready makes those changes. Its Standard Schema converter asks every vendor fortarget: "openapi-3.0", since it builds OpenAPI 3.0.0 documents, then moves the returneddefinitionsintocomponents.schemasand points the$refs there (normalizeConvertedSchema). Since@nestjs/swagger12.1.0 it also reads function-shaped schemas (nestjs/swagger#4230), which is whatSchema.toStandardJSONSchemaV1returns.With this branch and
@nestjs/swagger@12.1.3, Effect schemas give an OpenAPI 3.0.0 document that passesoas-validator@5.0.8without any extra code, with every$refresolving tocomponents.schemas, aszod@4.6.7does there: a named property, one schema shared by two properties and across endpoints, recursive and mutually recursive named schemas, and a named root.On
v4/next-minor,@nestjs/swaggerlogsSkipping a "effect" standard schema that could not be converted to OpenAPI 3.0 (Unsupported target: openapi-3.0)and documents the body asObject, without a response schema. AdonisJS's@foadonis/openapiasks for the same target.On bundle size, measured with
packages/tools/bundle(Rollup, minified, gzipped):v4/next-minorSchema.toJsonSchemaDocumentSchema.toStandardJSONSchemaV1,draft-2020-12targetCode that doesn't call
Schema.toStandardJSONSchemaV1doesn't change. Code that does carries every target, since the target is only known wheninput()oroutput()is called, as it already carries thedraft-07branch.Conversion
The conversion is a new internal
JsonSchema.toStandaloneOpenApi3_0, an adapter on top of the existing Draft-04 one, soconstbecomes a single-valueenumand exclusive bounds use the boolean form, asJsonSchema.toDocumentDraft04already does. On top of that:$schema: not written, since a Schema Object has none. OpenAPI 3.0 identifies the dialect through the document'sopenapifield rather than per schema.definitionswith#/definitions/...references, as in thedraft-07branch. 3.0 has neither$defsnordefinitions, so a consumer moves them tocomponents/schemaseither way, as@nestjs/swaggerdoes.zodwrites the same for this target.examples: the first one becomesexample.null: 3.0 has no"null"type. A{ type: "null" }branch of ananyOfbecomesnullable: trueon the first branch with a singletype, andnullis added to that branch'senum, if it has one. When annotations are the only siblings, the remaining branch replaces theanyOf. Since 3.0.3,nullableonly applies next totype, and it would also letnullthrough keywords likeallOf,notor$ref. So when no branch qualifies, as inNullOrof a schema with an identifier,nullis kept as a{ enum: [null] }branch, whichJsonSchema.fromSchemaOpenApi3_0reads back unchanged.typearrays are split the same way.itemsmust be a single schema, soprefixItemsthrowsCannot convert JSON Schema keyword "prefixItems" to OpenAPI 3.0. This follows how the other converters treat keywords the target can't represent, instead of approximating withitems: { anyOf }like some other libraries.$anchor,$id,dependentRequired,dependentSchemasandpatternPropertiesthrow the same way.The converter isn't public. A public
JsonSchema.toMultiDocumentOpenApi3_0would reference#/components/schemas/<name>, asJsonSchema.Documentdescribes for OpenAPI 3.0, and could reuse the internaltoMultiDocumentComponentsthatJsonSchema.toMultiDocumentOpenApi3_1uses for key sanitization on top of the same adapter.New tests in
toStandardJSONSchemaV1.test.tscoverinputandoutput, a nullable string, literal, union and reference,null, a literal, exclusive bounds, definitions, a tuple, and that other targets still throw.JsonSchema.test.tscovers the converter directly, includingtypearrays, enums, siblings and rejected keywords. 24 of the new tests fail without the change.Validation
pnpm vitest run --project effect packages/effect/test/schema packages/effect/test/JsonSchema.test.ts(2,838 tests passed)pnpm lintpnpm check@nestjs/swagger@12.1.3document and bundle sizes abovecc @gcanti