Consumes attribute/filter in controller-based app can produce inaccurate OpenAPI doc
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] 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_
Contributor guide
Research direction
Start by reproducing the issue in a controller-based API app with a Consumes attribute for application/octet-stream and no matching input formatter. Trace how the generated OpenAPI request-body content is determined and how model binding handles the request. Done means the document no longer advertises a content type that the application rejects, with coverage for the reported scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100