Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI doesn't support stream parameters #59770

Open
1 task done
rmannibucau opened this issue Jan 8, 2025 · 0 comments
Open
1 task done

OpenAPI doesn't support stream parameters #59770

rmannibucau opened this issue Jan 8, 2025 · 0 comments
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-openapi

Comments

@rmannibucau
Copy link

rmannibucau commented Jan 8, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Microsoft.AspNetCore.OpenApi.OpenApiSchemaStore prepopulate the Stream schema (note that it doesn't use the latest openapi representation but that would be an enhancement) but the key uses parameterinfo (set to null by default) so the getoradd in the store fails cause when using [FromBody] Stream body there is a parameter info.

Note that setting Stream as metadata to avoid to have a parameter fails in Microsoft.AspNetCore.OpenApi.OpenApiSchemaService.GetOrCreateSchemaAsync cause there is an api description so it still tries to lookup a JsonTypeInfo.

TIP: using this code can workaround the issue in an ugly manner:

[JsonSourceGenerationOptions]
[JsonSerializable(typeof(Stream))] // make GetOrCreateSchemaAsync happy (ApplyParameterInfo)
public partial class OpenApiWorkaroundForStream : JsonSerializerContext;

builder.Services.ConfigureHttpJsonOptions(o => o
            .SerializerOptions
            .TypeInfoResolverChain
            .Add(OpenApiWorkaroundForStream.Default));

        app
            .MapPost(....)
            .WithMetadata(new AcceptsMetadata(["application/octect-stream"], typeof(Stream))); // no param so hardcoded schema is used

Expected Behavior

The Stream schema is looked up as expected

Steps To Reproduce

use an minimal api endpoint with request body in parameters

Exceptions (if any)

No response

.NET Version

9

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jan 8, 2025
@martincostello martincostello added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Jan 8, 2025
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 feature-openapi
Projects
None yet
Development

No branches or pull requests

2 participants