我正在使用Swagger Codegen启动REST服务。对于不同的参数,我需要有不同的响应。
示例:<baseURL>/path可以使用?filter1=或?filter2=,并且这些参数应产生不同的响应消息。
我希望我的OpenAPI YAML文件分别记录这两个查询参数。这可能吗?
如果您仍在寻找,我找到了解决此问题的方法。这有点像黑客,但它确实有效。
基本上,您可以通过在 URL 中添加斜杠 (/) 对同一路径进行两个定义。
这样,您可以<baseURL>/path使用该参数设置一个响应,并使用该参数?filter1=设置另一个响应。为每个定义提供唯一的值也很重要。<baseURL>//path?filter2=operationId
paths:
/path/you/want:
get:
summary: Test
operationId: get1
parameters:
- name: filter1
type: string
in: path
required: true
responses:
200:
description: Successful response
schema:
$ref: '#/definitions/SomeResponse'
/path/you//want:
get:
summary: Another test
operationId: get2
parameters:
- name: filter2
type: string
in: path
required: true
responses:
200:
description: Successful response
schema:
$ref: '#/definitions/SomeOtherResponse'
Run Code Online (Sandbox Code Playgroud)
我用路径参数尝试了这个,效果很好!
| 归档时间: |
|
| 查看次数: |
2249 次 |
| 最近记录: |