Skip to content

Commit 89f5e73

Browse files
authored
docs: Api standards doc
1 parent f049670 commit 89f5e73

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed

docs/api-standards.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
2+
# RHOAS OpenAPI Standards
3+
4+
This document is intended as a collaborative document to agree and define standards for the design of RHOAS OpenAPI specifications.
5+
6+
This document is not intended as a replacement for https://github.com/redhat-developer/app-services-api-guidelines tooling/linter.
7+
8+
9+
## Versioning
10+
11+
12+
13+
* Set the version number in the _info.version_ field.
14+
* The version should follow [Semantic Versioning](https://semver.org/).
15+
* A **MAJOR** version change is required when you make incompatible API changes.
16+
* Removal of an endpoint.
17+
* Changes to an endpoint URI structure.
18+
* Modifying a schema object such as a request or response payload object.
19+
* Removal of a query parameter.
20+
* Making a non-required parameter required.
21+
* Modifying a field name.
22+
* Modifying authorization.
23+
* Introducing rate-limiting.
24+
* Removal of a field
25+
* Addition of a required field in the request object
26+
* Addition of validation that was not present before
27+
* A **MINOR **version change is required when an additive change is made to the OpenAPI document.
28+
* Adding an endpoint.
29+
* Adding optional query parameters.
30+
* Adding optional fields to a schema used in a request payload.
31+
* Adding a response field.
32+
* A **PATCH **version change is required when a change which fixes broken functionality of the schema.
33+
* Invalid reference to a schema object
34+
* Typo in a property such as a tag
35+
* Errors in the document itself, such as a string that is not closed.
36+
* A pre-release extension may be added to indicate that the API version is unstable. For example: 2.0.0-alpha1.
37+
* APIs must not expose the minor or patch version in the API URL.
38+
* For releases which have alpha or beta stability the API **must** append the stability level after the major version using _[Channel-based versioning](https://cloud.google.com/apis/design/versioning). _For example: **v1beta**, **v2alpha**.
39+
* All resource endpoints must include the channel version; `/v1`, `/v2`, `v2beta` etc.
40+
* /api/srs_mgmt/v1/registries
41+
* /api/kafka_mgmt/v1/kafkas
42+
* /api/kafka_mgmt/v2beta/kafkas
43+
* The name of the OpenAPI file should include the version using the following format: \
44+
“${service_or_api_name}.{yaml | json}”. Some examples:
45+
* kas-fleet-manager.yaml
46+
* srs-fleet-manager.json
47+
* kafka-admin-api.yaml
48+
49+
50+
## Rules
51+
52+
53+
54+
* Should use OpenAPI v3+
55+
* `info.license` must be Apache 2.0
56+
* Every endpoint must have an _operationId_ specified.
57+
* The `servers` config array is required for control plane APIs and should look as follows: \
58+
59+
60+
```yaml
61+
servers:
62+
- url: https://api.openshift.com
63+
description: Main (production) server
64+
- url: https://api.stage.openshift.com
65+
description: Staging server
66+
- url: http://localhost:8000
67+
description: localhost
68+
- url: /
69+
description: current domain
70+
```
71+
72+
73+
* Examples should be provided where possible/appropriate for documentation purposes.
74+
75+
76+
## Naming
77+
78+
79+
### API Paths
80+
81+
API endpoints should use _snake_case _for word separation.
82+
83+
Examples:
84+
85+
* /cloud_providers/..
86+
* /service_accounts/../reset_credentials
87+
88+
89+
### Fields
90+
91+
Fields should use _snake_case_ for word separation.
92+
93+
Examples:
94+
95+
* cloud_provider_region
96+
* bootstrap_server_host
97+
98+
99+
### Operations
100+
101+
The **operationId **will be used to name methods in the API clients. As such, changes to the names should be treated as breaking changes, and so we should be careful and explicit with our naming of them.
102+
103+
104+
* **get{Resource}By{Argument} **- get a single Resource
105+
* getKafkaById
106+
* getRegistryById
107+
* getServiceAccountById
108+
* getTopicByName
109+
* **get{Resources}** - get multiple Resources
110+
* getRegistries
111+
* getKafkas
112+
* getServiceAccounts
113+
* getTopics
114+
* **delete{Resource}?By{Arg}** - Delete a single resource or multiple resources
115+
* deleteKafkaById
116+
* deleteTopicByName
117+
* deleteTopics
118+
* deleteRegistryById
119+
* **update{Resource}?By{Argument}** - update a resource or multiple resources
120+
* updateKafkaById
121+
* updateKafkaByName
122+
* updateRegistryById
123+
* updateTopics
124+
* **create{Resource}**- create a resource
125+
* createKafka
126+
* createRegistry
127+
* createTopic
128+
129+
130+
## Security
131+
132+
The following security scheme **must** be added to the OpenAPI document.
133+
134+
Depending on your API this can be applied globally, or per endpoint.
135+
136+
137+
```yaml
138+
# 1) Define the security scheme type (HTTP bearer)
139+
components:
140+
securitySchemes:
141+
bearer: # arbitrary name for the security scheme
142+
type: http
143+
scheme: bearer
144+
bearerFormat: JWT # optional, arbitrary value for documentation purposes
145+
# 2) Apply the security globally to all operations
146+
security:
147+
- bearer: [] # use the same name as above
148+
```
149+
150+
151+
152+
## Tags
153+
154+
Grouping operations with tags is a good practice and is recommended.
155+
156+
If tags are used a root level global “tags” section should be defined matching those used in operations.
157+
158+
159+
## Schemas
160+
161+
There are a number of schemas which should be common across all managed service APIs.
162+
163+
_Note: This list is incomplete._
164+
165+
166+
### Error
167+
168+
[Error](https://github.com/redhat-developer/app-services-api-guidelines/tree/main/spectral#rhoas-error-schema)
169+
170+
171+
### List
172+
173+
[List](https://github.com/redhat-developer/app-services-api-guidelines/tree/main/spectral#rhoas-list-schema)
174+
175+
This would mean enforcing page/total/size pagination on lists.

0 commit comments

Comments
 (0)