Custom json media types - How to modify "Response schema" in generated API schema #3085
-
The endpoints of my app (whose specifications were not up to me) has custom json content types. These endpoints have names like "application/vnd.message+json". They are json encoded but in addition there is a json schema (represented in my case by pydantic models) which defines the structure of the json data. The only way I found to have these custom media types in the "Content-Type" response header was to simply add it manually to the header kwarg in the Response object. However, in the schema generated at "/schema", I just see "Response schema: application/json" everywhere, and the content-type headers are listed as "string". How can I get the generated schema to show my custom json media types? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
These lines:
suggest that the media type must be "application/json". Note sure why it uses "startswith". In my experience, json-encoded media-types are more commonly in the format "application/+json", for example: https://webconcepts.info/concepts/media-type/application/problem+json When I pass in It seems like the problem I have is the restriction that the media type must start with "application/json". To me, this restriction would make more sense as either being "application/json" OR starting with "application/" and ending with "+json". |
Beta Was this translation helpful? Give feedback.
I created #3088