Repository navigation
fix(openapi): emit OpenAPI 3.1 schemas instead of 3.0 ones - #63
Merged
Merged
Conversation
Request bodies and query parameters were converted with zod's openapi-3.0 target, although every
builder documents its output as OpenAPI 3.1. Under 3.1 that output is misread: `nullable: true` is
ignored, so a validator rejects null where the schema allows it, and a boolean `exclusiveMinimum`
fails the meta-schema. Conversions now use JSON Schema 2020-12, which OpenAPI 3.1 builds on,
without the root `$schema` the conversion adds.
Resource and relationship `type` fields are written as `const` rather than a single-value `enum`,
matching what the conversion emits for literals.
Specs generated with this version change shape: literals become `const`, nullable primitives
`type: [..., "null"]` and other nullable schemas an `anyOf` with `{ type: "null" }`, exclusive
bounds numbers, tuples `prefixItems`, and extracted definitions move from `definitions` to `$defs`.
Snapshot tests of a generated spec need updating, and request body and query parameter output no
longer fits an OpenAPI 3.0 document.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #63 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 29 30 +1
Lines 4049 4058 +9
Branches 405 406 +1
=========================================
+ Hits 4049 4058 +9
🚀 New features to boost your workflow:
|
Merged
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.
Request bodies and query parameters were converted with zod's openapi-3.0 target, although every
builder documents its output as OpenAPI 3.1. Under 3.1 that output is misread:
nullable: trueisignored, so a validator rejects null where the schema allows it, and a boolean
exclusiveMinimumfails the meta-schema. Conversions now use JSON Schema 2020-12, which OpenAPI 3.1 builds on,
without the root
$schemathe conversion adds.Resource and relationship
typefields are written asconstrather than a single-valueenum,matching what the conversion emits for literals.
Specs generated with this version change shape: literals become
const, nullable primitivestype: [..., "null"]and other nullable schemas ananyOfwith{ type: "null" }, exclusivebounds numbers, tuples
prefixItems, and extracted definitions move fromdefinitionsto$defs.Snapshot tests of a generated spec need updating, and request body and query parameter output no
longer fits an OpenAPI 3.0 document.
Refs to
$defsstill break once a schema is embedded; that predates this change and is tracked in #62.