feat(v3): express extensions:"x-nullable" as a standard type union#2202
Open
kklem0 wants to merge 1 commit into
Open
feat(v3): express extensions:"x-nullable" as a standard type union#2202kklem0 wants to merge 1 commit into
kklem0 wants to merge 1 commit into
Conversation
OpenAPI 3.1 removed the `nullable` keyword; the standard way to declare a nullable property is the type union ["<type>", "null"], and typed client generators ignore vendor extensions. Convert a truthy x-nullable from the extensions struct tag into the union (and drop the extension) so nullability from annotations survives into the generated v3.1 spec. A negated !x-nullable keeps its extension form, since non-nullable is already the default. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Adds a way for annotation-declared nullability to reach the OpenAPI 3.1 output (see umbrella issue).
OpenAPI 3.1 removed the
nullablekeyword; the standard expression is the type union["<type>", "null"], and typed-client generators ignore vendor extensions. Previouslyextensions:"x-nullable"survived only as anx-nullable: trueextension, so there was no way to mark a property nullable in the generated 3.1 spec.With this PR:
{"type": ["string", "null"]}A negated
!x-nullablekeeps its extension form (non-nullable is already the default). This intentionally changes the extension passthrough behavior for truthyx-nullable; the existingExtensions tagtest is updated accordingly, andTestComplementSchemaNullableExtensionV3covers union conversion, negation, and preservation of other extensions.Validated on a production codebase: 181 nullable properties now render as standard type unions, matching our swag v1 + swagger2openapi (OpenAPI 3.0
nullable: true) pipeline one-for-one.