Skip to content

OpenAPI doesn't support stream parameters #59770

Closed as duplicate of#56021
Closed as duplicate of#56021
@rmannibucau

Description

@rmannibucau

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions