假设我有一个用户模型定义:id,first_name,last_name,created_at,我在swagger中有一个对象定义。
创建用户的POST请求需要first_name和last_name。我怎么会大摇大摆呢? Swagger期望单个对象我应该为此创建一个新对象吗?
答案 0 :(得分:1)
怎么样
myuser:
allOf:
- $ref: '#/definitions/myuserbase'
- type: object
properties:
id:
description: |
Unique identifier for the classifier.
type: string
example: user1
created_at:
description: |
Date and time the user was created.
type: string
format: date-time
required:
- id
和
myuserbase:
type: object
properties:
first_name:
description: |
First name of the user
type: string
last_name:
description: |
Last name of the user
type: string
required:
- first_name
- last_name
答案 1 :(得分:0)
您可以将first_name
,last_name
标记为必填字段。这是一个例子:
required:
- first_name
- last_name
(换句话说,不需要创建单独的对象)