API-11Recommended
Use enums for fixed values
Give every field with a fixed set of values an enum in the contract, and document what each value means.
How to do it
Use stable lowercase strings, such as "pending" and "shipped". Tell clients to treat an unknown value as a safe default, because you may add values later. This rule is Recommended because a contract must stay open to new values. Inside your code, enums are required, as use enums instead of magic strings says.
How to check
Every status or type field in the OpenAPI file has enum, and a client test with an unknown value does not crash.
Sources
Related rules
- ARC-56 Use enums instead of magic strings in Clean code and architecture
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/requests-and-responses/api-enums">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.