-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobileapi-rules.yml
More file actions
105 lines (95 loc) · 3.72 KB
/
Copy pathmobileapi-rules.yml
File metadata and controls
105 lines (95 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
extends:
- spectral:oas
rules:
# MobileAPI.dev: every operation must declare a summary in Title Case.
mobileapi-operation-summary-required:
description: Every operation must have a summary.
given: "$.paths.*[get,post,put,patch,delete]"
severity: error
then:
field: summary
function: truthy
mobileapi-operation-summary-title-case:
description: Operation summaries should be in Title Case (first word capitalized, no trailing period).
given: "$.paths.*[get,post,put,patch,delete].summary"
severity: warn
then:
function: pattern
functionOptions:
match: "^[A-Z\\[].*[^\\.]$"
# MobileAPI.dev: tags must use lowercase-hyphenated form (Django REST Framework default).
mobileapi-tags-lowercase-hyphen:
description: Tags should be lowercase, hyphen-separated.
given: "$.paths.*[get,post,put,patch,delete].tags[*]"
severity: warn
then:
function: pattern
functionOptions:
match: "^[a-z0-9][a-z0-9\\-]*$"
# MobileAPI.dev: every operation must declare an operationId for client codegen.
mobileapi-operation-id-required:
description: Every operation must declare an operationId.
given: "$.paths.*[get,post,put,patch,delete]"
severity: error
then:
field: operationId
function: truthy
# MobileAPI.dev: paths use a trailing slash (Django REST Framework convention).
mobileapi-path-trailing-slash:
description: Paths should end with a trailing slash (Django convention).
given: "$.paths"
severity: warn
then:
function: pattern
functionOptions:
match: "/$"
field: "@key"
# MobileAPI.dev: every operation should declare a 200/201 response.
mobileapi-success-response-required:
description: Every operation should declare a 2xx success response.
given: "$.paths.*[get,post,put,patch,delete].responses"
severity: warn
then:
function: truthy
field: "200"
# MobileAPI.dev: every operation should document a 401 Unauthorized response.
mobileapi-unauthorized-response-documented:
description: Authenticated operations should document a 401 response.
given: "$.paths[?(@property != '/api-token-auth/' && @property != '/status/' && @property != '/payment_successful' && @property != '/payment_successful/')]*[get,post,put,patch,delete].responses"
severity: info
then:
function: truthy
field: "401"
# MobileAPI.dev: rate-limited operations should document 429 responses.
mobileapi-rate-limit-response-documented:
description: Operations that consume credits should document a 429 Too Many Requests response.
given: "$.paths[?(@property != '/api-token-auth/' && @property != '/status/')]*[get,post,put,patch,delete].responses"
severity: info
then:
function: truthy
field: "429"
# MobileAPI.dev: schemas should include id and human-readable name where applicable.
mobileapi-schema-id-property:
description: Resource schemas should include an 'id' property as primary key.
given: "$.components.schemas[?(@.type == 'object')]"
severity: info
then:
field: properties.id
function: truthy
# MobileAPI.dev: prefer ApiKeyHeader (Authorization) over ApiKeyQuery for production traffic.
mobileapi-prefer-header-auth:
description: Document Authorization header as primary auth, query parameter as fallback only.
given: "$.components.securitySchemes"
severity: info
then:
field: ApiKeyHeader
function: truthy
# MobileAPI.dev: server URL should be HTTPS only in production.
mobileapi-https-server:
description: Production server URL must use HTTPS.
given: "$.servers[*].url"
severity: error
then:
function: pattern
functionOptions:
match: "^https://"