-
Notifications
You must be signed in to change notification settings - Fork 678
Best Practices on Resource Definitions
-
Use nouns instead of verbs in resource paths.
Example :/users,/ordersinstead of/getUser,/createOrder -
Use lowercase letters in resource names.
Example :/client-certificatesinstead of/ClientCertificates -
Use hyphens (
-) to separate words in compound resource names.
Example :/change-requestsinstead of/change_requests,/changerequests
Use the appropriate HTTP method based on the nature of the operation:
| Method | Purpose |
|---|---|
| GET | Retrieve resources |
| POST | Create new resources |
| PUT | Update existing resources |
| DELETE | Remove resources |
| PATCH | Partially update resources |
- Define structured and descriptive request/response bodies.
- Reuse definitions using
$refto promote consistency and avoid duplication.
Example:
responses:
200:
description: |
OK. Change request list is returned.
content:
application/json:
schema:
$ref: '#/components/schemas/ChangeRequestList'
404:
$ref: '#/components/responses/NotFound'
500:
$ref: '#/components/responses/InternalServerError'Use appropriate status codes:
-
2xx: Successful responses -
4xx: Client errors (e.g.,400 Bad Request,401 Unauthorized,404 Not Found) -
5xx: Server errors (e.g.,500 Internal Server Error,503 Service Unavailable)
Use JSON Schema composition keywords to simplify definitions:
-
oneOf: Exactly one schema must match -
anyOf: At least one schema must match -
allOf: Combines multiple schemas -
not: Negate a schema
Example:
allOf:
- $ref: '#/components/schemas/BaseResource'
- type: object
properties:
additionalField:
type: stringUse appropriate status codes:
-
2xx: Successful responses -
4xx: Client errors (e.g.,400 Bad Request,401 Unauthorized,404 Not Found) -
5xx: Server errors (e.g.,500 Internal Server Error,503 Service Unavailable)
Use JSON Schema composition keywords to simplify definitions:
-
oneOf: Exactly one schema must match -
anyOf: At least one schema must match -
allOf: Combines multiple schemas -
not: Negate a schema
Example:
allOf:
- $ref: '#/components/schemas/BaseResource'
- type: object
properties:
additionalField:
type: stringDefine security requirements at the resource level to enforce authorization. Use relevant OAuth2 scopes to control access based on user roles or permissions.
Example:
security:
- OAuth2Security:
- apim:api_view
- apim:api_manage
- apim:client_certificates_view
- apim:client_certificates_manageUse tags to group and categorize related resources in the API documentation