Repository navigation
fix: resolve nullable oneOf to the referenced type - #246
Merged
Merged
Conversation
ASP.NET Core 10 emits nullable reference properties in OpenAPI 3.1 as
oneOf: [{ type: null }, { $ref }]. ResolveOneOf only handled a single
variant, so these properties became object?. Apply the same
single-non-null-variant rule that anyOf already uses.
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.
Summary
ASP.NET Core 10 emits a nullable reference property in OpenAPI 3.1 as a
oneOfofnulland a$ref:ResolveOneOfonly handled a single variant, so this becameobject?.ResolveAnyOfalready handled the[type, null]pattern. Both now share one helper:The nullability rules in
type-mapping.mdnow list this pattern.Complements #150, which hoists unions with two or more non-null variants. That PR filters out
nullbefore hoisting, so[null, $ref]still reachesResolveOneOfand becomesobjectthere. The new test fails on #150 too.Evidence
New test
Generate_FromText_OneOfNullAndRef_GeneratesNullableReference, using the spec above:Not found: "public Customer? Customer { get; init; }"(generatedpublic object? Customer)After: passes, with no
OrderCustomerunion hoisted, and the output compiles with warnings as errors.dotnet testpasses for the whole solution.Merge Danger
Door: two-way
Blast Radius: generated-types
Consumers whose specs use
oneOf: [null, X]getX?instead ofobject?when they regenerate. That is a type change in generated code, but it replaces a placeholder with the intended type. AoneOfwith two or more non-null variants is unchanged.