IApiRequestMetadataProvider not respected and still add application/*+json content type.
- 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
IApiResponseMetadataProvider respect the provided content type in SetContentTypes.
IApiRequestMetadataProvider always add application/*+json content event if it's not provided in SetContentTypes.
### Expected Behavior
application/*+json should not be added if it's not provided in IApiRequestMetadataProvider SetContentTypes
### Steps To Reproduce
Create an atttribute implementing IApiRequestMetadataProvider like this
`[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class TestConsumesAttribute : Attribute, IApiRequestMetadataProvider
{
private readonly MediaTypeCollection _contentTypes;
public TestConsumesAttribute(string contentType)
{
_contentTypes = new MediaTypeCollection { contentType };
}
void IApiRequestMetadataProvider.SetContentTypes(MediaTypeCollection contentTypes)
{
contentTypes.Clear();
foreach (var contentType in _contentTypes)
{
contentTypes.Add(contentType);
}
}
}`
Add swagger gen and put the attibute on a controller with "application/json" media type and an input model.
You can see that application/*+json is always added.
Using the consume attribute application/*+json will not be added.
Be the interface itself should be enough to set the mediatype values.
### Exceptions (if any)
_No response_
### .NET Version
8
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.