Skip to content

fix: Ensure OpenAPI request bodies include (#59042)#64859

Open
AbdelrahmanHassan131 wants to merge 7 commits into
dotnet:mainfrom
AbdelrahmanHassan131:fix/openapi-bug
Open

fix: Ensure OpenAPI request bodies include (#59042)#64859
AbdelrahmanHassan131 wants to merge 7 commits into
dotnet:mainfrom
AbdelrahmanHassan131:fix/openapi-bug

Conversation

@AbdelrahmanHassan131

Copy link
Copy Markdown

DescriptionAttribute for [FromForm] parameters and add verification tests.

fix: Ensure OpenAPI request bodies include (#59042)

Fixes caching of OpenApiOperationTransformerContext to prevent exceptions in OpenAPI document generation.

Description

Corrected caching logic for OpenApiOperationTransformerContext in OpenApiDocumentService.

Ensured transformer contexts are properly initialized and stored in _operationTransformerContextCache.

Added handling for operation metadata to avoid cache misses.

Verified with all existing unit and integration tests for OpenAPI document generation.

Fixes #59042

`DescriptionAttribute` for `[FromForm]` parameters and add verification tests.
@github-actions github-actions Bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Dec 23, 2025
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Dec 23, 2025
@AbdelrahmanHassan131

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@desjoerd desjoerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.

I've added a few comments, could you take a look at them? 😊

{
parameterSchema = new OpenApiSchema
{
Description = parameterDescription,

@desjoerd desjoerd Dec 24, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is added because it will be componetized (and a $ref) you can set the description on the final $ref via the metadata x-ref-description. Or is there another reason? As this would change the output to emit an allOf.

{
propSchema = new OpenApiSchema
{
Description = parameterDescription,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

{
propSchema = new OpenApiSchema
{
Description = parameterDescription,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

using Microsoft.AspNetCore.OpenApi;
using Microsoft.Extensions.DependencyInjection;

public class ReproduceIssue59042Tests : OpenApiDocumentServiceTestBase

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these tests would best fit in OpenApiDocumentServiceTests.Parameters.cs

@desjoerd desjoerd added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Dec 24, 2025
@AbdelrahmanHassan131

Copy link
Copy Markdown
Author

This change was not added specifically for componentization. The goal is to preserve the description in the generated schema output without relying on ref metadata.

I also followed your suggestion: for componentized schemas emitted as $ref, the description is now stored in Metadata using x-ref-description. This avoids introducing an unnecessary allOf while preserving the description.

Additionally, I moved the related unit test to OpenApiDocumentServiceTests.Parameters.cs as you recommended.

The implementation should now behave as intended, but I’m happy to adjust further if needed.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jan 2, 2026
@desjoerd

desjoerd commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Looks good to me!

@captainsafia could you review this PR as well? :)

@AbdelrahmanHassan131

Copy link
Copy Markdown
Author

Hi @captainsafia , just checking in to see if there's any additional information or changes needed on my end to move this forward or it needs more than what i did so to close the PR.

Thanks for your time and effort!

@mikekistler

Copy link
Copy Markdown
Contributor

Reassigning to @halter73

@mikekistler mikekistler requested review from halter73 and removed request for captainsafia February 15, 2026 16:36
@AbdelrahmanHassan131

Copy link
Copy Markdown
Author

Hi @halter73 , just checking in to see if there's any additional information or changes needed on my end to move this forward or it needs more than what i did so to close the PR.

Thanks for your time and effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc community-contribution Indicates that the PR has been added by a community member feature-openapi pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

description is missing when using with FromForm

3 participants