[QUESTION] how can I remove the media type from the main response
See original GitHub issueDescription
How can I remove the media type from the main response?
@router.delete("/topics/{topic}",
summary="Delete topic",
response_class=None,
responses={
200: {"description": "Topic successfully deleted"},
404: {"description": "Topic not found"}
})
async def delete_topic(topic):
"""
Delete a topic with all of it's entries
"""
deleted = await delete_topic(topic)
if not deleted:
return Response(status_code=404)
return
In this example the open-api documentation will show no media type for the 404 response, but it will show application/json for the 200 response. How can I remove that. My response body is always empty.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Remove a media type from a controller method - Stack Overflow
1 Answer 1 ... You could use a ResultFilterAttribute and override the OnResultExecuted method which is triggered right after the action gets ...
Read more >Media Types - Swagger
Media type is a format of a request or response body data. Web service operations can accept and return data in different formats,...
Read more >MIME types (IANA media types) - HTTP - MDN Web Docs
MIME types are case-insensitive but are traditionally written in lowercase. The parameter values can be case-sensitive.
Read more >ASP.NET Web API: Media-Type Formatters - TutorialsTeacher
Media type formatters are the classes responsible for serializing request/response data so that Web API can understand the request data format and send...
Read more >Additional Responses in OpenAPI - FastAPI - tiangolo
You can use this same responses parameter to add different media types for the same main response. For example, you can add an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for your answer. But if I do it like this
the documentaion still shows
And if I change
response_class
toresponse_class=Response
I get “AssertionError: A response class with media_type is needed to generate OpenAPI”You now can use
response_class=Response
, I’m not sure since which version 🤷 (we are now on version0.54.1
).But this seems to work as you expected: