Skip to content

Conversation

@AbdelrahmanHassan131
Copy link

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
Author

@dotnet-policy-service agree

Copy link
Contributor

@desjoerd desjoerd left a comment

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,
Copy link
Contributor

@desjoerd desjoerd Dec 24, 2025

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
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
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
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
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
Copy link
Contributor

desjoerd commented Jan 6, 2026

Looks good to me!

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

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

2 participants