【发布时间】:2025-11-27 10:20:17
【问题描述】:
以下是 API *.yml 部分。我想将数据的响应头设置为Content-type: text/plain,但它现在总是返回application/json。
/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
此python代码返回响应:
def post_order(platform, open_req=None): # noqa: E501
"""order
"""
return 'do some magic!'
响应头总是content-type: application/json
responses:
200:
description: Customer order receive successed
headers: {}
content:
application/json:
schema:
type: string
text/plain:
schema:
type: string
这个 sn-p 的这个响应头总是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
我可以在函数post_order中设置响应头内容类型吗?
【问题讨论】:
-
你的定义是有效的。您能否更详细地解释问题是什么以及何时发生?即使客户端请求
text/plain,您的 API 服务器是否总是返回 JSON?还是别的什么?