Reputation: 3575
Let's say I have a user model defined with: id, first_name, last_name, created_at, and I have an object definition for it in swagger.
A POST request to create a user would expect first_name and last_name. How would I write that in swagger? Swagger expects a single object for the Should I create a new object just for the that?
Upvotes: 0
Views: 490
Reputation: 305
How about
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
and
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
Upvotes: 1
Reputation: 10807
You can mark first_name
, last_name
as the required fields. Here is an example:
required:
- first_name
- last_name
(in other words, no need to create a separate object)
Upvotes: 0