Our Create User endpoint does not accept any parameters, but it does require a JSON payload that conforms to our User schema. Therefore, we should add a new requestBody field inside our Operation Object to define this requirement.
The value of the requestBody field should contain three fields:
- description: A short description of the payload.
- content(object): This specifies the valid MIME types (for example, application/json, text/plain) that are acceptable for this endpoint, as well as the expected structure of the payload. This structure is defined under the MIME type property, under a sub-property called schema, and is very similar to the JSON schema syntax, represented as YAML.
- required (boolean): This specifies whether the request payload is required:
paths:
/users:
post:
...
requestBody:
description: The New User object
required: true
content:
application/json:
schema:
properties:
email:
type: string
format: email
digest:
type: string
pattern: ^\\$2[aby]?\\$\\d{1,2}\\$[.\\/A-Za-z0-9]{53}$
profile:
type: object
properties:
bio:
type: string
summary:
type: string
name:
type: object
properties:
first:
type: string
last:
type: string
middle:
type: string
additionalProperties: false
additionalProperties: false
required:
- digest
example:
email: e@ma.il
digest: $2a$10$enCaroMp4gMvEmvCe4EuP.0d5FZ6yc0yUuSJ0pQTt4EO5MXvonUTm
profile:
bio: Daniel is a species of JavaScript developer that is commonly found in Hong Kong and London. In 2015, Daniel opened his own digital agency called Brew, which specialized in the Meteor framework.
summary: JavaScript Developer
name:
first: Daniel
last: Li