Enums
You can use the enum
keyword to specify possible values of a request parameter or a model property. For example, the sort parameter in GET /items?sort=[asc|desc]
can be described as:
In YAML, you can also specify one enum value per line:
All values in an enum must adhere to the specified type
. If you need to specify descriptions for enum items, you can do this in the description
of the parameter or property:
Nullable enums
A nullable enum can be defined as follows:
Note that null
must be explicitly included in the list of enum
values. Using nullable: true
alone is not enough here.
Reusable enums
In OpenAPI 3.0, both operation parameters and data models use a schema
, making it easy to reuse the data types. You can define reusable enums in the global components
section and reference them via $ref
elsewhere.
Did not find what you were looking for? Ask the community
Found a mistake? Let us know