Describing enums
When an API operation includes an enum, you can addx-enumDescriptions to provide more context about each option. GitBook will display the enum values and their descriptions in a table next to the operation.
Why describe enums
Enum values are often abbreviated or use technical naming conventions that aren’t immediately clear to API consumers. Adding descriptions helps users understand:- What each value represents
- When to use each option
- The difference between similar values
- Business logic or workflows associated with each value
Adding enum descriptions
Use thex-enumDescriptions extension in your schema definition:
openapi.yaml
Complete example
Here’s a more detailed example showing enum descriptions in context:openapi.yaml
Reusable enum schemas
For enums used in multiple places, define them as reusable schemas:openapi.yaml
Defining enums as reusable schemas with
$ref ensures consistent descriptions across your entire API documentation.Inline enum descriptions
You can also add enum descriptions directly in path parameters or request bodies:openapi.yaml
Integer and number enums
Enum descriptions work with any enum type, not just strings:openapi.yaml
Best practices
1
Always describe enums
Add descriptions to all enum values, even if they seem self-explanatory. What’s obvious to you may not be clear to API consumers.
2
Be consistent
Use consistent language and structure across all enum descriptions in your API.
3
Explain transitions
For status enums, explain what triggers transitions between states and what actions are valid in each state.
4
Include examples when helpful
For complex enums, consider adding examples in the description to clarify usage.
5
Keep descriptions concise
Aim for one or two clear sentences. If you need more explanation, add it to the overall schema description.