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.
This PR updates the deserializers to translate incoming
nullable
andx-nullable
properties to theOpenApiSchema.Type
property. And then translate back into separate properties in the V2/V3 serializers, preserving the same ordering as in the current 1.x versions.I chose this approach to avoid having multiple versions of the truth internally. For example, a V2 document may be loaded that contains
x-nullable: true
, then theOpenApiSchema.Type
is modified from user code, and the file is written back. It would be unexpected to have the presence ofx-nullable: true
in the original document override theOpenApiSchema.Type
change from code. I'm assuming that consumers upgrading to v2.x are going to manipulate theOpenApiSchema.Type
property to add/remove nullability, and then write out the version as configured (which is an implementation detail).But for backwards compatibility, the presence of
x-nullable
in theOpenApiSchema
is still taken into account, in case it gets explicitly added by user code.The only downside is that we lose the relative position of
x-nullable: true
if multiple extensions are used. I believe this to be an acceptable tradeoff.Furthermore, this PR simplifies and optimizes the logic to write the schema type. When writing V2/V3, multiple non-null types still result in not writing the type constraint. Writing nullability in V2/V3 is handled separately from writing the schema type.
Tests are added to verify
nullable
/x-nullable
with/without a schema type round-trip in V2/V3.Fixes #2342, fixes #2344.