Skip to content

Consumes attribute/filter in controller-based app can produce inaccurate OpenAPI doc #57684

@mikekistler

Description

@mikekistler

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

A Consumes attribute/filter in controller-based app that specifies a content type without input formatter will produce operation in the generated OpenAPI document with an "application/json" content entry, but this is incorrect because the content filter will cause a request with "application/json" content to fail with a 415 status code.

Expected Behavior

I think the operation request body should not have an "application/json" content entry, since this will fail. As it turns out, so will a request with the content-type from the consumes, since model binding will reject it. Perhaps the best result here would be an analyzer that flagged this error at build time.

Steps To Reproduce

In a controller based API app, define an action method with a Consumes attribute for "application/octet-stream" but don't define an input formatter for this type.

Exceptions (if any)

No response

.NET Version

9.0.100-preview.7.24407.12

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-openapi

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions