Swagger 是否有任何可能的方法在参数发生变化时多次定义同一路径?
我需要定义一个在参数发生变化时多次使用的服务。我需要多次定义这个服务,但每当我第二次定义它时,它就会自动覆盖上一次。 以下是我对它的定义。这是第一个定义:Swagger 是否有任何可能的方法在参数发生变化时多次定义同一路径?,swagger,swagger-2.0,swagger-editor,Swagger,Swagger 2.0,Swagger Editor,我需要定义一个在参数发生变化时多次使用的服务。我需要多次定义这个服务,但每当我第二次定义它时,它就会自动覆盖上一次。 以下是我对它的定义。这是第一个定义: /sevice : post: summary: Service ABC description: | This service is used to get ABC. parameters: - name: XYZ in: query
/sevice :
post:
summary: Service ABC
description: |
This service is used to get ABC.
parameters:
- name: XYZ
in: query
description: '8'
required: true
type: number
format: integer
- name: LMN
in: query
description: '2'
required: true
type: number
format: integer
tags:
- ABC
responses:
'200':
description: An array of products
schema:
type: array
items:
$ref: '#/definitions/ABC'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
/sevice :
post:
summary: Service ABC
description: |
This service is used to remove ABC.
parameters:
- in: body
name: jsonData
description: Object that needs to be sended to the store.
required: true
schema:
$ref: '#/definitions/PQR'
tags:
- ABC
responses:
'200':
description: An array of products
schema:
type: array
items:
$ref: '#/definitions/LMN'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
这是第二个定义:
/sevice :
post:
summary: Service ABC
description: |
This service is used to get ABC.
parameters:
- name: XYZ
in: query
description: '8'
required: true
type: number
format: integer
- name: LMN
in: query
description: '2'
required: true
type: number
format: integer
tags:
- ABC
responses:
'200':
description: An array of products
schema:
type: array
items:
$ref: '#/definitions/ABC'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
/sevice :
post:
summary: Service ABC
description: |
This service is used to remove ABC.
parameters:
- in: body
name: jsonData
description: Object that needs to be sended to the store.
required: true
schema:
$ref: '#/definitions/PQR'
tags:
- ABC
responses:
'200':
description: An array of products
schema:
type: array
items:
$ref: '#/definitions/LMN'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
同一路径是否可能在一个API规范中多次出现?不,不可能。我尝试过这样做,但在检查时会出现重复错误,因为我的API是基于Swagger定义构建的。我的建议是为该服务的目的在路径后面附加一个名称,例如定义one/service/get或/service/delete 另外,我看到您的第二个定义旨在删除资源,而您的第一个定义是获取资源。您可以使用DELETE-HTTP方法创建第二个,使用GET-HTTP方法创建第一个,并将这两个定义组合在一起。这样,您的路径是相同的,可以执行不同的HTTP函数。是可以使用的所有HTTP方法选项的列表。POST通常用于创建一个全新的资源 这个问题是OpenAPI的Github上的一个公开问题(标记为182)
我希望这有帮助 从OpenAPI 2.0和3.0开始,这是不可能的。OpenAPI规范存储库中的相关功能请求:。