Swagger 如何根据http方法要求字段?
我正在尝试编写一个usingswagger,但我面临一些问题,因为一些字段是必需的,或者不需要,这取决于所使用的方法 以下是更新规格中的一行 资源对象必须包含类型和id成员 这里有一个来自“创建规格” 资源对象必须至少包含一个类型成员 所以现在我有Swagger 如何根据http方法要求字段?,swagger,swagger-2.0,Swagger,Swagger 2.0,我正在尝试编写一个usingswagger,但我面临一些问题,因为一些字段是必需的,或者不需要,这取决于所使用的方法 以下是更新规格中的一行 资源对象必须包含类型和id成员 这里有一个来自“创建规格” 资源对象必须至少包含一个类型成员 所以现在我有 Customer: title: Customer type: object required: ["id", "type"] properties: id: type: string
Customer:
title: Customer
type: object
required: ["id", "type"]
properties:
id:
type: string
type:
type: string
attributes:
type: object
properties:
name:
type: string
address:
type: string
我想做的是为
patch
方法设置required:[“id”,“type”]
,但只有required:[“type”]
为post
方法。是否可以在不重新定义其他客户的情况下执行此操作 您可以使用以下方法实现:
Customer:
title: Customer
type: object
required:
- type
properties:
id:
type: string
type:
type: string
attributes:
type: object
properties:
name:
type: string
address:
type: string
Customer_patch:
type: object
required:
- id
allOf:
- $ref: '#/definitions/Customer'
您必须重新定义另一个客户以放置其他必填字段,但您可以重新使用实际的客户定义对象。这一问题现在还没有解决吗?当然,在+1附近进行此工作是可行的,但目前还不理想。