Reading OpenAPI/Swagger Schemas
5 exercises on reading OpenAPI/Swagger schemas — required vs optional fields, types, enums, nullable values, $ref and constraints.
Key patterns
required: [...]lists mandatory fields;propertiesalone does not mean requiredenum= a closed whitelist of allowed values$ref: "#/components/schemas/X"points to a reusable schema in the same filenullable: truemeansnullis allowed; constraints likeminItems/minLengthare enforced
0 / 5 completed
1 / 5
Read this OpenAPI request-body schema:
CreateUser:
type: object
required:
- email
- password
properties:
email:
type: string
format: email
password:
type: string
minLength: 8
displayName:
type: stringAccording to the schema, which field is optional when creating a user?Only fields listed under
In OpenAPI/JSON Schema, a field appearing in
required are mandatory.In OpenAPI/JSON Schema, a field appearing in
properties is allowed, but it is only required if its name is in the object's required array.required: [email, password]→ those two must be sent.displayNameis defined underpropertiesbut absent fromrequired→ it is optional.
properties is mandatory. It is not. Note the supporting constraints: format: email hints the string must be a valid email, and minLength: 8 enforces a minimum password length. The phrase to internalise: "required vs optional is governed by the required list, not by the property list".