[release/10.0] Handle DescriptionAttribute for nullable value types in OpenAPI generation - #67051
Conversation
Improve OpenApiSchemaService to retrieve DescriptionAttribute from underlying types, enabling correct descriptions for enums and nullable enums. Expand tests to cover these scenarios and verify schema descriptions. Standardize HelixContent formatting in project files.
Co-authored-by: Youssef Fahmy <youssefvictor00@gmail.com>
Co-authored-by: Youssef Fahmy <youssefvictor00@gmail.com>
|
Thanks to whoever made the backport bot add the servicing template as part of the PR description automatically :) Drafting for now until I fill the template later on Monday. |
|
Hi @github-actions[bot]. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
DescriptionAttribute for nullable value types in OpenAPI generation
There was a problem hiding this comment.
Pull request overview
This backport fixes OpenAPI schema generation so DescriptionAttribute applied to enum types is honored even when the enum is used via Nullable<T> (e.g., MyEnum?), restoring missing description fields in generated OpenAPI documents.
Changes:
- Unwrap nullable value types before reading
DescriptionAttributewhen generating schema descriptions. - Expand request body schema tests to cover enum/property/type description scenarios, including nullable enums.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs | Updates schema generation to read DescriptionAttribute from the underlying type for nullable value types. |
| src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.RequestBodySchemas.cs | Adds/extends tests asserting enum/type/property descriptions, including nullable enum coverage. |
|
Approved via email. |
Backport of #65245 to release/10.0
/cc @Youssef1313 @rdeveen
Handle
DescriptionAttributefor nullable value types in OpenAPI generationFixes missing description in OpenAPI document for nullable enums.
Description
This PR handles DescriptionAttribute correctly when generating OpenAPI documents when processing
Nullable<T>whereTis an enum that hasDescriptionAttribute, which was previously ignored.Fixes #65067
Customer Impact
Customer reported in #65067. While this appears to have been broken since the beginning, there are certain scenarios where it could have worked by chance (when two APIs are declared, and one uses
Nullable<Enum>while the other usesEnum). For those scenarios that worked by chance, this is seen by users as a regression (and user report is reporting it as a regression).Regression?
Technically no, but from user perspective, it could be if they fall in the "worked by chance" scenario. The working version in this case is Microsoft.AspNetCore.OpenApi 10.0.1 and the broken version is 10.0.2
Risk
Low. The change is very well-scoped and simply unwraps nullable value types before retrieving DescriptionAttribute.
Verification
Test is added
Packaging changes reviewed?
N/A