Repository navigation
Fix handling of get-only non-nullable properties in OpenAPI schema generation - #66584
marcominerva wants to merge 2 commits into
Conversation
|
Thanks for your PR, @marcominerva. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Pull request overview
This PR updates ASP.NET Core's OpenAPI schema generation so nullable reference type handling better reflects get-only properties, addressing incorrect nullable output in generated schemas.
Changes:
- Adjusts property nullability inference in
JsonNodeSchemaExtensionsto stop treating get-only non-nullable properties as nullable. - Changes
ShouldApplyNullablePropertySchemato prefer read-state for get-only properties. - Adds a regression test covering get-only primitive/collection properties in request-body schema generation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/OpenApi/src/Extensions/TypeExtensions.cs |
Updates nullable-property detection logic for property schemas. |
src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs |
Refines schema nullability application and null-type cleanup for properties. |
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.PropertySchemas.cs |
Adds a regression test for get-only property nullability behavior. |
mikekistler
left a comment
There was a problem hiding this comment.
Looks good! 👍
Thanks for this fix.
|
Hi @mikekistler! Since this PR has been approved, do you think it can be merged? |
|
Sorry that we missed this PR for long. The linked issue is now closed and seems to be fixed by a different PR. Hence, I'm closing this PR. Sorry again that we haven't observed your PR earlier. |
This pull request improves how nullable reference types are handled in OpenAPI schema generation, ensuring that get-only non-nullable properties are not incorrectly marked as nullable in the generated schemas. The changes include updates to the logic for determining property nullability and add new tests to verify the correct behavior.
Nullability handling improvements:
ApplyNullabilityContextInfoinJsonNodeSchemaExtensions.csto ensure that get-only non-nullable properties are not marked as nullable, and to only consider setter nullability if a setter exists. Also, removed the redundant check fortypeof(object)in the componentization logic.ShouldApplyNullablePropertySchemainTypeExtensions.csto use the property's read-state for get-only properties, ensuring correct nullability detection for properties without setters.Testing enhancements:
GetOpenApiSchema_GetOnlyNonNullableProperties_NotMarkedNullableinOpenApiSchemaService.PropertySchemas.csto verify that get-only non-nullable properties are not marked as nullable, while get-only nullable properties are correctly marked. Introduced a supporting model class for the test.Fixes #58192