Best Practices
API Design Guidelines
Well-designed APIs are easy to use, document, and maintain. Follow these best practices to create OpenAPI specs that developers love.
Principles
- • Consistency - Use the same patterns throughout
- • Clarity - Make intentions obvious
- • Completeness - Document all behaviors
- • Discoverability - Help users explore your API
Naming Conventions
Paths: Use Kebab-Case Nouns
Good
Avoid
Schemas: Use PascalCase Nouns
Good
Avoid
Properties: Use camelCase
Good
Avoid
Operation IDs: Use Verb + Noun
Good
Avoid
Resource Design
Use Standard HTTP Methods
| Method | Usage | Example | Response |
|---|---|---|---|
| GET | Read resource(s) | GET /users | 200, 404 |
| POST | Create resource | POST /users | 201, 400 |
| PUT | Replace resource | PUT /users/{id} | 200, 404 |
| PATCH | Partial update | PATCH /users/{id} | 200, 404 |
| DELETE | Remove resource | DELETE /users/{id} | 204, 404 |
Use Hierarchical Paths for Relationships
Documentation Standards
Always Include These Fields
Document All Parameters
Provide Examples
Error Handling
Use Consistent Error Responses
400
Bad Request
401
Unauthorized
403
Forbidden
404
Not Found
Security Best Practices
Define Security at the Right Level
Use global security for the default, override per-operation only when needed.
Document All Auth Methods
Include descriptions for security schemes explaining how to obtain credentials.
Use Specific Scopes
Prefer fine-grained scopes (read:users, write:users) over broad ones (admin).
Mark Public Endpoints Explicitly
Use security: [] to clearly indicate no auth required.
Schema Design
Separate Create/Update/Response Schemas
Use readOnly/writeOnly
Mark Required Fields
API Versioning
URL Path (Recommended)
Clear, visible, easy to route
Header
Clean URLs, harder to test
Query Parameter
Easy override, clutters URLs
Quick Checklist
Before Publishing
Quality Checks