Skip to content

Commit 2b6f590

Browse files
authored
Merge pull request #34 from redhat-developer/api-standards
docs: Api standards doc
2 parents db0dfb0 + 4d8f6d7 commit 2b6f590

File tree

2 files changed

+179
-3
lines changed

2 files changed

+179
-3
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
# RHOAS API Guidelines
1+
# Red Hat Application Services API Guidelines
22

33
This repo will contain website documentation for API guidelines and tooling to help adhere to the guidelines.
4-
## Spectral
54

6-
See [./spectral](./spectral) for information on how to use `@rhoas/spectral-ruleset` with Spectral.
5+
## API standards
6+
7+
[ApiStandards](./docs/api-standards.md)
8+
9+
## OpenAPI Validation
10+
11+
[API validator](./spectral) helps to ensure that your specification meets all standards.

docs/api-standards.md

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

0 commit comments

Comments
 (0)