You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Swagger描述无名称的JSON格式查询参数?

问题描述

我有一个响应POST请求的API端点,其查询参数为URL编码后的JSON字符串,格式示例如下:

json_string = '{"items": [{"name": "chicken", "quantity": 1, "basePrice": 499, "priceWithModifiers": 499}, {"name": "soda", "quantity": 1, "basePrice": 399, "priceWithModifiers": 399}], "salesTax": {"id": "T8JKFEVBE6F30", "name": "Sales Tax", "rate": 900000, "isDefault": true}, "orderType": {"id": "ZJQ5ND5FZAAVP", "taxable": true, "isDefault": true, "filterCategories": false, "isHidden": false, "hoursAvailable": "BUSINESS", "isDeleted": false}}'

完整URL格式为 endpoint/?{json_string}——即JSON字符串经URL编码后直接跟在?之后,不需要指定参数键名。

我尝试通过content -> application/json -> schema将该参数描述为字符串,但由于必须指定参数名称,生成的查询参数中总会多出一个多余的=(比如变成endpoint/?paramName={json_string})。我不想重写这个API本身。

生成这类查询字符串的示例代码:

  • JavaScript:
const my_dict = {"items": [5,6,7], "SalesTax": {"id": "foobar"}, "orderType": {"id": "Takeout"}}
query_param = JSON.stringify(my_dict)
  • Python:
import json
my_dict = {"items": [5,6,7], "SalesTax": {"id": "foobar"}, "orderType": {"id": "Takeout"}}
query_param = json.dumps(my_dict)

内容的提问来源于stack exchange,提问作者davetherock

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 16:03:37