├── Guidelines.md
├── LICENSE.md
├── README.md
├── Spectral.md
└── spectral
├── functions
├── check-spelling-code.js
├── check-spelling.js
└── is-object-schema.js
├── monite.all.yaml
├── monite.openapi-structure.yaml
├── monite.section1-general.yaml
├── monite.section10-headers.yaml
├── monite.section11-webhooks.yaml
├── monite.section12-hypermedia.yaml
├── monite.section13-performance.yaml
├── monite.section14-pagination.yaml
├── monite.section15-versioning.yaml
├── monite.section16-deprecation.yaml
├── monite.section2-language.yaml
├── monite.section3-security.yaml
├── monite.section4-data-types.yaml
├── monite.section5-uri.yaml
├── monite.section6-rest.yaml
├── monite.section7-json.yaml
├── monite.section8-requests.yaml
├── monite.section9-responses.yaml
├── random.examples.yaml
├── test-openapi.yaml
└── test.bash
/Guidelines.md:
--------------------------------------------------------------------------------
1 | # Monite API Style Guide
2 |
3 | These are the guidelines we use at Monite to design and develop our APIs. We aim to apply the same set of rules both
4 | to our public and internal APIs to make it easier for us to achieve consistency and make high-quality APIs from
5 | the get go. However, we can sometimes apply certain rules differently to our internal APIs, if our technology
6 | or security considerations require us to do so.
7 |
8 |
9 | ## Summary
10 |
11 | * REST, but not always HATEOAS
12 | * Security is super important
13 | * American English
14 | * Mostly snake_case
15 | * API First, based on OpenAPI
16 |
17 |
18 | ## Requirement level keywords
19 |
20 | The requirement level keywords "MUST", "MUST NOT", "SHOULD", "SHOULD NOT", "MAY", and "OPTIONAL" used in this document should be interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119).
21 |
22 | * **MUST** and **MUST NOT** mean that it is a critical rule that we must always follow.
23 | * **SHOULD** and **SHOULD NOT** mean that there are exceptions to the rule, but we should be very careful when applying those exceptions. Sometimes we start with these keywords and eventually change them to **MUST** and **MUST NOT**.
24 |
25 |
26 | ## Section 1: General
27 |
28 | ### MUST follow the API-First principle
29 |
30 | When working on a new product on our platform, or expanding an existing product, we always start with an API. In practice, this means the following:
31 |
32 | * We build an API before building the corresponding UI.
33 | * We design future APIs extensively (API-Design-First) by including all relevant stakeholders in the discussion and getting as much feedback as possible, before starting implementing the API.
34 | * We strive to make every API externalizable from the very beginning, to make it easier to publish it in the future, if needed.
35 |
36 |
37 | Why
38 | The recent experience from successful tech companies prove that following the API-First principle can significantly improve the quality of API design decisions, hence saving development time and reducing integration friction during the API lifecycle.
39 |
40 |
41 |
42 | Q&A
43 | Q: Is API-First contradicting modern agile development practices and introducing waterfall processes?
44 | A: No. API-First, when implemented properly, implies a lot of iterations, evolution of API prototypes, and building common understanding of the API design through collaboration and early feedback from multiple parties.
45 |
46 |
47 |
48 | See also
49 |
55 |
56 |
57 | ### MUST follow REST
58 |
59 | Our public APIs must follow the [REST architectural style](https://en.wikipedia.org/wiki/Representational_state_transfer). This means implementing [REST principles (constraints)](https://en.wikipedia.org/wiki/Representational_state_transfer#Architectural_constraints): Client–server architecture, Statelessness, Cacheability, Layered system, Code on demand, and Uniform interface.
60 |
61 | **Note**: Although REST is extremely widespread, there is no official standard that defines **exactly** every part of the REST architectural style. We want to follow the most common and most logical best practices that already exist around REST, while also staying pragmatic in our choices. This style guide is our attempt to formalize how we see REST and how we implement it with our APIs.
62 |
63 |
64 | Why
65 | REST is the most popular architectural style at the moment (2022 State of the API | Postman). This means that this architectural style is very well-known by the majority of developers in the world; there are already a lot of tools, frameworks, libraries and best practices around REST – and therefore it provides the flattest learning curve and best developer experience for most of the developers who will be integrating with Monite.
66 |
67 |
68 |
69 | Q&A
70 | Q: What about other styles (SOAP, GraphQL, gRPC)?
71 | A: We will never support SOAP, but will consider introducing more modern styles/frameworks in the future, if this is needed for our API consumers and there is a clear benefit for it.
72 | Q: What about Level 3 REST and HATEOAS?
73 | A: At the moment, we are not planning to support HATEOAS in all parts of our API. However, we aim to introduce HATEOAS where it makes sense.
74 |
75 |
76 |
77 | See also
78 |
83 |
84 |
85 | ### MUST follow the YAGNI and Robustness principles
86 |
87 | In general, our APIs must expose only what is really necessary for our API clients. This is an important best practice, which allows us to keep the minimal API surface – to document, maintain, monitor, and protect – depending on the real use cases of our API clients.
88 |
89 | This practice is usually referred to as the [YAGNI principle](https://martinfowler.com/bliki/Yagni.html) and is often extended by Postel's law ([Robustness principle](https://en.wikipedia.org/wiki/Robustness_principle)):
90 |
91 | > Be conservative in what you send, be liberal in what you accept.
92 |
93 | In practice, this means that our APIs should not expose resources, parameters, actions, headers, data unless it's really clear why and how they will be used.
94 |
95 | Note: However, we cannot expect that our API clients will follow the same principle. So, we must build our API in a way that is tolerant to accepting something that is not part of the API contract.
96 |
97 |
98 | See also
99 |
104 |
105 |
106 | ### SHOULD NOT expose internal implementation specifics to external API consumers
107 |
108 | Similar to the [abstraction principle in OOP](https://en.wikipedia.org/wiki/Object-oriented_programming#Data_Abstraction), API abstraction allows API providers to achieve several goals:
109 |
110 | - The reason for API consumers to use our APIs lies in the fact that they want to rely on our expertise in a specific field and use our services instead of building themselves. Therefore, our APIs must be easy to understand and integrate for API clients who don't know and should not know all the internal details of how the API platforms works under the hood.
111 | - Exposing internal details can give extra information to potential attackers, since this is not only increasing the [API attack surface](https://cheatsheetseries.owasp.org/cheatsheets/Attack_Surface_Analysis_Cheat_Sheet.html), but also gives invaluable details on how the system is built and works internally.
112 | - Decoupling internal implementation from public APIs is crucial for us to have full control on this implementation and easily evolve it, if necessary, without breaking the public API contract. On the contrary, if API internals are exposed to API clients who start using these APIs for some reason, it would be much more difficult to migrate these clients from the API parts that were not intended for the public use.
113 |
114 | _Spectral rule_: [monite-general-exposing-internals](spectral/monite.section1-general.yaml)
115 |
116 |
117 | ## Section 2: Language
118 |
119 | ### MUST use U.S. English for naming
120 |
121 | We use the U.S. English (or American English) for all the parts of our APIs (like API URIs, field names, parameter names, header names, etc.).
122 |
123 | To decide whether a certain term belongs to the U.S. English or not, we consult with [Wikipedia](https://en.wikipedia.org/wiki/American_and_British_English_spelling_differences) and most renowned English dictionaries.
124 |
125 |
126 | Why
127 | The U.S. version of English is now being commonly used in modern software products and programming frameworks. On the contrary, British English definitely has a much smaller scope in Tech. As for using languages other than English, we don't want to use them in our API names because this might cause a lot of confusion and other problems with API adoption.
128 |
129 |
130 | _Spectral rules_:
131 |
132 | * [monite-language-spelling-names](spectral/monite.section2-language.yaml)
133 | * [monite-language-spelling-texts](spectral/monite.section2-language.yaml)
134 |
135 |
136 | ### SHOULD avoid industry jargon and use simple, unambiguous terms
137 |
138 | We should strive to create our API that can be consumed by a wide variety of audiences, with no or very limited expertise in our API's business domain.
139 |
140 | For this, we should try to use the terms that are easier to follow, easier to understand, and more common in different parts of the world.
141 |
142 | | :x: Not recommended | :+1: Recommended |
143 | |----------------------------|-------------------------|
144 | | `card.pan` | `card.number` |
145 |
146 | _Spectral rule_: [monite-language-avoid-jargon](spectral/monite.section2-language.yaml)
147 |
148 |
149 | ### SHOULD use inclusive and bias-free language and API design
150 |
151 | The language used in our APIs must reflect the modern understanding of inclusive, gender-neutral and bias-free communication. We should constantly educate ourselves on the topics of diversity, equity and inclusion, and make sure our APIs represent these values.
152 |
153 | For more information on this, read [Bias-free communications](https://docs.microsoft.com/en-us/style-guide/bias-free-communication) and [Avoid unnecessarily gendered language](https://developers.google.com/style/inclusive-documentation).
154 |
155 | | :x: Not recommended | :+1: Recommended | Comment |
156 | |--------------------------------------|-------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|
157 | | `blackList`, `whiteList` | `blockList`, `allowList` | |
158 | | `master/slave` | `primary/replica` (in case of identical instances) or `primary/secondary` (for other use cases) | |
159 | | `master` | `master` -> `main` (for example, see [GitHub](https://github.com/github/renaming)) | |
160 | | `person.gender` = {`male`, `female`} | `shopper.gender` = {`male`, `female`, `unknown`, `unspecified`} | Provide more options, and also critically assess if collecting gender information is even needed in this case. |
161 |
162 | _Spectral rule_: [monite-language-non-inclusive](spectral/monite.section2-language.yaml)
163 |
164 |
165 | ### SHOULD NOT use "filler" words in field names
166 |
167 | When naming fields or other elements of an API, avoid using unnecessary filler words like "code", "details", or "info". Usually the same name works well without additional filler words, which are redundant in most of the cases.
168 |
169 | | :x: Not recommended | :+1: Recommended |
170 | |----------------------------|-------------------------|
171 | | `company_info` | `company` |
172 | | `address_details` | `address` |
173 | | `country_code` | `country` |
174 |
175 | _Spectral rule_: [monite-language-filler-words](spectral/monite.section2-language.yaml)
176 |
177 |
178 | ## Section 3: Security
179 |
180 | Read first:
181 |
182 | * [OWASP API Security Project](https://owasp.org/www-project-api-security/)
183 | * [API Security Checklist](https://github.com/shieldfy/API-Security-Checklist)
184 |
185 | ### MUST use HTTPs with TLS 1.2+ on all endpoints
186 |
187 | HTTP is not secure and its scope must be very limited. For our APIs we must always use encrypted connections, and unencrypted API calls must be rejected.
188 |
189 | _Spectral rule_: [monite-security-https-only](spectral/monite.section3-security.yaml)
190 |
191 |
192 | ### MUST require authentication for all endpoints (except for the Auth service)
193 |
194 | All API endpoints must be protected behind authentication to avoid [broken authentication](https://owasp.org/www-project-top-ten/2017/A2_2017-Broken_Authentication) issues.
195 |
196 | The only exception to this requirement is the OAuth 2.0 service, which exposes endpoints like `/auth/token` and `/auth/revoke` that by design might be accessible without any authentication.
197 |
198 |
199 | ### SHOULD NOT use Basic Authentication
200 |
201 | Use standard authentication instead (e.g., JWT, OAuth).
202 |
203 | _Spectral rule_: [monite-security-no-http-basic](spectral/monite.section3-security.yaml)
204 |
205 |
206 | ### MUST NOT expose any sensitive data in the URL
207 |
208 | If you have any sensitive data in a URL, there is a high chance that this data might be intercepted/recorded/modified by a malicious actor. URLs can be exposed in many ways, like browsers, emails, UI and so on. Even if they are not displayed in a web browser and used only for backend-to-backend interaction in an encrypted HTTPs connection, such URLs can still appear in server logs and other places.
209 |
210 | For sensitive data like credentials, passwords, security tokens, API keys and similar:
211 |
212 | * use the standard Authorization header.
213 |
214 | For sensitive data like [PCI](https://www.pcisecuritystandards.org/) or [PII](https://en.wikipedia.org/wiki/Personal_data):
215 |
216 | * use request/response body.
217 |
218 | _Spectral rule_: [monite-security-no-secrets-in-path-or-query-parameters](spectral/monite.section3-security.yaml)
219 |
220 |
221 | ## Section 4: Data types and formats
222 |
223 | ### MUST use only allowed data types
224 |
225 | To achieve high consistency between different parts of our API and improve its interoperability, we want to limit the variety of data types we use for API elements (request and response fields, parameters and HTTP headers) and use one of the allowed data types.
226 |
227 | We achieve this by mostly using data types and formats commonly adopted by other industry specifications, such as [JSON Schema](https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-7.3), [OpenAPI](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#data-types), and various ISO and IETF standards.
228 |
229 | | **Type** | **OpenAPI type** | **OpenAPI format** | **Description** | **Example** |
230 | |--------------------|------------------|--------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------|
231 | | Boolean | `boolean` | | One of the two Boolean values (**true** or **false**). | true |
232 | | Object | `object` | | A complex object consisting of one or several fields. | |
233 | | Array | `array` | | An array containing values of the same type. | |
234 | | Integer | `integer` | `int32` | A 4-byte signed integer in the range -2,147,483,648 to 2,147,483,647 (inclusive). | 7721071004 |
235 | | Long integer | `integer` | `int64` | A 8-byte signed integer in the range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (inclusive). | 772107100456824 |
236 | | Float number | `number` | `float` | A single precision decimal number (**binary32** in [IEEE 754-2008/ISO 60559:2011](https://en.wikipedia.org/wiki/IEEE_754)). | 3.1415927 |
237 | | Double | `number` | `double` | A double precision decimal number (**binary64** in [IEEE 754-2008/ISO 60559:2011](https://en.wikipedia.org/wiki/IEEE_754)). | 3.141592653589793 |
238 | | Decimal | `string` | `decimal` | An arbitrarily precise signed decimal number. | "3.141592653589793238462643383279" |
239 | | String | `string` | | An arbitrary string of characters. | "Monite rocks!" |
240 | | Date & time | `string` | `date-time` | A timestamp following [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) (a subset of [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)). | "2022-07-17T08:26:40.252Z" |
241 | | Date | `string` | `date` | A date following [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) (a subset of [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)). | "2022-07-17" |
242 | | Time | `string` | `time` | Time value following [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) (a subset of [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)). | "08:26:40.252Z" |
243 | | Email | `string` | `email` | An email address following [RFC 5322](https://tools.ietf.org/html/rfc5322). | "someone@example.com" |
244 | | URI | `string` | `uri` | A web URI following [RFC 3986](https://tools.ietf.org/html/rfc3986). | "https://www.example.com" |
245 | | UUID | `string` | `uuid` | A Universally Unique Identifier following [RFC 4122](https://tools.ietf.org/html/rfc4122). | "279fc665-d04d-4dba-bcad-17c865489dfa" |
246 | | Base64 string | `string` | `base64` | A string that contains Base64-encoded data following [RFC 4648 Section 4](https://www.rfc-editor.org/rfc/rfc4648#section-4). | "VGVzdA==" |
247 | | Binary | `string` | `binary` | Arbitrary binary data, such as the contents of an image file. Typically used for file uploads and downloads. | |
248 | | Regular expression | `string` | `regex` | A regular expression following [ECMA 262](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf). | "^[a-z0-9]+$" |
249 |
250 | **Note**: If you want to use a data type that is not part of the table above, make a suggestion to this API Style Guide.
251 |
252 | _Spectral rules_:
253 |
254 | * [monite-data-incorrect-integer-format](spectral/monite.section4-data-types.yaml)
255 | * [monite-data-incorrect-number-format](spectral/monite.section4-data-types.yaml)
256 | * [monite-data-incorrect-string-format](spectral/monite.section4-data-types.yaml)
257 |
258 |
259 | ### SHOULD use standard types for Language, Country and Currency values
260 |
261 | For some data types (related to localization and regionality), it's common to use enumerations with limited sets of predefined string values, based on corresponding ISO standards.
262 |
263 | To easily find all API elements of such data types and treat these elements in the same way, we should use `string` as their type and corresponding format values from the table below.
264 |
265 | | **Type** | **OpenAPI type** | **OpenAPI format** | **Description** | **Example** |
266 | |--------------------|------------------|--------------------|-------------------------------------------------------------------------------------------------------------|----------------------------------------|
267 | | Language | `string` | `lang` | A two-letter language code following [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). | "en" |
268 | | Country | `string` | `country` | A two-letter country code following [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). | "DE" |
269 | | Currency | `string` | `currency` | A three-letter currency code following [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217). | "EUR" |
270 |
271 | :+1: Recommended
272 |
273 | ``` yaml
274 | country:
275 | type: string
276 | format: country
277 | enum:
278 | - AF
279 | - AX
280 | - AL
281 | - DZ
282 | - AS
283 | - ...
284 | description: Country of a customer.
285 | ```
286 |
287 | ### SHOULD specify data formats in schema models
288 |
289 | For all data types that support providing their `format`, we should specify this format in schema models. This will allow API consumers to better understand what values can be represented by our API elements and therefore build better validation logic on their side.
290 |
291 | Once specified in schema models, this format should be propagated to OpenAPI files, technical documentation, server-side libraries, and other artifacts that improve developer experience of API consumers.
292 |
293 | :x: Not recommended
294 |
295 | ``` yaml
296 | website:
297 | type: string
298 | description: Customer website.
299 | ```
300 |
301 | :+1: Recommended
302 |
303 | ``` yaml
304 | website:
305 | type: string
306 | description: Customer website.
307 | format: uri
308 | ```
309 |
310 | _Spectral rules_:
311 |
312 | * [monite-data-missing-integer-format](spectral/monite.section4-data-types.yaml)
313 | * [monite-data-missing-number-format](spectral/monite.section4-data-types.yaml)
314 |
315 |
316 | ### SHOULD use the common Address object
317 |
318 | For unification purposes, we should use the same schema for all objects representing a postal address. This object should contain the following fields, and their presence should be either required or not depending on the context where this address is used in the API.
319 |
320 | | **Field Name** | **OpenAPI type** | **OpenAPI format** | **Description** |
321 | |----------------|------------------|--------------------|-------------------------------------------------------------------------------------------------|
322 | | `postal_code` | `string` | | Also referred to as a "ZIP code". |
323 | | `country` | `string` | `country` | Specified by a country code. |
324 | | `state` | `string` | | Also referred to as a "province" or "county". |
325 | | `city` | `string` | | |
326 | | `line1` | `string` | | Combines a street address, house number, apartment number and any other suffixes of the address |
327 | | `line2` | `string` | | Usually optional and being used only if the address is very long and doesn't fit into `line1`. |
328 |
329 |
330 | ### SHOULD use the common Money object
331 |
332 | For unification purposes, we should use the same schema for all objects representing money values. This object should contain the following fields, both are always required:
333 |
334 | | **Field Name** | **OpenAPI type** | **OpenAPI format** | **Description** |
335 | |----------------|------------------|--------------------|---------------------------------------------|
336 | | `amount` | `integer` | `int64` | Represented in "minor units" |
337 | | `currency` | `string` | `currency` | "Minor units" depend on the currency value. |
338 |
339 | **Note**: Minor units are specified according to [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217#Minor_units_of_currency) and can be found in [this table](https://en.wikipedia.org/wiki/ISO_4217#Active_codes).
340 |
341 | **Note**: We strongly recommend against using string, float or double values for representing amounts, because of arising problems around precision and serialization/deserialization from JSON. Storing amount values as long integers is a common best practice, adopted by API payment providers like [Adyen](https://docs.adyen.com/development-resources/currency-codes) and [Stripe](https://stripe.com/docs/currencies).
342 |
343 |
344 | See also
345 |
346 | - [JSON can safely represent integers only in the [- 2^53+1, 2^53-1] range](https://datatracker.ietf.org/doc/html/rfc7159#section-6)
347 | - [OpenAPI incompatible with I-JSON](https://github.com/OAI/OpenAPI-Specification/issues/1517)
348 | - [Google API: Type and format summary](https://developers.google.com/discovery/v1/type-format)
349 |
350 |
351 |
352 |
353 | ## Section 5: URIs
354 |
355 | ### MUST use the forward slash to indicate hierarchical relationships
356 |
357 | The forward-slash (`/`) character is used in the path portion of the URI to indicate a hierarchical relationship between resources, for example:
358 |
359 | * `https://api.example.com/v1/invoices`
360 | * `https://api.example.com/v1/invoices/{id}`
361 | * `https://api.example.com/v1/invoices/{id}/parts`
362 | * `https://api.example.com/v1/invoices/{id}/parts/{id}`
363 |
364 | _Spectral rule_: [monite-uri-no-backslash](spectral/monite.section5-uri.yaml)
365 |
366 |
367 | ### MUST NOT use the trailing forward slash in URIs
368 |
369 | As the last character within a URI's path, a forward slash (`/`) adds no extra value and might cause confusion. So, it's better to drop it completely from the URI.
370 |
371 | | :x: Not recommended | :+1: Recommended |
372 | |---------------------------------------|--------------------------------------|
373 | | https://api.example.com/v1/resources/ | https://api.example.com/v1/resources |
374 |
375 | _Spectral rule_: [OAS: path-keys-no-trailing-slash](https://meta.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules#path-keys-no-trailing-slash)
376 |
377 |
378 | ### MUST NOT have empty segments in a path
379 |
380 | Empty path segments could cause a lot of ambiguity, so we must not have them in a path.
381 |
382 | | :x: Not recommended | :+1: Recommended |
383 | |----------------------------------------------------|--------------------------------------------------------|
384 | | https://api.example.com/v1/resources//subresources | https://api.example.com/v1/resources/{id}/subresources |
385 | | https://api.example.com/v1/resources//my_profile | https://api.example.com/v1/resources/my_profile |
386 |
387 | _Spectral rule_: [monite-uri-no-empty-path-segments](spectral/monite.section5-uri.yaml)
388 |
389 |
390 | ### MUST use lowercase letters in URIs
391 |
392 | Always prefer lowercase letters in URI paths, for simplicity and consistency.
393 |
394 | | :x: Not recommended | :+1: Recommended |
395 | |--------------------------------------|--------------------------------------|
396 | | HTTPS://API.EXAMPLE.COM/v1/resources | https://api.example.com/v1/resources |
397 | | https://api.example.com/V1/Resources | https://api.example.com/v1/resources |
398 |
399 | _Spectral rule_: [monite-uri-no-uppercase](spectral/monite.section5-uri.yaml)
400 |
401 |
402 | ### MUST NOT use "api" in a path
403 |
404 | We want the "api" suffix to be part of the host name (e.g. https://api.sandbox.monite.com). This means that using "api" in a base path is redundant, and we MUST NOT do this.
405 |
406 | | :x: Not recommended | :+1: Recommended |
407 | |------------------------------------------------|--------------------------------------------|
408 | | https://api.example.com/v1/api/resources | https://api.example.com/v1/resources |
409 | | https://api.example.com/v1/payments-api/orders | https://api.example.com/v1/payments/orders |
410 |
411 | _Spectral rule_: [monite-uri-no-api-suffix](spectral/monite.section5-uri.yaml)
412 |
413 |
414 | ### MUST NOT add file extensions to URIs
415 |
416 | File extensions look bad and do not add any advantage. Removing them decreases the length of URIs as well. No reason to keep them.
417 |
418 | Apart from the above reason, if you want to highlight the media type of API using file extension, then you should rely on the media type, as communicated through the `Content-Type` header, to determine how to process the body's content.
419 |
420 | | :x: Not recommended | :+1: Recommended |
421 | |--------------------------------------------|----------------------------------------|
422 | | https://api.example.com/v1/me/document.xml | https://api.example.com/v1/me/document |
423 |
424 | _Spectral rule_: [monite-uri-no-file-extensions](spectral/monite.section5-uri.yaml)
425 |
426 |
427 | ### MUST use lower snake_case for path segments and query parameters
428 |
429 | We restrict path segments and query parameter names to ASCII snake_case strings matching regex `^[a-z][a-z\_0-9]*$`. The first character must be a lowercase letter and subsequent characters can be letters, underscores (`_`), and numbers.
430 |
431 | We prefer snake_case over kebab-case because we use snake_case for resource and field names, and resource names can be exposed in segment paths, query parameters and request/response payloads. If we decide to use kebab-case for resources in a URI and keep snake_case in payloads, this will cause a lot of inconsistencies.
432 |
433 | | :x: Not recommended | :+1: Recommended |
434 | |------------------------------------------------------------|------------------------------------------------------------|
435 | | https://api.example.com/v1/sales-orders | https://api.example.com/v1/sales_orders |
436 | | https://api.example.com/v1/salesOrders | https://api.example.com/v1/sales_orders |
437 | | https://api.example.com/v1/transactions?customer-name=Test | https://api.example.com/v1/transactions?customer_name=Test |
438 |
439 | Spectral rules:
440 |
441 | * [monite-uri-path-snake-case](spectral/monite.section5-uri.yaml)
442 | * [monite-uri-query-parameters-snake-case](spectral/monite.section5-uri.yaml)
443 |
444 |
445 | ## Section 6: REST & Resources
446 |
447 | ### MUST build APIs around resources
448 |
449 | When designing a REST API, always start with identifying resources – the main notions (objects) around which an API client performs various actions. These actions can be either CRUD (typically represented with POST/GET/PATCH/DELETE HTTP methods), or some other (e.g. resulting in changing a resource's state).
450 |
451 | > The key abstraction of information in REST is a resource. Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g., a person), and so on.
452 | > In other words, any concept that might be the target of an author's hypertext reference must fit within the definition of a resource.
453 | > A resource is a conceptual mapping to a set of entities, not the entity that corresponds to the mapping at any particular point in time.
454 |
455 | ([Roy Fielding's dissertation](https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_2_1_1))
456 |
457 | #### Collection and singleton resources
458 |
459 | A resource can be either a part of a resource collection (with other resources of the same type in the same collection) or a singleton resource (exactly one instance of the resource always exists within any given parent).
460 |
461 | For example, `customers` is a collection of resources accessible via the `/customers` URI, where each individual resource can be accessed by its `id` via `/customers/{id}`.
462 |
463 | A common example of a singleton resource can be a `config` object that always exists for a given project and is accessible via `/projects/{id}/config`.
464 |
465 | **Note**: Singleton resources must not have an ID field, because there is always only one singleton resource for any parent resource.
466 |
467 | **Note**: Singleton resources must not define the CREATE or DELETE standard methods. The singleton is implicitly created or deleted when its parent is created or deleted.
468 |
469 | **Note**: Singleton resources should define the GET and PATCH methods.
470 |
471 | **Note**: Singleton resource names are always singular.
472 |
473 | #### Resources and sub-resources
474 |
475 | A resource may contain sub-resources (either a collection or singleton).
476 |
477 | For example, a `customer` resource can have an `accounts` collection of sub-resources, which is accessible via `/customers/{customer_id}/accounts`.
478 |
479 | This way, a single `account` sub-resource can be accessed via `/customers/{customer_id}/accounts/{account_id}`.
480 |
481 |
482 | ### MUST provide access to resources via URI path segments
483 |
484 | To get access to a collection of resources or a singleton resource, an API client must navigate using path segments of API URIs.
485 |
486 | For example, this is how one can retrieve a collection of invoice resources:
487 |
488 | * `https://api.example.com/v1/invoices`
489 |
490 | This is how one can retrieve a collection of subresources:
491 |
492 | * `https://api.example.com/v1/resources/{id}/subresources`
493 |
494 | ### MUST use nouns to represent resources
495 |
496 | REST URIs should refer to a resource that is a thing (noun) instead of referring to an action (verb). Actions are also possible, but only around a specific resource.
497 |
498 | | :x: Not recommended | :+1: Recommended |
499 | |-------------------------------------|-----------------------------------------|
500 | | https://api.example.com/v1/navigate | https://api.example.com/v1/directions |
501 | | https://api.example.com/v1/similar | https://api.example.com/v1/similarities |
502 |
503 | ### MAY use verbs for actions on a resource (but avoid when possible)
504 |
505 | In some cases, we can use verbs in a URI to represent actions performed on a resource. This is mostly for actions that cannot be represented with standard HTTP methods (POST, GET, PATCH, PUT, DELETE) and, for example, result in an asynchronous change of a resource state.
506 |
507 | | :x: Not recommended | :+1: Recommended |
508 | |---------------------------------------------|----------------------------------------------------|
509 | | POST https://api.example.com/v1/archiveUser | POST https://api.example.com/v1/users/{id}/archive |
510 |
511 | ### SHOULD NOT use CRUD function names in URIs
512 |
513 | Do not use URIs to indicate a CRUD (Create, Read, Update, Delete) function. URIs should only be used to uniquely identify the resources and not any action upon them.
514 |
515 | Use the corresponding HTTP methods instead.
516 |
517 | | :x: Not recommended | :+1: Recommended |
518 | |---------------------------------------------|----------------------------------------------|
519 | | POST https://api.example.com/v1/createUser | POST https://api.example.com/v1/users |
520 | | POST https://api.example.com/v1/getUser | GET https://api.example.com/v1/users/{id} |
521 | | POST https://api.example.com/v1/updateUser | PATCH https://api.example.com/v1/users/{id} |
522 | | POST https://api.example.com/v1/replaceUser | PUT https://api.example.com/v1/users/{id} |
523 | | POST https://api.example.com/v1/deleterUser | DELETE https://api.example.com/v1/users/{id} |
524 |
525 | _Spectral rule_: [monite-rest-no-crud-in-uri-names](spectral/monite.section6-rest.yaml)
526 |
527 |
528 | ### MUST pluralize resource names, unless it's a singleton resource
529 |
530 | When naming a collection of resources, use the plural version of a noun. An exception is a singleton resource, which is always unique and only one in the entire API context.
531 |
532 | | :+1: Recommended | Explanation |
533 | |---------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
534 | | https://api.example.com/v1/invoices | There might be multiple invoices to be processed by this API. |
535 | | https://api.example.com/v1/invoices/{id} | A single invoice can be retrieved from a collection by its ID. |
536 | | https://api.example.com/v1/users | There might be multiple users to be processed by this API. |
537 | | https://api.example.com/v1/me | Here, `me` is a singleton resource pointing to the API user. |
538 | | https://api.example.com/v1/company | If there is only one company that can be accessed by an API user, it is also a singleton resource, because an API user cannot access any other company. |
539 | | https://api.example.com/v1/company/settings | Although `settings` is plural, it's a singleton resource because there can be only one set of settings for a company (unless there is an API design that allows for multiple sets of different settings to be provided for a company. |
540 |
541 | ### SHOULD limit the number of subresource levels
542 |
543 | We don't want to have too many nested levels for API URLs, because it leads to unnecessary complexity in understanding the API, as well as might result in too long URLs not fitting the browser limitations.
544 |
545 | _Spectral rule_: [monite-rest-limited-resource-levels](spectral/monite.section6-rest.yaml)
546 |
547 |
548 | ### MUST expose id, created_at and updated_at fields in collection resources
549 |
550 | For unification and consistency, every collection resource should have these fields:
551 |
552 | * `id`: a unique ID that allows API consumers to refer to this resource instance.
553 | * `created_at`: a date-time value indicating when this resource instance was created.
554 | * `updated_at`: a date-time value indicating when this resource instance was modified last time.
555 |
556 | **Note**: These fields MUST NOT be exposed in singleton resources. The `id` field is not necessary because there is always only one instance for a singleton resource per its parent resource; while `created_at` and `updated_at` are always the same as its parent resource.
557 |
558 | ### MUST follow these rules for resource identifies (resource IDs)
559 |
560 | #### Resource IDs MUST be URL-friendly
561 |
562 | Since IDs should be used in API URIs (to refer to a specific resource instance), they must be URL-friendly.
563 |
564 | #### Resource IDs MUST be globally unique
565 |
566 | A resource ID value should uniquely identify a specific resource instance within the scope of the entire API platform. No resources should have the same value as their ID, as it can cause a lot of confusion.
567 |
568 | #### Resource IDs MUST be generated by an API provider
569 |
570 | To make sure all resource IDs meet our requirements, we must always generate them ourselves and assign them to each specific resource instance upon resource creation.
571 |
572 | #### Resource IDs MUST NOT be submitted by an API consumer
573 |
574 | Because all resource IDs must be generated by us, we don't allow API consumers to generate such IDs (even if they use exactly the same ID format as we do).
575 |
576 | However, we understand that our API consumers might also need to store some IDs assigned to resource instances by their platform. In this case, we allow API consumers to store their own IDs in a `partner_internal_id` field.
577 |
578 | #### Resource IDs MUST be opaque strings
579 |
580 | API consumers must never build any business logic based on the ID format and must always treat resource IDs as random strings. To fulfill this requirement, resource IDs should look like opaque strings, even if there is some logic and format behind the ID generation algorithm.
581 |
582 | #### Resource IDs SHOULD NOT have variable length
583 |
584 | Once we settle on the format of resource IDs, we should try to do our best to make sure these IDs always have the same length. The reason is that API consumers set a fixed column length in their code and databases to process and store such IDs, and changing the length (especially increasing the length) can have a drastic impact on their integration with our API platform.
585 |
586 | If changing the length of resource IDs is inevitable, treat it as a breaking change and prepare your API consumers in advance, with additional communication and fuzzy testing.
587 |
588 | #### Resource IDs MUST NOT be sequential numbers
589 |
590 | Using sequential numbers for resource IDs is considered an awful development practice. The main reasons are:
591 |
592 | * In this case, resource IDs are easily guessable. This makes it much easier for a malicious user to attempt to access resources that they shouldn't have to.
593 | * The last generated resource ID gives any API client information of how many resources of a certain type exist on an API platform. This might expose some critical business information (like the total number of API clients, the total number of payment transactions, etc.), which in a normal situation should never be available for people outside an organization owning this API platform.
594 | * Quite often these IDs directly correspond to the auto-incremented database indexes from a data table storing information about these resources. This gives even more information to a potential attacker in case they can get access to the internal systems.
595 |
596 | #### Resource IDs MAY use either UUID or Snowflake formats
597 |
598 | One of the easiest ways to get an opaque string that is guaranteed to be unique and hence can be used as resource IDs is to generate UUID values.
599 |
600 | An alternative (and more powerful) option is to generate so-called [Snowflake IDs](https://en.wikipedia.org/wiki/Snowflake_ID) that follow some generation format, which is unknown to API consumers. Since API consumers don't know the exact format of such IDs, they still treat them as opaque and unique. However, this makes it possible for API producers to de-construct such IDs and decode some values from it. For example, in the case of distributed systems, such IDs can be used for smart routing and data storage decisions.
601 |
602 | #### Resource IDs MAY use prefixes indicating resource types
603 |
604 | To make it faster to determine which resource type a specific resource ID is referring to, some API producers add predefined prefixes to each resource ID value. These prefixes can be 2, 3, or 4 characters long and uniquely correspond to a specific resource type on an API platform.
605 |
606 | For example, all resource IDs for a `payment` resource can follow either the `PA_*` or `PAY_*` or `PYMT_*` format.
607 |
608 | Using such IDs makes it much quicker to troubleshoot different cases and identify a situation when some IDs are being used in the wrong context.
609 |
610 | #### Resource IDs MUST be stable and never change their value for a given resource instance
611 |
612 | Each resource ID uniquely identifies a specific resource instance. This means that once a resource ID has been generated and assigned to a specific resource instance, it becomes an inherent part of that resource.
613 |
614 | #### Resource IDs MUST follow the "resource_id" format when being referred in payloads of other resources
615 |
616 | For example, if an API has the following `product` resource:
617 |
618 | ```json
619 | {
620 | "id" : "e675f59e-ddd1-4835-8bc2-edd76c54fad4",
621 | "name" : "Tomato"
622 | }
623 | ```
624 |
625 | The invoice resource should link to it by the `product_id` field:
626 |
627 | ```json
628 | {
629 | "line_items" : [
630 | {
631 | "product_id" : "e675f59e-ddd1-4835-8bc2-edd76c54fad4",
632 | "number" : 1200
633 | }
634 | ]
635 | }
636 | ```
637 |
638 | ## Section 7: JSON payload
639 |
640 | ### MUST use the JSON format for request and response payloads
641 |
642 | Every request and response payload must be a valid JSON object, representing structured resource data. This allows API consumers to easily parse, construct, and validate such payloads; and this allows us to safely expand such payloads with new keys in the future, if needed.
643 |
644 | The JSON format is a well-known and established industry standard, defined in [RFC 7159](https://tools.ietf.org/html/rfc7159). We prefer to additionally apply restrictions of the [RFC 7493 "Internet JSON"](https://tools.ietf.org/html/rfc7493) standard, which means in particular:
645 |
646 | * a JSON payload cannot contain duplicate keys on the same level, each key must be unique.
647 | * a JSON payload must use UTF-8 encoding and consist of valid Unicode strings.
648 |
649 | :x: Not recommended
650 |
651 | ``` json
652 | [
653 | 100,
654 | 120,
655 | 176
656 | ]
657 | ```
658 |
659 | :x: Not recommended
660 |
661 | ``` xml
662 |
663 | 100
664 | 120
665 | 176
666 |
667 | ```
668 |
669 | :+1: Recommended
670 |
671 | ``` json
672 | {
673 | "prices" : [
674 | 100,
675 | 120,
676 | 176
677 | ]
678 | }
679 | ```
680 | _Spectral rule_: [monite-json-root-json-objects](spectral/monite.section7-json.yaml)
681 |
682 |
683 | ### SHOULD prefer nested structures instead of flattened ones
684 |
685 | This enables better grouping and easier extensibility in the future.
686 |
687 | :x: Not recommended
688 |
689 | ``` xml
690 | {
691 | "account_payout_delay_days" 2,
692 | "account_payout_interval" = "daily"
693 | }
694 | ```
695 |
696 | :+1: Recommended
697 |
698 | ``` json
699 | {
700 | "account" : {
701 | ...
702 | "payout_schedule" : {
703 | "delay_days" : 2,
704 | "interval" : "daily"
705 | }
706 | }
707 | }
708 | ```
709 |
710 |
711 | ### MUST use lower snake_case for field names
712 |
713 | We restrict field names to ASCII snake_case strings matching regex `^[a-z][a-z\_0-9]*$`. The first character must be a lowercase letter, and subsequent characters can be letters, underscores (`_`), and numbers.
714 |
715 | | :x: Not recommended | :+1: Recommended |
716 | |----------------------------|------------------------------------------------------------|
717 | | sales-order-id | sales_order_id |
718 | | salesOrderId | sales_order_id |
719 | | sales-order-ID | sales_order_id |
720 |
721 | _Spectral rule_: [monite-json-field-names-snake-case](spectral/monite.section7-json.yaml)
722 |
723 |
724 | ### MUST pluralize array names
725 |
726 | The names of arrays must be pluralized to indicate that they contain multiple values.
727 |
728 | :x: Not recommended
729 |
730 | ``` json
731 | {
732 | "price" : [
733 | 100,
734 | 120,
735 | 176
736 | ]
737 | }
738 | ```
739 |
740 | :+1: Recommended
741 |
742 | ``` json
743 | {
744 | "prices" : [
745 | 100,
746 | 120,
747 | 176
748 | ]
749 | }
750 | ```
751 |
752 | ### MUST NOT use null for empty arrays
753 |
754 | To avoid confusion, empty arrays must be still represented as arrays, not as nulls.
755 |
756 | :x: Not recommended
757 |
758 | ``` json
759 | {
760 | "prices" : null
761 | }
762 | ```
763 |
764 | :+1: Recommended
765 |
766 | ``` json
767 | {
768 | "prices" : []
769 | }
770 | ```
771 |
772 | ### SHOULD follow the "verb_at" format for date-time properties
773 |
774 | Using certain name conventions for most popular data types makes it easier for API consumers to understand what to expect from a field just by looking at its name.
775 |
776 | For date-time properties we want to use the "_at" suffix, preceded by a verb in a present or past tense, which is quite common for many modern APIs.
777 |
778 | | :x: Not recommended | :+1: Recommended |
779 | |----------------------------|--------------------------|
780 | | created | created_at |
781 | | modification_date | updated_at |
782 | | start_date | starts_at |
783 | | expire_at | expires_at or expired_at |
784 | | will_expire_at | expires_at |
785 |
786 |
787 | ## Section 8: HTTP requests
788 |
789 | ### SHOULD support the following HTTP methods
790 |
791 | In our REST APIs, an operation can use the following HTTP methods:
792 |
793 | * `POST` – to create new resources or perform an action on a resource.
794 | * `GET` – to return a resource or collection of resources.
795 | * `PATCH` – to (partially) update a resource.
796 | * `PUT` – to replace a resource.
797 | * `DELETE` – to delete a resource. **Note**: always evaluate if this method is needed for real use cases or not; and when it's really needed, consider using the "soft delete" technique.
798 |
799 | For more specific guidance on how to use these HTTP methods, refer to the corresponding rule in this section.
800 |
801 | ### MAY use other HTTP methods
802 |
803 | When necessary, it is allowed to use other HTTP methods (for example, the `OPTIONS` method for pre-flight requests to support [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)).
804 |
805 |
806 | ### MUST create resources via POST to a collection
807 |
808 | **Note**: A successful `POST` request must always return the created resource in a response with HTTP status code **201 Created**.
809 |
810 | Example of a `POST` request:
811 |
812 | ```shell
813 | curl -X POST https://api.example.com/v1/products \
814 | -H 'Content-Type: application/json' \
815 | -d '{
816 | "name": "Potato",
817 | "price": {
818 | "currency": "EUR",
819 | "value": 1000
820 | }
821 | }'
822 | ```
823 |
824 | Successful response (**201 Created**):
825 |
826 | ```json
827 | {
828 | "name": "Potato",
829 | "price": {
830 | "currency": "EUR",
831 | "value": 1000
832 | },
833 | "id": "e675f59e-ddd1-4835-8bc2-edd76c54fad4",
834 | "created_at": "2022-05-02T15:13:29.901787+00:00",
835 | "updated_at": "2022-05-02T15:13:29.901787+00:00"
836 | }
837 | ```
838 |
839 | ### MUST create only one resource at a time
840 |
841 | When using the `POST` call to create a resource, we should create only one resource at a time. To create subresources, a separate `POST` call should be made.
842 |
843 | This is done so to avoid a situation when one of the resources is created successfully, while another is not. In this case, it's not clear if the response should be `Success` or `Error`. Most likely, the whole request should be treated as an atomic operation and hence should return the error code.
844 |
845 | To avoid this ambiguity, we expect separate API calls for creating a resource and its subresources.
846 |
847 | For example:
848 |
849 | ```shell
850 | curl -X POST https://api.example.com/v1/resources \
851 | -H 'Content-Type: application/json' \
852 | -d '{
853 | "name": "My resource"
854 | }'
855 | ```
856 |
857 | **201 Created** response:
858 |
859 | ```json
860 | {
861 | "id" : "e675f59e-ddd1-4835-8bc2-edd76c54fad4",
862 | "name" : "My resource"
863 | }
864 | ```
865 |
866 | Another request:
867 |
868 | ```shell
869 | curl -X POST https://api.example.com/v1/resources/e675f59e-ddd1-4835-8bc2-edd76c54fad4/subresources \
870 | -H 'Content-Type: application/json' \
871 | -d '{
872 | "name": "My sub-resource"
873 | }'
874 | ```
875 |
876 | Another **201 Created** response:
877 |
878 | ```json
879 | {
880 | "id" : "d654f59e-dad1-4835-8bc2-edd76c54faf2",
881 | "name" : "My sub-resource",
882 | "parent_id" : "e675f59e-ddd1-4835-8bc2-edd76c54fad4"
883 | }
884 | ```
885 |
886 |
887 | ### MAY perform an action via POST to an action URI for a resource
888 |
889 | When an action to be performed with a resource doesn't belong to the variety of CRUD operations (and hence cannot be represented with standard HTTP methods), it is allowed to use a `POST` call to initiate this action. In such cases, an action is represented with a verb appended to a resource URI.
890 |
891 | Example of a `POST` request performing resource verification with a `/verify` action:
892 |
893 | ```shell
894 | curl -X POST https://api.example.com/v1/resources/e675f59e-ddd1-4835-8bc2-edd76c54fad4/verify \
895 | -H 'Content-Type: application/json' \
896 | -d '{
897 | "verification_tier": "medium"
898 | }'
899 | ```
900 |
901 | Successful **202 Accepted** response:
902 |
903 | ```json
904 | {
905 | "verification_status" : "scheduled"
906 | }
907 | ```
908 |
909 | ### MUST retrieve a collection of resources via GET to the resources URI
910 |
911 | **Note**: A request body is not allowed for `GET` calls.
912 |
913 | **Note**: All resources must be wrapped into a `data` array, for better extensibility of a response body (for example, to add pagination-related properties).
914 |
915 | **Note**: When there might be a lot of resources returned by a `GET` call (more than 20), always consider adding pagination to return only chunks of the resource collection.
916 |
917 | Example of a `GET` request:
918 |
919 | ```shell
920 | curl https://api.example.com/v1/products
921 | ```
922 |
923 | Successful **200 OK** response:
924 |
925 | ```json
926 | {
927 | "data": [
928 | {
929 | "name": "Potato",
930 | "price": {
931 | "currency": "EUR",
932 | "value": 1000
933 | },
934 | "id": "3278430a-512e-4eca-967b-3dc59743d0bc",
935 | "created_at": "2022-05-02T15:13:26.517562+00:00",
936 | "updated_at": "2022-05-02T15:13:26.517572+00:00"
937 | },
938 | {
939 | "name": "Tomato",
940 | "price": {
941 | "currency": "USD",
942 | "value": 2000
943 | },
944 | "id": "e675f59e-ddd1-4835-8bc2-edd76c54fad4",
945 | "created_at": "2022-05-02T15:13:29.901787+00:00",
946 | "updated_at": "2022-05-02T15:13:29.901796+00:00"
947 | }
948 | ]
949 | }
950 | ```
951 |
952 | When the `GET` call should return no resources, a successful **200 OK** response must still have a `data` array, empty in this case:
953 |
954 | ```json
955 | {
956 | "data": []
957 | }
958 | ```
959 |
960 | _Spectral rules_:
961 |
962 | * [monite-requests-get-no-request-body](spectral/monite.section8-requests.yaml)
963 |
964 |
965 | ### MUST retrieve a single resource via GET to the resources URI with an ID as a path parameter
966 |
967 | **Note**: A request body is not allowed for `GET` calls.
968 |
969 | **Note**: A resource must be returned on the root level of a response and not be wrapped into any other objects.
970 |
971 | Example of a `GET` request:
972 |
973 | ```shell
974 | curl https://api.example.com/v1/products/3278430a-512e-4eca-967b-3dc59743d0bc
975 | ```
976 |
977 | Successful **200 OK** response:
978 |
979 | ```json
980 | {
981 | "name":"Potato",
982 | "price":{
983 | "currency":"EUR",
984 | "value":1000
985 | },
986 | "id":"3278430a-512e-4eca-967b-3dc59743d0bc",
987 | "created_at":"2022-05-02T15:13:26.517562+00:00",
988 | "updated_at":"2022-05-02T15:13:26.517572+00:00"
989 | }
990 | ```
991 |
992 | _Spectral rules_:
993 |
994 | * [monite-requests-get-no-request-body](spectral/monite.section8-requests.yaml)
995 |
996 |
997 | ### MUST filter a resource collection with query parameters
998 |
999 | To filter a collection of returned resources against one or several criteria, use query parameters.
1000 |
1001 | Example of a `GET` request:
1002 |
1003 | ```shell
1004 | curl https://api.example.com/v1/products?name=Tomato
1005 | ```
1006 |
1007 | Successful **200 OK** response:
1008 |
1009 | ```json
1010 | {
1011 | "data": [
1012 | {
1013 | "name": "Tomato",
1014 | "price": {
1015 | "currency": "USD",
1016 | "value": 2000
1017 | },
1018 | "id": "e675f59e-ddd1-4835-8bc2-edd76c54fad4",
1019 | "created_at": "2022-05-02T15:13:29.901787+00:00",
1020 | "updated_at": "2022-05-02T15:13:29.901796+00:00"
1021 | }
1022 | ]
1023 | }
1024 | ```
1025 |
1026 | When it's necessary to filter by nested fields, use the dot notation for query parameter names:
1027 |
1028 | ```shell
1029 | curl https://api.example.com/v1/products?price.currency=EUR
1030 | ```
1031 |
1032 | Successful **200 OK** response:
1033 |
1034 | ```json
1035 | {
1036 | "data": [
1037 | {
1038 | "name": "Potato",
1039 | "price": {
1040 | "currency": "EUR",
1041 | "value": 1000
1042 | },
1043 | "id": "3278430a-512e-4eca-967b-3dc59743d0bc",
1044 | "created_at": "2022-05-02T15:13:26.517562+00:00",
1045 | "updated_at": "2022-05-02T15:13:26.517572+00:00"
1046 | }
1047 | ]
1048 | }
1049 | ```
1050 |
1051 | ### MUST use POST instead of GET to pass sensitive data
1052 |
1053 | In some cases you might need to pass sensitive data along with your `GET` request. Since `GET` calls don't have a request body, make sure you never pass this data in a request URI.
1054 |
1055 | Instead, consider passing this data in HTTP headers, which would be much more secure. When it's not possible for some reason, then you can change your `GET` call to `POST` and pass sensitive data in a request body.
1056 |
1057 | :x: Not recommended
1058 |
1059 | ```shell
1060 | curl https://api.example.com/v1/resources?sensitive_data=sensitive_value
1061 | ```
1062 |
1063 | :+1: Recommended
1064 |
1065 | ```shell
1066 | curl -X POST https://api.example.com/v1/resources \
1067 | -H 'Content-Type: application/json' \
1068 | -d '{
1069 | "sensitive_data": "sensitive_value"
1070 | }'
1071 | ```
1072 |
1073 |
1074 | ### MUST update parts of a resource via PATCH to a resource URI
1075 |
1076 | To update a resource, an API client should send only the fields that need to be changed. All the other fields should stay intact.
1077 |
1078 | **Note**: A successful `PATCH` request must always return the updated resource in a response.
1079 |
1080 | **Note**: The entire `PATCH` operation is atomic. This means that if some fields cannot be set to the specified values, the entire `PATCH` request should be rejected with a validation error.
1081 |
1082 | Example of a `PATCH` request:
1083 |
1084 | ```shell
1085 | curl -X PATCH https://api.example.com/v1/products/e675f59e-ddd1-4835-8bc2-edd76c54fad4 \
1086 | -H 'Content-Type: application/json' \
1087 | -d '{
1088 | "name": "New potato"
1089 | }'
1090 | ```
1091 |
1092 | Successful response (**200 OK**) with changed `name` and `updated_at` fields:
1093 |
1094 | ```json
1095 | {
1096 | "name": "New potato",
1097 | "description": "This is a potato",
1098 | "price": {
1099 | "currency": "EUR",
1100 | "value": 1000
1101 | },
1102 | "id": "e675f59e-ddd1-4835-8bc2-edd76c54fad4",
1103 | "created_at": "2022-05-02T15:13:29.901787+00:00",
1104 | "updated_at": "2022-07-02T15:13:29.901787+00:00"
1105 | }
1106 | ```
1107 |
1108 | Also, for nullable fields it should be possible to set them back to `null`. For example:
1109 |
1110 | ```shell
1111 | curl -X PATCH https://api.example.com/v1/products/e675f59e-ddd1-4835-8bc2-edd76c54fad4 \
1112 | -H 'Content-Type: application/json' \
1113 | -d '{
1114 | "description": null
1115 | }'
1116 | ```
1117 |
1118 | Successful response (**200 OK**) with changed `description` and `updated_at` fields:
1119 |
1120 | ```json
1121 | {
1122 | "name": "New potato",
1123 | "description": null,
1124 | "price": {
1125 | "currency": "EUR",
1126 | "value": 1000
1127 | },
1128 | "id": "e675f59e-ddd1-4835-8bc2-edd76c54fad4",
1129 | "created_at": "2022-05-02T15:13:29.901787+00:00",
1130 | "updated_at": "2022-07-02T15:13:29.901787+00:00"
1131 | }
1132 | ```
1133 |
1134 |
1135 | ### MUST replace the entire resource via PUT to a resource URI
1136 |
1137 | In general, we should prefer using `PATCH` for changing a resource. However, in some cases it might be more convenient to use `PUT` to update the entire resource in one API call (for example, when uploading a `config` file from a file storage).
1138 |
1139 | **Note**: A successful `PUT` request must always return the updated resource in a response.
1140 |
1141 | Example of a `PUT` request:
1142 |
1143 | ```shell
1144 | curl -X PUT https://api.example.com/v1/company/config \
1145 | -H 'Content-Type: application/json' \
1146 | -d '{
1147 | "option1": "value1",
1148 | "option2": "value2",
1149 | "option3": "value3",
1150 | "option4": "value4"
1151 | }'
1152 | ```
1153 |
1154 | Successful **200 OK** response:
1155 |
1156 | ```json
1157 | {
1158 | "option1": "value1",
1159 | "option2": "value2",
1160 | "option3": "value3",
1161 | "option4": "value4"
1162 | }
1163 | ```
1164 |
1165 | ### MUST delete a resource via DELETE to a resource URI
1166 |
1167 | When deleting a resource, always consider using "soft delete" to mark a resource as deleted in our database but not actually deleting it. However, even in the case of soft delete, an API client should never see the difference with a regular delete operation and should treat a deleted resource as gone.
1168 |
1169 | **Note**: A request body is not allowed for `DELETE` calls.
1170 |
1171 | Example of a `DELETE` request:
1172 |
1173 | ```shell
1174 | curl -X DELETE https://api.example.com/v1/products/3278430a-512e-4eca-967b-3dc59743d0bc
1175 | ```
1176 |
1177 | A successful `DELETE` response must return a **204 No Content** HTTP status code and provide no response body.
1178 |
1179 | A failed `DELETE` response must return a **404 Not Found** HTTP status code, no matter if the specified resource ID is actually not found or if it is found but marked as deleted.
1180 |
1181 | **Note**: After deleting a resource (even in case of a "soft delete"), this resource instance must never be accessible again. This means, for example, that the `GET /v1/resources/{id}` call to this resource must always return **404 Not Found** after resource deletion.
1182 |
1183 | _Spectral rules_:
1184 |
1185 | * [monite-requests-delete-no-request-body](spectral/monite.section8-requests.yaml)
1186 |
1187 |
1188 | ### SHOULD NOT allow a DELETE operation for resource collections
1189 |
1190 | Mass deletion of resources can have a drastic impact on the data safety of API integrations, intentionally or unintentionally. We find these risks to be too high and decided to avoid introducing a `DELETE` operation for resource collections.
1191 |
1192 | :x: Not recommended
1193 |
1194 | ```shell
1195 | curl -X DELETE https://api.example.com/v1/resources
1196 | ```
1197 |
1198 |
1199 | ## Section 9: HTTP responses
1200 |
1201 | ### MUST use only standard HTTP status codes
1202 |
1203 | Our APIs must use only HTTP status codes that are defined by [RFC 9110](https://httpwg.org/specs/rfc9110.html#overview.of.status.codes).
1204 |
1205 | Creating custom status codes is not allowed.
1206 |
1207 | ### MUST use standard HTTP status codes properly
1208 |
1209 | When using standard HTTP status codes, we must return them to identify the use cases according to the [RFC 9110](https://httpwg.org/specs/rfc9110.html#overview.of.status.codes) standard.
1210 |
1211 | For example, in case of a resource not found, we must return 404 (Not Found) and not something different.
1212 |
1213 | This way we can ensure that our API behavior is predictable and consistent for API clients.
1214 |
1215 | ### SHOULD use the limited set of HTTP status codes
1216 |
1217 | To minimize the amount of HTTP status codes that our clients need to process, we should stick to a limited subset of codes that make sense to use for our API.
1218 |
1219 | Currently, this list is the following:
1220 |
1221 | - '200' (OK)
1222 | - '201' (Created)
1223 | - '202' (Accepted)
1224 | - '204' (No Content)
1225 | - '400' (Bad Request)
1226 | - '401' (Unauthorized)
1227 | - '403' (Forbidden)
1228 | - '404' (Not Found)
1229 | - '405' (Method Not Allowed)
1230 | - '406' (Not Acceptable)
1231 | - '409' (Conflict)
1232 | - '422' (Unprocessable Content)
1233 | - '500' (Internal Server Error)
1234 |
1235 | ### MUST return the predefined set of HTTP status codes for GET
1236 |
1237 | For `GET` responses, only the following codes are allowed:
1238 |
1239 | | **Code** | **Comment** | `GET /resources` | `GET /resources/{id}` |
1240 | |----------|-------------------------------------------------------|--------------------|-----------------------|
1241 | | 200 | To return a resource or a list of resources | :white_check_mark: | :white_check_mark: |
1242 | | 400 | To indicate an error with parsing a request | :white_check_mark: | :white_check_mark: |
1243 | | 401 | To respond to unauthorized requests | :white_check_mark: | :white_check_mark: |
1244 | | 403 | To indicate that accessing a resource is forbidden | :white_check_mark: | :white_check_mark: |
1245 | | 404 | To indicate that an individual resource is not found | | :white_check_mark: |
1246 | | 405 | To indicate that the requested method is not allowed | :white_check_mark: | :white_check_mark: |
1247 | | 422 | To indicate that submitted values cannot be processed | :white_check_mark: | :white_check_mark: |
1248 | | 500 | To inform about an internal error on a platform side | :white_check_mark: | :white_check_mark: |
1249 |
1250 | ### MUST return the predefined set of HTTP status codes for POST
1251 |
1252 | For `POST` responses, only the following codes are allowed:
1253 |
1254 | | **Code** | **Comment** | `POST /resources` | `POST /resources/{id}/action` |
1255 | |----------|--------------------------------------------------------------------------------|--------------------|-------------------------------|
1256 | | 200 | To indicate that an action was successfully performed | | :white_check_mark: |
1257 | | 201 | To return a created resource | :white_check_mark: | |
1258 | | 202 | To indicate that the request was accepted and will be performed asynchronously | :white_check_mark: | :white_check_mark: |
1259 | | 400 | To indicate an error with parsing a request | :white_check_mark: | :white_check_mark: |
1260 | | 401 | To respond to unauthorized requests | :white_check_mark: | :white_check_mark: |
1261 | | 403 | To indicate that accessing a resource is forbidden | :white_check_mark: | :white_check_mark: |
1262 | | 404 | To indicate that an individual resource is not found | | :white_check_mark: |
1263 | | 405 | To indicate that the requested method is not allowed | :white_check_mark: | :white_check_mark: |
1264 | | 422 | To indicate that submitted values cannot be processed | :white_check_mark: | :white_check_mark: |
1265 | | 500 | To inform about an internal error on a platform side | :white_check_mark: | :white_check_mark: |
1266 |
1267 | ### MUST return the predefined set of HTTP status codes for PATCH
1268 |
1269 | For `PATCH` responses, only the following codes are allowed:
1270 |
1271 | | **Code** | **Comment** |
1272 | |----------|-------------------------------------------------------|
1273 | | 200 | To return a resource |
1274 | | 400 | To indicate an error with parsing a request |
1275 | | 401 | To respond to unauthorized requests |
1276 | | 403 | To indicate that accessing a resource is forbidden |
1277 | | 404 | To indicate that an individual resource is not found |
1278 | | 405 | To indicate that the requested method is not allowed |
1279 | | 422 | To indicate that submitted values cannot be processed |
1280 | | 500 | To inform about an internal error on a platform side |
1281 |
1282 | ### MUST return the predefined set of HTTP status codes for PUT
1283 |
1284 | For `PUT` responses, only the following codes are allowed:
1285 |
1286 | | **Code** | **Comment** |
1287 | |----------|-------------------------------------------------------|
1288 | | 200 | To return a resource |
1289 | | 400 | To indicate an error with parsing a request |
1290 | | 401 | To respond to unauthorized requests |
1291 | | 403 | To indicate that accessing a resource is forbidden |
1292 | | 404 | To indicate that an individual resource is not found |
1293 | | 405 | To indicate that the requested method is not allowed |
1294 | | 422 | To indicate that submitted values cannot be processed |
1295 | | 500 | To inform about an internal error on a platform side |
1296 |
1297 | ### MUST return the predefined set of HTTP status codes for DELETE
1298 |
1299 | For `DELETE` responses, only the following codes are allowed:
1300 |
1301 | | **Code** | **Comment** |
1302 | |----------|-------------------------------------------------------|
1303 | | 204 | To indicate that resource deletion was successful |
1304 | | 400 | To indicate an error with parsing a request |
1305 | | 401 | To respond to unauthorized requests |
1306 | | 403 | To indicate that accessing a resource is forbidden |
1307 | | 404 | To indicate that an individual resource is not found |
1308 | | 405 | To indicate that the requested method is not allowed |
1309 | | 422 | To indicate that submitted values cannot be processed |
1310 | | 500 | To inform about an internal error on a platform side |
1311 |
1312 |
1313 | ## Section 10: HTTP headers
1314 |
1315 | ### MUST use lower kebab-case for HTTP header names
1316 |
1317 | We restrict HTTP header names to ASCII kebab-case strings.
1318 |
1319 | | :x: Not recommended | :+1: Recommended |
1320 | |----------------------------|-------------------------|
1321 | | X_Monite_Entity_ID | x-monite-entity-id |
1322 |
1323 | Spectral rule: [monite-headers-kebab-case](spectral/monite.section10-headers.yaml)
1324 |
1325 |
1326 | ## Section 11: Webhooks
1327 |
1328 | ### MUST send webhooks only via HTTPs with TLS 1.2+
1329 |
1330 | Webhooks payloads can contain sensitive information, which must never be available to any party between a webhook sender and a webhook receiver.
1331 |
1332 | For this reason, we must send webhooks to our API clients only via an encrypted TLS connection.
1333 |
1334 | ### SHOULD send webhooks only to endpoints that require authentication
1335 |
1336 | We should send webhooks only to endpoints that are secured with any of the modern authentication methods.
1337 |
1338 |
1339 | ## Section 12: Hypermedia
1340 |
1341 | ### SHOULD use absolute URIs for links to other resources
1342 |
1343 | Links to other resources must always use full absolute URIs.
1344 |
1345 | This makes it easier for API clients to resolve the URIs and retrieve relevant resources.
1346 |
1347 |
1348 | ## Section 13: Performance
1349 |
1350 | ### MUST protect API behind authentication
1351 |
1352 | ### MUST implement rate limiting
1353 |
1354 | ### SHOULD support pagination
1355 |
1356 | ### SHOULD provide regional access points
1357 |
1358 |
1359 | ## Section 14: Pagination
1360 |
1361 | ### SHOULD prefer cursor-based pagination over offset-based pagination
1362 |
1363 | ### MUST use consistent names for fields that implement pagination
1364 |
1365 |
1366 | ## Section 15: Compatibility & Versioning
1367 |
1368 | ### MUST support versioning
1369 |
1370 | ### SHOULD avoid breaking changes
1371 |
1372 | ### SHOULD treat adding optional API elements as non-breaking changes
1373 |
1374 | ### SHOULD treat renamings and deletion of API elements as breaking changes
1375 |
1376 | ### SHOULD support API clients in handling breaking changes
1377 |
1378 |
1379 | ## Section 16: Deprecation
1380 |
1381 | ### SHOULD inform API clients about API elements being deprecated
1382 |
1383 | ### SHOULD remove deprecated API elements over time
1384 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Guidelines
2 |
3 | To access the complete Monite API Style Guide, please see [Guidelines](Guidelines.md).
4 |
5 |
6 | ## Purpose
7 |
8 | As an API-First company, we put extremely high expectations on the quality of [our APIs](https://docs.monite.com/reference/). That's why we need to have solid guidance on how we should build our APIs, how they should behave, and why we are making certain choices around our APIs.
9 |
10 | Although there are already a lot of good APIs and knowledge around building APIs in the industry, there is no single standard way of building Web APIs. This means that every company needs to make their own choices on what makes their API good, and we are not an exception to that.
11 |
12 | Our API Style Guide is a representation of our choices, and we want to keep it public to share our knowledge with our customers and anyone else who is interested in building modern Web APIs.
13 |
14 |
15 | ## Scope
16 |
17 | This style guide should be applied by our development teams to both **public**/**partner** and **internal** APIs. The main reasons for that:
18 |
19 | * The fewer differences we have between our internal and public API layers, the easier it will be for us to develop our platform.
20 | * Any API, even if it's internal at the moment, might be tasked to become public in the future. With this mindset we should build all our APIs externalizable from the beginning, so having a shared style guide will help us avoid unnecessary changes in the future.
21 |
22 |
23 | ## Target audiences
24 |
25 | Most of these guidelines are focused on technical aspects of API design and implementation, and therefore are points of interest mostly for software developers.
26 |
27 | However, there are certain aspects of these guidelines that are addressing more common issues and should be valuable for a broader group, including product managers, technical writers, technical support, developer experience engineers, and people in many other roles.
28 |
29 |
30 | ## Spectral
31 |
32 | We believe that nobody can remember all the rules in the API style, so it's key to be able to automatically validate as many rules as possible.
33 |
34 | For that purpose we are using [Spectral](https://stoplight.io/open-source/spectral/) that can lint API contracts in the [OpenAPI](https://www.openapis.org/) format.
35 |
36 | To start with Spectral, you can install it as an npm package or use other installation methods:
37 |
38 | ```bash
39 | npm install -g @stoplight/spectral-cli
40 | ```
41 |
42 | Additionally, you might want to install a [spellchecker](https://www.npmjs.com/package/spellchecker) package to check spelling of API names and descriptions:
43 |
44 | ```bash
45 | npm install spellchecker
46 | ```
47 |
48 | After that, you are ready to validate your OpenAPI file with the rulesets in this repository:
49 |
50 | ```bash
51 | spectral lint spectral/test-openapi.yaml -r spectral/monite.all.yaml
52 | ```
53 |
54 | For more detailed guidance on how to automate your style guide, see [Spectral](Spectral.md).
55 |
56 | ## Contributing
57 |
58 | We encourage everybody to contribute to this API Style Guide. Only together we can achieve high quality and clarity of all the guidelines, as well as keep them up-to-date and useful for the API community.
59 |
60 | It doesn't matter whether your official job title is an engineer or not - if you have some feedback and want to make this style guide better, please share with us.
61 |
62 | You can contribute in the following ways:
63 | * Create an issue (if you spotted a problem but not sure how to solve it best).
64 | * Create a merge request (if you have a good idea on how we should change our style guide).
65 | * Star, fork, and share the link to this repository with your network.
66 |
67 |
68 | ## See also
69 |
70 | There are a lot of other resources created and shared by some companies and API enthusiasts. In some of our work, we were relying on these resources; while others are listed here just to help you build the bigger picture.
71 |
72 | The list below is not the most comprehensive list of other API style guides, but can give you good insights on where else you can look for inspiration.
73 |
74 | ## Spectral Rulesets
75 |
76 | * [Spectral Rulesets Directory](https://github.com/stoplightio/spectral-rulesets)
77 | * [APIs You Won't Hate: Spectral Style Guide](https://github.com/apisyouwonthate/style-guide)
78 | * [Stoplight OWASP API Security Ruleset](https://github.com/stoplightio/spectral-owasp-ruleset)
79 |
80 | ## Organization Style Guides
81 |
82 | * [Zalando RESTful API and Event Guidelines](https://opensource.zalando.com/restful-api-guidelines/)
83 | * [Spectral Spelling and Grammar Ruleset](https://github.com/api-stuff/spectral-spelling-grammar)
84 | * [Microsoft REST API Guidelines](https://github.com/microsoft/api-guidelines)
85 | * [adidas API Guidelines](https://adidas.gitbook.io/api-guidelines)
86 |
87 | ## Other Style Guide Resources
88 |
89 | * [Google API Improvement Proposals](https://google.aip.dev/)
90 | * [API style book](http://apistylebook.com/design/guidelines/)
91 | * [SAP API Style Guide](https://help.sap.com/viewer/53e39c8b7c924c28a2575be50bc09786/PUBLIC/en-US/01e4b09a0bb24235b3618deb0618e1af.html)
92 | * [API Style Guides | Guidelines and Best Practices](https://stoplight.io/api-style-guides-guidelines-and-best-practices/)
93 | * [Postman Open Technologies - Governance Rules](https://www.postman.com/postman/workspace/postman-open-technologies-governance-rules/overview)
94 | * [API Guidelines in the Wild](https://dret.github.io/guidelines/)
95 |
96 |
--------------------------------------------------------------------------------
/Spectral.md:
--------------------------------------------------------------------------------
1 | # How to use Spectral
2 |
3 | To automate every rule we have in our API style guide, we use [Spectral](https://stoplight.io/open-source/spectral), which is an open-source framework that allows to "lint" [OpenAPI](https://www.openapis.org/) files and check their validity.
4 |
5 | Spectral rules can be used both for ensuring that the OpenAPI file is compliant with the OpenAPI specification, as well as to validate the design and behavior of the API itself.
6 |
7 | The current versions we support:
8 |
9 | * Spectral: 6.5.0
10 | * OpenAPI: 3.0.2
11 |
12 | ## Getting started
13 |
14 | Spectral in an NPM package, so you need to [install Node.js and NPM](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) first.
15 |
16 | Then, you can install Spectral [in different ways](https://meta.stoplight.io/docs/spectral/b8391e051b7d8-installation). For example, do the following:
17 |
18 | ```bash
19 | npm install -g @stoplight/spectral-cli
20 | ```
21 |
22 | Additionally, you might want to install a [spellchecker](https://www.npmjs.com/package/spellchecker) package to check spelling of API names and descriptions:
23 |
24 | ```bash
25 | npm install spellchecker
26 | ```
27 |
28 | After that, you are ready to validate your OpenAPI file with the rulesets in this repository:
29 |
30 | ```bash
31 | spectral lint spectral/test-openapi.yaml -r spectral/monite.all.yaml
32 | ```
33 |
34 | ## Constructing your style guide
35 |
36 | We publish our API style guide in a modular way, which allows you to choose yourself what rules you want to apply in your case.
37 |
38 | ### Choose style guide sections
39 |
40 | First of all, you can decide which sections to include or exclude from the checks. For that, customize the `extends` section of the root `monite.all.yaml` file and remove unnecessary sections or mark them with `#`:
41 |
42 | ```yaml
43 | extends:
44 | - "spectral:oas"
45 | - monite.openapi-structure.yaml
46 | - monite.section1-general.yaml
47 | # - monite.section2-language.yaml
48 | # - monite.section3-security.yaml
49 | - monite.section4-data-types.yaml
50 | ```
51 |
52 | ### Change rule severity level
53 |
54 | If you want to change the importance of a specific rule, just add it to the `rules` section of the root `monite.all.yaml` file and set the desired severity level. For example:
55 |
56 | ```yaml
57 | rules:
58 | monite-language-spelling-names: warn
59 | ```
60 |
61 | ### Turn of some rules
62 |
63 | If you want to completely disable a certain rule, set its severity to `off`.
64 |
65 | ```yaml
66 | rules:
67 | monite-language-spelling-names: off
68 | ```
69 |
70 | ### Choose your versioning scheme
71 |
72 | We have a few predefined versioning schemes you can choose from. Depending on your needs, you can enable one and disable another.
73 |
74 | ```yaml
75 | rules:
76 | monite-versioning-date-format: off
77 | monite-versioning-semantic: error
78 | ```
79 |
80 | ### Edit a spellcheker's dictionary
81 |
82 | You can also add or remove terms from the custom dictionary used by a spell checker. To do this, go to the `/spectral/functions/check-spelling.js` and `/spectral/functions/check-spelling-code.js` files and customize the `exceptions` array:
83 |
84 | ```
85 | const exceptions = ["asc","bic","iban"];
86 | ```
87 |
88 | ## Help us improve!
89 |
90 | Obviously, there are still so many things we can do to cover the entire style guide and make all the rules more efficient.
91 |
92 | If you see any opportunity we can improve this style guide, please don't hesitate to raise an issue and make a suggestion.
93 |
94 | Many thanks in advance, and we hope you will find this repo useful for your projects.
--------------------------------------------------------------------------------
/spectral/functions/check-spelling-code.js:
--------------------------------------------------------------------------------
1 | const spellChecker = require('spellchecker');
2 | const exceptions = ["bic","datetime","gt","gte","icontains","iban","idempotency","isnull","lt","lte","md5","mimetype","oid","userpic"];
3 |
4 | const codeStyleRegex = /[_]/ // snake_case
5 |
6 | export default (input) => {
7 |
8 | const words = input.split(codeStyleRegex);
9 | const mistakes = words
10 | .filter((word) => !exceptions.includes(word))
11 | .filter((word) => spellChecker.isMisspelled(word));
12 |
13 | if (mistakes.length > 0) {
14 | return [{
15 | message: `Spelling mistakes found: ${mistakes.join(', ')}`,
16 | }];
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/spectral/functions/check-spelling.js:
--------------------------------------------------------------------------------
1 | const spellChecker = require('spellchecker');
2 | const exceptions = ["Jinja2","asc","bic","iban"];
3 |
4 | const separatorsRegex = /\s/ // any whitespace
5 |
6 | export default (input) => {
7 |
8 | const words = input.replace(/`/g, '').split(separatorsRegex);
9 | const mistakes = words
10 | .filter((word) => !exceptions.includes(word))
11 | .filter((word) => spellChecker.isMisspelled(word));
12 |
13 | if (mistakes.length > 0) {
14 | return [{
15 | message: `Spelling mistakes found: ${mistakes.join(', ')}`,
16 | }];
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/spectral/functions/is-object-schema.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assertObjectSchema = (schema) => {
4 | if (schema.type !== 'object') {
5 | throw 'Schema type is not an object.';
6 | }
7 | if (schema.additionalProperties) {
8 | throw 'Schema is a map.';
9 | }
10 | };
11 |
12 | const check = (schema) => {
13 | const combinedSchemas = [...(schema.anyOf || []), ...(schema.oneOf || []), ...(schema.allOf || [])];
14 | if (combinedSchemas.length > 0) {
15 | combinedSchemas.forEach(check);
16 | } else {
17 | assertObjectSchema(schema);
18 | }
19 | };
20 |
21 | export default (targetValue) => {
22 | try {
23 | check(targetValue);
24 | } catch (ex) {
25 | return [
26 | {
27 | message: ex,
28 | },
29 | ];
30 | }
31 | };
32 |
--------------------------------------------------------------------------------
/spectral/monite.all.yaml:
--------------------------------------------------------------------------------
1 | extends:
2 | - "spectral:oas"
3 | - monite.openapi-structure.yaml
4 | - monite.section1-general.yaml
5 | - monite.section2-language.yaml
6 | - monite.section3-security.yaml
7 | - monite.section4-data-types.yaml
8 | - monite.section5-uri.yaml
9 | - monite.section6-rest.yaml
10 | - monite.section7-json.yaml
11 | - monite.section8-requests.yaml
12 | - monite.section9-responses.yaml
13 | - monite.section10-headers.yaml
14 | # - monite.section11-webhooks.yaml
15 | # - monite.section12-hypermedia.yaml
16 | - monite.section13-performance.yaml
17 | # - monite.section14-pagination.yaml
18 | - monite.section15-versioning.yaml
19 | # - monite.section16-deprecation.yaml
20 |
21 |
22 | documentationUrl: https://github.com/team-monite/api-style-guide
23 |
24 | #aliases:
25 | # HeaderNames:
26 | # - "$..parameters.[?(@.in === 'header')].name"
27 | # Info:
28 | # - "$..info"
29 | # InfoDescription:
30 | # - "#Info.description"
31 | # Paths:
32 | # - "$.paths[*]~"
33 | # Tags:
34 | # - "$.tags[*]"
35 |
36 | rules:
37 | # https://meta.stoplight.io/docs/spectral/docs/reference/openapi-rules.md#oas3-schema
38 | oas3-schema: true
39 |
40 | path-keys-no-trailing-slash: error
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/spectral/monite.openapi-structure.yaml:
--------------------------------------------------------------------------------
1 | # ##########################################################
2 | # OpenAPI validation #
3 | # This ruleset validates the elements of the OpenAPI file #
4 | # to make sure it's clear and consistent #
5 | # ##########################################################
6 |
7 | rules:
8 |
9 | monite-openapi-version-302:
10 | message: The OpenAPI format must be 3.0.2
11 | severity: off
12 | given: "$"
13 | then:
14 | field: openapi
15 | function: pattern
16 | functionOptions:
17 | match: 3.0.2
18 |
19 | monite-openapi-version-310:
20 | message: The OpenAPI format must be 3.1.0
21 | severity: error
22 | given: "$"
23 | then:
24 | field: openapi
25 | function: pattern
26 | functionOptions:
27 | match: 3.1.0
28 |
29 | monite-openapi-path-version-number:
30 | message: Version numbers (like "/v1") should be in "servers", not in "paths"
31 | severity: warn
32 | given: "$.paths[*]~"
33 | then:
34 | function: pattern
35 | functionOptions:
36 | notMatch: /((?:\/)(v|version)[0-9]{1,3}(?:\/)?)/i
37 |
38 | monite-openapi-path-id-parameter-name-format:
39 | message: Path parameter names should be "resource_id", not just "id"
40 | severity: warn
41 | given: "$..parameters[?(@.in == 'path')]"
42 | then:
43 | field: name
44 | function: pattern
45 | functionOptions:
46 | notMatch: \b(id|Id|ID|iD)\b
47 |
48 | monite-openapi-schemas-and-examples-in-components:
49 | message: Request body schema should only reference components
50 | severity: error
51 | given:
52 | - "$..requestBody.content..*.schema.$ref"
53 | - "$..responses.*.content..*.schema.$ref"
54 | - "$..responses.*.content..*.examples.$ref"
55 | then:
56 | function: pattern
57 | functionOptions:
58 | match: "#/components/"
59 |
60 | monite-openapi-schema-in-name:
61 | message: The schema name should not have "Schema" in it, this is redundant
62 | severity: info
63 | given: "$.components.schemas.*~"
64 | then:
65 | function: pattern
66 | functionOptions:
67 | notMatch: (Schema)
68 |
69 | monite-openapi-security-schemes-defined:
70 | message: Security schemes are missing in this OpenAPI
71 | severity: error
72 | given: "$..components"
73 | then:
74 | field: securitySchemes
75 | function: truthy
76 |
77 | monite-component-names-valid-characters:
78 | message: All component name MUST consist of the following characters `A..Z a..z 0..9 . _ -`
79 | severity: error
80 | given:
81 | - "$.components.schemas[*]~"
82 | - "$.components.parameters[*]~"
83 | - "$.components.securitySchemes[*]~"
84 | - "$.components.requestBodies[*]~"
85 | - "$.components.responses[*]~"
86 | - "$.components.headers[*]~"
87 | - "$.components.examples[*]~"
88 | - "$.components.links[*]~"
89 | - "$.components.callbacks[*]~"
90 | then:
91 | function: pattern
92 | functionOptions:
93 | match: ^[a-zA-Z0-9._-]+$
94 |
95 | monite-openapi-info-description-max-length:
96 | message: The info object description should be less than 200 characters
97 | severity: warn
98 | given: "$.info"
99 | then:
100 | field: description
101 | function: length
102 | functionOptions:
103 | max: 200
104 |
105 | monite-openapi-info-summary-max-length:
106 | message: The info object summary should be less than 30 characters
107 | severity: warn
108 | given: "$.info"
109 | then:
110 | field: summary
111 | function: length
112 | functionOptions:
113 | max: 30
114 |
115 | monite-openapi-tags-name-sentence-case:
116 | message: Tag names should start with a capital letter
117 | severity: warn
118 | given: "$.tags[*]"
119 | then:
120 | field: name
121 | function: pattern
122 | functionOptions:
123 | match: ^[A-Z].*
124 |
125 | monite-openapi-operation-summary:
126 | message: Each operations should have a summary
127 | severity: warn
128 | given: "$.paths.*[get,post,patch,put,delete,options,head,trace]"
129 | then:
130 | field: summary
131 | function: truthy
132 |
133 | monite-openapi-operation-summary-sentence-case:
134 | message: Operation summaries should start with a capital letter
135 | severity: warn
136 | given: "$.paths.*.*.summary"
137 | then:
138 | function: pattern
139 | functionOptions:
140 | match: ^[A-Z].*
141 |
142 | monite-openapi-error-response-body:
143 | message: Every error response should have a response body with content
144 | severity: warn
145 | given: "$.paths.[*].responses[?(@property.match(/^(4|5)/))]"
146 | then:
147 | field: content
148 | function: truthy
149 |
150 | monite-openapi-response-body-200x:
151 | message: All 200x responses except for 204 MUST include a response body
152 | severity: warn
153 | given: "$.paths.[?( @property === '200' || @property === '201' || @property === '202')]"
154 | then:
155 | field: content
156 | function: truthy
157 |
158 | monite-openapi-response-204-no-body:
159 | message: All 204 responses must not have a response body
160 | severity: warn
161 | given: "$.paths.[?( @property === '204')]"
162 | then:
163 | field: content
164 | function: falsy
165 |
166 | monite-openapi-number-boundaries:
167 | message: Numeric types need to have their minimum and maximum defined
168 | severity: info
169 | given:
170 | - $..properties.[?(@.type=="number")]
171 | - $..properties.[?(@.type=="integer")]
172 | then:
173 | - field: maximum
174 | function: defined
175 | - field: minimum
176 | function: defined
177 |
--------------------------------------------------------------------------------
/spectral/monite.section1-general.yaml:
--------------------------------------------------------------------------------
1 | # ##########################################################################################
2 | # Section 1: General #
3 | # This ruleset covers the General rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-1-general #
5 | # ##########################################################################################
6 |
7 | rules:
8 |
9 | monite-general-exposing-internals:
10 | message: Potentially exposing internals (words "private" or "internal" spotted)
11 | severity: warn
12 | given:
13 | - "$.info.title"
14 | - "$.info.summary"
15 | - "$.info.description"
16 | - "$.paths.*~"
17 | - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].name"
18 | - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].description"
19 | - "$.components.schemas.*~"
20 | - "$..properties.*~"
21 | then:
22 | function: pattern
23 | functionOptions:
24 | notMatch: (internal|Internal|private|Private)
25 |
--------------------------------------------------------------------------------
/spectral/monite.section10-headers.yaml:
--------------------------------------------------------------------------------
1 | # ################################################################################################
2 | # Section 10: HTTP headers #
3 | # This ruleset covers the HTTP headers rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-10-http-headers #
5 | # ################################################################################################
6 |
7 | rules:
8 |
9 | monite-headers-kebab-case:
10 | message: Header parameters must be kebab-case
11 | severity: error
12 | given: "$.paths.*.*.parameters[?(@.in=='header')].name"
13 | then:
14 | function: pattern
15 | functionOptions:
16 | match: ^([a-z]*)(-[a-z0-9][a-z0-9]*)*$
17 |
--------------------------------------------------------------------------------
/spectral/monite.section11-webhooks.yaml:
--------------------------------------------------------------------------------
1 | # ############################################################################################
2 | # Section 11: Webhooks #
3 | # This ruleset covers the Webhook rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-11-webhooks #
5 | # ############################################################################################
6 |
7 | rules:
8 |
9 |
--------------------------------------------------------------------------------
/spectral/monite.section12-hypermedia.yaml:
--------------------------------------------------------------------------------
1 | # ##############################################################################################
2 | # Section 12: Hypermedia #
3 | # This ruleset covers the Hypermedia rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-12-hypermedia #
5 | # ##############################################################################################
6 |
7 | rules:
8 |
9 |
--------------------------------------------------------------------------------
/spectral/monite.section13-performance.yaml:
--------------------------------------------------------------------------------
1 | # ################################################################################################
2 | # Section 13: Performance #
3 | # This ruleset covers the Performance rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-13-performance #
5 | # ################################################################################################
6 |
7 | rules:
8 |
9 | # TO DO
10 | monite-performance-rate-limiting:
11 | message: Rate limiting should be supported
12 | severity: warn
13 | given: "$.[responses][?(@property[0] == '2' )][headers]"
14 | then:
15 | - functionOptions:
16 | properties:
17 | - X-RateLimit-Limit
18 | - RateLimit-Limit
19 | function: xor
20 | - functionOptions:
21 | properties:
22 | - X-RateLimit-Remaining
23 | - RateLimit-Remaining
24 | function: xor
25 | - functionOptions:
26 | properties:
27 | - X-RateLimit-Reset
28 | - RateLimit-Reset
29 | function: xor
--------------------------------------------------------------------------------
/spectral/monite.section14-pagination.yaml:
--------------------------------------------------------------------------------
1 | # ##############################################################################################
2 | # Section 14: Pagination #
3 | # This ruleset covers the Pagination rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-14-pagination #
5 | # ##############################################################################################
6 |
7 | rules:
8 |
9 |
--------------------------------------------------------------------------------
/spectral/monite.section15-versioning.yaml:
--------------------------------------------------------------------------------
1 | # ############################################################################################################
2 | # Section 15: Compatibility & versioning #
3 | # This ruleset covers the Versioning rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-15-compatibility-versioning #
5 | # ############################################################################################################
6 |
7 | rules:
8 |
9 | monite-versioning-date-format:
10 | message: The API version must follow the YYYY-MM-DD format
11 | severity: error
12 | given: "$.info.version"
13 | then:
14 | function: pattern
15 | functionOptions:
16 | match: ^([0-9]{4}-[0-9]{2}-[0-9]{2})$
17 |
18 | monite-versioning-semantic:
19 | message: The API version must follow the semver format
20 | given: "$.info.version"
21 | severity: off
22 | then:
23 | function: pattern
24 | functionOptions:
25 | match: ^[0-9]+.[0-9]+.[0-9]+(-[a-z0-9+.-]+)?
26 |
--------------------------------------------------------------------------------
/spectral/monite.section16-deprecation.yaml:
--------------------------------------------------------------------------------
1 | # ###############################################################################################
2 | # Section 16: Deprecation #
3 | # This ruleset covers the Deprecation rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-16-deprecation #
5 | # ###############################################################################################
6 |
7 | rules:
8 |
9 |
--------------------------------------------------------------------------------
/spectral/monite.section2-language.yaml:
--------------------------------------------------------------------------------
1 | # ###########################################################################################
2 | # Section 2: Language #
3 | # This ruleset covers the Language rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-2-language #
5 | # ###########################################################################################
6 |
7 | functions:
8 | - check-spelling
9 | - check-spelling-code
10 |
11 | rules:
12 |
13 | monite-language-spelling-names:
14 | message: "{{error}}"
15 | severity: error
16 | given:
17 | - "$.paths.*~"
18 | - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].name"
19 | - "$..properties.*~"
20 | then:
21 | function: check-spelling-code
22 |
23 | monite-language-spelling-texts:
24 | message: "{{error}}"
25 | severity: warn
26 | given:
27 | - "$.info.title"
28 | - "$.info.summary"
29 | - "$.info.description"
30 | - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].description"
31 | - "$..properties.*.description"
32 | then:
33 | function: check-spelling
34 |
35 | monite-language-spelling-schema-names:
36 | message: "{{error}}"
37 | severity: warn
38 | given:
39 | - "$.components.schemas.*~"
40 | then:
41 | function: check-spelling
42 |
43 | monite-language-avoid-jargon:
44 | message: Try to avoid jargon and use commonly used terms instead
45 | severity: warn
46 | given:
47 | - "$.info.title"
48 | - "$.info.summary"
49 | - "$.info.description"
50 | - "$.paths.*~"
51 | - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].name"
52 | - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].description"
53 | - "$.components.schemas.*~"
54 | - "$..properties.*~"
55 | then:
56 | function: pattern
57 | functionOptions:
58 | notMatch: (pan)
59 |
60 | monite-language-non-inclusive:
61 | message: Non-inclusive terms have been found
62 | severity: error
63 | given:
64 | - "$.info.title"
65 | - "$.info.summary"
66 | - "$.info.description"
67 | - "$.paths.*~"
68 | - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].name"
69 | - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].description"
70 | - "$.components.schemas.*~"
71 | - "$..properties.*~"
72 | then:
73 | function: pattern
74 | functionOptions:
75 | notMatch: (blacklist|Blacklist|black_list|whitelist|Whitelist|white_list|slave|Slave)
76 |
77 | monite-language-filler-words:
78 | message: Filler words
79 | severity: warn
80 | given:
81 | - "$.paths.*~"
82 | - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].name"
83 | - "$.components.schemas.*~"
84 | - "$..properties.*~"
85 | then:
86 | function: pattern
87 | functionOptions:
88 | notMatch: (_info|_details)
89 |
--------------------------------------------------------------------------------
/spectral/monite.section3-security.yaml:
--------------------------------------------------------------------------------
1 | # ###########################################################################################
2 | # Section 3: Security #
3 | # This ruleset covers the Security rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-3-security #
5 | # ###########################################################################################
6 |
7 | rules:
8 |
9 | monite-security-https-only:
10 | message: We must use only HTTPS in our APIs
11 | severity: error
12 | given: "$.servers..url"
13 | then:
14 | function: pattern
15 | functionOptions:
16 | match: ^https://.*
17 |
18 | monite-security-no-http-basic:
19 | message: Basic authentication (with username/password) is not very secure
20 | severity: warn
21 | given: "$.components.securitySchemes[*]"
22 | then:
23 | field: scheme
24 | function: pattern
25 | functionOptions:
26 | notMatch: basic
27 |
28 | monite-security-no-secrets-in-path-or-query-parameters:
29 | message: Secrets, tokens, passwords and api keys must be passed in headers, not in path or query parameters
30 | severity: error
31 | given:
32 | - "$..parameters[?(@ && @.in && @.in.match(/path/))].name"
33 | - "$..parameters[?(@ && @.in && @.in.match(/query/))].name"
34 | then:
35 | function: pattern
36 | functionOptions:
37 | notMatch: /^(client_secret|token|access_token|refresh_token|id_token|password|secret|apikey)$/i
38 |
39 |
--------------------------------------------------------------------------------
/spectral/monite.section4-data-types.yaml:
--------------------------------------------------------------------------------
1 | # #########################################################################################################
2 | # Section 4: Data types and formats #
3 | # This ruleset covers the Data Types rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-4-data-types-and-formats #
5 | # #########################################################################################################
6 |
7 | rules:
8 |
9 | monite-data-missing-integer-format:
10 | message: Format is not specified for an integer property
11 | severity: warn
12 | given: "$.paths.*.*..schema..properties..[?(@.type=='integer')]"
13 | then:
14 | field: format
15 | function: defined
16 |
17 | monite-data-missing-number-format:
18 | message: Format is not specified for a number property
19 | severity: warn
20 | given: "$.paths.*.*..schema..properties..[?(@.type=='number')]"
21 | then:
22 | field: format
23 | function: defined
24 |
25 | monite-data-incorrect-integer-format:
26 | message: "Incorrect integer format: {{value}}. Must be one of: int32, int64"
27 | severity: error
28 | given: '$..[?(@.type=="integer")]'
29 | then:
30 | field: format
31 | function: enumeration
32 | functionOptions:
33 | values:
34 | - int32
35 | - int64
36 |
37 | monite-data-incorrect-number-format:
38 | message: "Incorrect number format: {{value}}. Must be one of: float, double"
39 | severity: error
40 | given: '$..[?(@.type=="number")]'
41 | then:
42 | field: format
43 | function: enumeration
44 | functionOptions:
45 | values:
46 | - float
47 | - double
48 |
49 | monite-data-incorrect-string-format:
50 | message: "Incorrect string format: {{value}}. See https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#must-use-only-allowed-data-types"
51 | severity: warn
52 | given: '$..[?(@.type=="string")]'
53 | then:
54 | field: format
55 | function: enumeration
56 | functionOptions:
57 | values:
58 | - date-time
59 | - date
60 | - time
61 | - email
62 | - uri
63 | - uuid
64 | - base64
65 | - binary
66 | - regex
67 | - lang
68 | - country
69 | - currency
70 | - color
71 |
72 |
--------------------------------------------------------------------------------
/spectral/monite.section5-uri.yaml:
--------------------------------------------------------------------------------
1 | # #######################################################################################
2 | # Section 5: URIs #
3 | # This ruleset covers the URI rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-5-uris #
5 | # #######################################################################################
6 |
7 | rules:
8 |
9 | monite-uri-no-backslash:
10 | message: The backslash is not allowed, use the forward slash ("/") instead
11 | severity: error
12 | given: "$.paths.*~"
13 | then:
14 | function: pattern
15 | functionOptions:
16 | notMatch: \\
17 |
18 | monite-uri-no-empty-path-segments:
19 | message: Empty path segments are not allowed
20 | severity: error
21 | given: "$.paths.*~"
22 | then:
23 | function: pattern
24 | functionOptions:
25 | notMatch: //
26 |
27 | monite-uri-no-uppercase:
28 | message: Uppercase is not allowed in path URIs
29 | severity: error
30 | given: "$.paths.*~"
31 | then:
32 | function: pattern
33 | functionOptions:
34 | notMatch: .*[A-Z]+.*
35 |
36 | monite-uri-no-api-suffix:
37 | message: Don't use "api" in a path, should be part of the host instead
38 | severity: error
39 | given: "$.paths[*]~"
40 | then:
41 | function: pattern
42 | functionOptions:
43 | notMatch: /.*(api\b).*/i
44 |
45 | monite-uri-no-file-extensions:
46 | message: Paths must not end with file types such as .json and .xml. Use response types instead.
47 | severity: error
48 | given: "$.paths[*]~"
49 | then:
50 | function: pattern
51 | functionOptions:
52 | notMatch: .(\.json|\.xml|\.html|\.txt)$
53 |
54 | monite-uri-path-snake-case:
55 | message: All resource names and actions must be lower snake_case.
56 | severity: error
57 | given: "$.paths.*~"
58 | then:
59 | function: pattern
60 | functionOptions:
61 | match: ^(([\/a-z][_a-z0-9\/]*)?({[^}]*})?)+$
62 |
63 | monite-uri-query-parameters-snake-case:
64 | message: Query parameters must be snake_case, with optional dots as delimiters
65 | severity: error
66 | given: "$.paths.*.*.parameters[?(@.in=='query')].name"
67 | then:
68 | function: pattern
69 | functionOptions:
70 | match: ^[a-z][a-z0-9]*(?:[_.]{1,2}[a-z0-9]+)*$
71 |
--------------------------------------------------------------------------------
/spectral/monite.section6-rest.yaml:
--------------------------------------------------------------------------------
1 | # #################################################################################################
2 | # Section 6: REST & Resources #
3 | # This ruleset covers the REST & Resources rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-6-rest-resources #
5 | # #################################################################################################
6 |
7 | rules:
8 |
9 | monite-rest-no-crud-in-uri-names:
10 | message: SHOULD NOT use CRUD function names in URIs
11 | severity: error
12 | given: "$.paths[*]~"
13 | then:
14 | function: pattern
15 | functionOptions:
16 | notMatch: ^\/(get|put|post|patch|options|head|trace|update|delete|create|list).*
17 |
18 | monite-rest-limited-resource-levels:
19 | message: We want to have a limited number of sub-resource levels
20 | severity: warn
21 | given: "$.paths.*~"
22 | then:
23 | function: pattern
24 | functionOptions:
25 | match: "^/[^/]*((/{[^}]*})*/[^/]*(/{[^}]*})*){0,3}/?$"
26 |
--------------------------------------------------------------------------------
/spectral/monite.section7-json.yaml:
--------------------------------------------------------------------------------
1 | # ###############################################################################################
2 | # Section 7: JSON payload #
3 | # This ruleset covers the JSON payload rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-7-json-payload #
5 | # ###############################################################################################
6 |
7 | functions:
8 | - is-object-schema
9 |
10 | rules:
11 |
12 | monite-json-root-json-objects:
13 | message: Requests and responses must be JSON objects
14 | severity: error
15 | given: "$.paths.*.*[responses,requestBody]..content..schema"
16 | then:
17 | function: is-object-schema
18 |
19 | monite-json-field-names-snake-case:
20 | message: Field name must be lower snake_case
21 | severity: error
22 | given: "$.paths.*.*[responses,requestBody]..content..schema..properties.*~"
23 | then:
24 | function: pattern
25 | functionOptions:
26 | match: ^[a-z_][a-z_0-9]*$
--------------------------------------------------------------------------------
/spectral/monite.section8-requests.yaml:
--------------------------------------------------------------------------------
1 | # ################################################################################################
2 | # Section 8: HTTP requests #
3 | # This ruleset covers the HTTP requests rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-8-http-requests #
5 | # ################################################################################################
6 |
7 | rules:
8 |
9 | monite-requests-get-no-request-body:
10 | message: There must be no request body for GET
11 | severity: error
12 | given: "$.paths.*.get"
13 | then:
14 | field: requestBody
15 | function: falsy
16 |
17 | monite-requests-delete-no-request-body:
18 | message: There must be no request body for DELETE
19 | severity: error
20 | given: "$.paths.*.delete"
21 | then:
22 | field: requestBody
23 | function: falsy
24 |
--------------------------------------------------------------------------------
/spectral/monite.section9-responses.yaml:
--------------------------------------------------------------------------------
1 | # #################################################################################################
2 | # Section 9: HTTP responses #
3 | # This ruleset covers the HTTP responses rules from the Monite API Style guide #
4 | # https://github.com/team-monite/api-style-guide/blob/main/Guidelines.md#section-9-http-responses #
5 | # #################################################################################################
6 |
7 | rules:
8 |
9 | monite-responses-default-response:
10 | message: Operation does not contain a default response
11 | severity: off
12 | given: $.paths.*.*.responses
13 | then:
14 | field: default
15 | function: truthy
16 |
17 | monite-responses-standard-status-codes:
18 | message: Response codes must be limited to a small predefined set of HTTP status codes
19 | severity: error
20 | given: $.paths.*.*.responses.*~
21 | then:
22 | function: enumeration
23 | functionOptions:
24 | values:
25 | - '200'
26 | - '201'
27 | - '202'
28 | - '204'
29 | - '400'
30 | - '401'
31 | - '403'
32 | - '404'
33 | - '405'
34 | - '406'
35 | - '409'
36 | - '416'
37 | - '422'
38 | - '500'
39 | - default
40 |
41 | monite-responses-error-not-rfc7807:
42 | message: All errors must follow RFC 7807
43 | severity: off
44 | given: "$.paths.[*].responses[?(@property.match(/^(4|5)/))].content.*~"
45 | then:
46 | function: enumeration
47 | functionOptions:
48 | values:
49 | - application/problem+json
50 |
51 | monite-responses-error-unknown-format:
52 | description: All error responses must be either RFC 7807 or application/json or application/xml.
53 | severity: error
54 | given: "$.paths.[*].responses[?(@property.match(/^(4|5)/))].content.*~"
55 | then:
56 | function: enumeration
57 | functionOptions:
58 | values:
59 | - application/problem+json
60 | - application/json
61 | - application/xml
62 |
63 | monite-responses-media-types-200:
64 | message: Any 200 response SHOULD only return media types as defined
65 | severity: warn
66 | given: "$.paths.[*].responses[?(@property.match(/^(2)/))].content.*~"
67 | then:
68 | function: enumeration
69 | functionOptions:
70 | values:
71 | - text/csv
72 | - application/zip
73 | - application/json
74 | - application/xml
75 | - multipart/form-data
76 |
77 | monite-responses-get-200-status-code:
78 | message: A GET operation must have a 200 status code for the response
79 | severity: error
80 | given: "$.paths[*].get.responses"
81 | then:
82 | field: '200'
83 | function: truthy
84 |
85 | monite-responses-get-200-media-type:
86 | message: A GET operation should have an application/json media type for 200 response
87 | severity: warn
88 | given: "$paths.get.responses.200.content"
89 | then:
90 | field: application/json
91 | function: truthy
92 |
93 | monite-responses-get-no-409:
94 | message: GET responses should not include a 409 response
95 | severity: warn
96 | given: "$.paths.*[?(@property === 'get' && @.responses && @.responses['409'])]"
97 | then:
98 | function: falsy
99 |
100 | monite-responses-post-201-status-code:
101 | message: A POST operation should have a 201 status code for the response
102 | severity: warn
103 | given: "$.paths[*].post.responses"
104 | then:
105 | field: '201'
106 | function: truthy
107 |
108 | monite-responses-post-201-media-type:
109 | message: POST responses should have a JSON body
110 | severity: error
111 | given: "$paths.post.responses.201.content"
112 | then:
113 | field: application/json
114 | function: truthy
115 |
116 | monite-responses-put-204-status-code:
117 | message: A PUT operation should have a 204 status code for the response
118 | severity: warn
119 | given: "$.paths[*].put.responses"
120 | then:
121 | field: '204'
122 | function: truthy
123 |
124 | monite-responses-put-500-status-code:
125 | message: A PUT operation should have a 500 status code for the response
126 | severity: warn
127 | given: "$.paths[*].put.responses"
128 | then:
129 | field: '500'
130 | function: truthy
131 |
132 | monite-responses-delete-204-status-code:
133 | message: A DELETE operation should have a 204 status code with the response
134 | severity: warn
135 | given: "$.paths[*].delete.responses"
136 | then:
137 | field: '204'
138 | function: truthy
--------------------------------------------------------------------------------
/spectral/random.examples.yaml:
--------------------------------------------------------------------------------
1 |
2 | rules:
3 |
4 | name-camel-case:
5 | message: Name should be camelCased
6 | severity: error
7 | given: "$.name"
8 | then:
9 | function: casing
10 | functionOptions:
11 | type: camel
12 |
13 | operation-id-snake-case:
14 | message: Your operations IDs need to be camel case
15 | given: "$.paths.*[get,post,patch,put,delete].operationId"
16 | then:
17 | function: casing
18 | functionOptions:
19 | type: snake
20 |
--------------------------------------------------------------------------------
/spectral/test.bash:
--------------------------------------------------------------------------------
1 | spectral lint test-openapi.yaml -r monite.all.yaml
2 |
--------------------------------------------------------------------------------