Below is an API *.yml section. I want to set the response header for the data to be Content-type: text/plain
, but it always returns application/json
now.
/order:
post:
tags:
- order
summary: order
operationId: PostOrder
parameters:
requestBody:
description: Order result
content:
application/json:
schema:
type: object
properties:
openReq:
type: string
example: 'test'
responses:
200:
description: Customer order receive successed
headers: {}
content:
application/json:
schema:
type: string
text/plain:
schema:
type: string
The response is returned by this python code:
def post_order(platform, open_req=None): # noqa: E501
"""order
"""
return 'do some magic!'
The response header is always content-type: application/json
responses:
200:
description: Customer order receive successed
headers: {}
content:
application/json:
schema:
type: string
text/plain:
schema:
type: string
This response header for this snippet is always content-type: text/plain; charset=utf-8
responses:
200:
description: Customer order receive successed
headers: {}
content:
# application/json:
# schema:
# type: string
text/plain:
schema:
type: string
Can I set the response header content type in function post_order
?
Maybe you are confusing the API Swagger Docs with the actual implementation, your documentation is correct, it means the response
200 OK
, can return asapplication/json
ortext/plain
. Which one is returned depends solely on your implementation of the endpoint. If your endpoint only returnsapplication/json
, then you will never receivetext/plain
, that is not Swagger/OpenApi's Job.