我正在寻找有关我的Open API 3.0规范的建议,这是我的用户架构对象的示例。我希望以某种方式使某些字段成为可选字段,但是我不确定如何定义它们。
当我将完整规格粘贴到https://editor.swagger.io中时,它将在“试用”功能中显示所有内容。其他一些模型较大,因此删除所有相关字段可能非常麻烦,也许它们可能显示fieldName:{},所以您知道它们可用吗?我不确定应该如何处理。
此架构对象用于POST,PUT和GET作为$ ref对象,我正尝试使其尽可能保持DRY。
也许还值得注意的是,由于工具尚无法正常工作(或者可能是我的规范),我将最终生成的结果转换为swagger 2.0,以生成Swift 4和Angular Typescript库。
另外值得注意的是,我通过使用包含查询字符串参数将api称为这些额外字段,例如 users?includes = person,person.telephone,createdByUser,repStats等...所以我只希望它们包含在GET请求中。
请参阅下面的注释字段。
User:
type: object
properties:
uuid:
type: string
username:
type: string
password:
type: string
format: password
email:
type: string
personUuid:
type: string
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
deletedAt:
type: string
format: date-time
createdByUuid:
type: string
updatedByUuid:
type: string
# Relations.
# I want these read only and optional on GET requests.
# They can be there on PUT/POST requests, the server will simply
# ignore them.
person:
$ref: '#/components/schemas/Person'
createdByUser:
$ref: '#/components/schemas/User'
updatedByUser:
$ref: '#/components/schemas/User'
repStats:
$ref: '#/components/schemas/RepStats'