@radicaltools/cli 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -16
- package/dist/hub-catalogue/concern/concern-api-collections.radical +1136 -0
- package/dist/hub-catalogue/concern/concern-api-errors.radical +1180 -0
- package/dist/hub-catalogue/concern/concern-api-evolution.radical +449 -210
- package/dist/hub-catalogue/concern/concern-api-idempotency.radical +1218 -0
- package/dist/hub-catalogue/concern/concern-api-resource-design.radical +1102 -0
- package/dist/hub-catalogue/concern/concern-api-style-guide.radical +1210 -0
- package/dist/hub-catalogue/concern/concern-architecture-style.radical +287 -131
- package/dist/hub-catalogue/concern/concern-audit-trail.radical +1096 -0
- package/dist/hub-catalogue/concern/concern-authentication.radical +247 -37
- package/dist/hub-catalogue/concern/concern-authorization.radical +311 -89
- package/dist/hub-catalogue/concern/concern-availability.radical +287 -63
- package/dist/hub-catalogue/concern/concern-backend-stack.radical +300 -381
- package/dist/hub-catalogue/concern/concern-backup-recovery.radical +385 -129
- package/dist/hub-catalogue/concern/concern-caching.radical +1294 -0
- package/dist/hub-catalogue/concern/concern-capacity.radical +194 -81
- package/dist/hub-catalogue/concern/concern-code-documentation.radical +1397 -0
- package/dist/hub-catalogue/concern/concern-code-quality-gate.radical +1409 -0
- package/dist/hub-catalogue/concern/concern-code-review-branching.radical +1416 -0
- package/dist/hub-catalogue/concern/concern-code-style.radical +1058 -0
- package/dist/hub-catalogue/concern/concern-communication-style.radical +473 -167
- package/dist/hub-catalogue/concern/concern-data-classification.radical +970 -0
- package/dist/hub-catalogue/concern/concern-data-consistency.radical +339 -308
- package/dist/hub-catalogue/concern/concern-data-store.radical +480 -158
- package/dist/hub-catalogue/concern/concern-decomposition.radical +260 -85
- package/dist/hub-catalogue/concern/concern-definition-of-done.radical +1214 -0
- package/dist/hub-catalogue/concern/concern-delivery-metrics.radical +966 -0
- package/dist/hub-catalogue/concern/concern-dependency-hygiene.radical +1345 -0
- package/dist/hub-catalogue/concern/concern-deployment.radical +343 -92
- package/dist/hub-catalogue/concern/concern-encryption.radical +339 -76
- package/dist/hub-catalogue/concern/concern-error-handling-logging.radical +1197 -0
- package/dist/hub-catalogue/concern/concern-eu-dora.radical +1321 -0
- package/dist/hub-catalogue/concern/concern-frontend-stack.radical +467 -160
- package/dist/hub-catalogue/concern/concern-incident-management.radical +1204 -0
- package/dist/hub-catalogue/concern/concern-infrastructure.radical +1300 -268
- package/dist/hub-catalogue/concern/concern-integration-resilience.radical +88 -51
- package/dist/hub-catalogue/concern/concern-messaging.radical +173 -140
- package/dist/hub-catalogue/concern/concern-module-boundaries.radical +162 -159
- package/dist/hub-catalogue/concern/concern-observability.radical +224 -275
- package/dist/hub-catalogue/concern/concern-operational-readiness.radical +1249 -0
- package/dist/hub-catalogue/concern/concern-personal-data.radical +637 -122
- package/dist/hub-catalogue/concern/concern-quality-priorities.radical +1091 -0
- package/dist/hub-catalogue/concern/concern-rate-limiting.radical +433 -141
- package/dist/hub-catalogue/concern/concern-release-versioning.radical +1358 -0
- package/dist/hub-catalogue/concern/concern-retention.radical +1399 -0
- package/dist/hub-catalogue/concern/concern-secrets.radical +332 -74
- package/dist/hub-catalogue/concern/concern-secure-coding.radical +1379 -0
- package/dist/hub-catalogue/concern/concern-secure-development.radical +1245 -0
- package/dist/hub-catalogue/concern/concern-security-detection.radical +1153 -0
- package/dist/hub-catalogue/concern/concern-supply-chain.radical +257 -183
- package/dist/hub-catalogue/concern/concern-technical-debt.radical +1450 -0
- package/dist/hub-catalogue/concern/concern-technology-lifecycle.radical +1145 -0
- package/dist/hub-catalogue/concern/concern-tenant-isolation.radical +271 -137
- package/dist/hub-catalogue/concern/concern-test-strategy.radical +243 -224
- package/dist/hub-catalogue/concern/concern-threat-modelling.radical +1143 -0
- package/dist/index.js +3680 -2074
- package/package.json +1 -1
|
@@ -0,0 +1,1102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hub": {
|
|
3
|
+
"id": "concern-api-resource-design",
|
|
4
|
+
"category": "concern",
|
|
5
|
+
"name": "Resource design",
|
|
6
|
+
"description": "How an HTTP API's resources look to its callers: how fields and paths are named, what each method and status code means, where operations that are not create, read, update or delete go, and how work that outlasts a request reports its outcome. The snippets lint the OpenAPI document with Spectral and test the running API with Vitest and supertest.",
|
|
7
|
+
"tags": [
|
|
8
|
+
"api",
|
|
9
|
+
"rest",
|
|
10
|
+
"http",
|
|
11
|
+
"resource design",
|
|
12
|
+
"openapi",
|
|
13
|
+
"spectral"
|
|
14
|
+
],
|
|
15
|
+
"requiredMetamodel": "c4-ddd-governance-builtin",
|
|
16
|
+
"concern": {
|
|
17
|
+
"id": "api-resource-design",
|
|
18
|
+
"trigger": "LIST RELATIONS WHERE source.type != \"person\" AND target.external != true AND (target.type = \"container\" OR target.type = \"component\")",
|
|
19
|
+
"applyTo": "target",
|
|
20
|
+
"why": "other parts and systems call these elements over an API, so how its resources, paths, fields, methods and status codes look has to be decided.",
|
|
21
|
+
"group": "api"
|
|
22
|
+
},
|
|
23
|
+
"sources": [
|
|
24
|
+
{
|
|
25
|
+
"title": "RFC 9110, HTTP Semantics (9.2 method properties, 10.2 Allow and Location, 15 status codes)",
|
|
26
|
+
"url": "https://www.rfc-editor.org/rfc/rfc9110"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"title": "RFC 3339, Date and Time on the Internet: Timestamps",
|
|
30
|
+
"url": "https://www.rfc-editor.org/rfc/rfc3339"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"title": "RFC 7396, JSON Merge Patch",
|
|
34
|
+
"url": "https://www.rfc-editor.org/rfc/rfc7396"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"title": "Microsoft Azure REST API Guidelines",
|
|
38
|
+
"url": "https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"title": "Zalando RESTful API and Event Guidelines",
|
|
42
|
+
"url": "https://opensource.zalando.com/restful-api-guidelines/"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"title": "Google AIP-122, Resource names",
|
|
46
|
+
"url": "https://google.aip.dev/122"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"title": "Google AIP-136, Custom methods",
|
|
50
|
+
"url": "https://google.aip.dev/136"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"title": "Google AIP-140, Field names",
|
|
54
|
+
"url": "https://google.aip.dev/140"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"title": "Google AIP-151, Long-running operations",
|
|
58
|
+
"url": "https://google.aip.dev/151"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"title": "Standard Webhooks specification",
|
|
62
|
+
"url": "https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"title": "Spectral: rulesets and core functions",
|
|
66
|
+
"url": "https://docs.stoplight.io/docs/spectral/cb95cf0d26b83-core-functions"
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"templateParams": [
|
|
70
|
+
{
|
|
71
|
+
"key": "CASING",
|
|
72
|
+
"title": "Field casing",
|
|
73
|
+
"label": "How are JSON fields and query parameters named?",
|
|
74
|
+
"hint": "The casing of fields shows in every client and every log line, and changing it later breaks every caller. If the API style guide pack adopted a published guide, answer as it does: Microsoft and Google use camelCase in JSON, Zalando snake_case.",
|
|
75
|
+
"defaultValue": "camel",
|
|
76
|
+
"options": [
|
|
77
|
+
{
|
|
78
|
+
"value": "camel",
|
|
79
|
+
"label": "camelCase",
|
|
80
|
+
"description": "customerId, createdAt, as the Microsoft Azure guidelines and Google's JSON mapping of field names write them. Pick it when callers are mostly JavaScript, TypeScript, Java or .NET, whose serializers produce it by default, or when the API sits beside Microsoft or Google APIs."
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"value": "snake",
|
|
84
|
+
"label": "snake_case",
|
|
85
|
+
"description": "customer_id, created_at, as the Zalando guidelines require. Pick it when callers and services are mostly Python or Ruby, or when the organisation already follows the Zalando guidelines."
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"key": "PATHS",
|
|
91
|
+
"title": "Paths",
|
|
92
|
+
"label": "How are words joined in a path segment?",
|
|
93
|
+
"hint": "Paths are the first thing a caller reads and the hardest thing to change. The guides agree on plural nouns, identifiers in braces and a limit on nesting (set in the details); they differ on how the words of one segment are joined.",
|
|
94
|
+
"defaultValue": "kebab",
|
|
95
|
+
"options": [
|
|
96
|
+
{
|
|
97
|
+
"value": "kebab",
|
|
98
|
+
"label": "kebab-case path segments",
|
|
99
|
+
"description": "/sales-orders/{orderId}/line-items: the Zalando guidelines require it and the Azure guidelines prefer it. Pick it by default: URLs are case-sensitive, and lower-case words joined by hyphens are the easiest to read, type and say aloud."
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"value": "camel",
|
|
103
|
+
"label": "camelCase path segments",
|
|
104
|
+
"description": "/salesOrders/{orderId}/lineItems: Google's resource names (AIP-122) require it and the Azure guidelines allow it. Pick it when the API follows Google's AIPs or its paths come from gRPC transcoding, where collection identifiers are camelCase."
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"key": "ACTIONS",
|
|
110
|
+
"title": "Actions",
|
|
111
|
+
"label": "Where do operations that are not create, read, update, delete or list go?",
|
|
112
|
+
"hint": "Cancel, approve, resend: some operations are not a plain write of a resource. The guides disagree here more than anywhere else, so the API has to pick one way and use it everywhere.",
|
|
113
|
+
"defaultValue": "custom",
|
|
114
|
+
"options": [
|
|
115
|
+
{
|
|
116
|
+
"value": "custom",
|
|
117
|
+
"label": "custom methods (POST /orders/{orderId}:cancel)",
|
|
118
|
+
"description": "A POST to the resource's path followed by a colon and a verb, as Google AIP-136 and the Azure guidelines' action operations do. Pick it when actions have inputs and side effects of their own and the verb should be visible in the path, the logs and the authorization rules."
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"value": "resource",
|
|
122
|
+
"label": "action resources (POST /orders/{orderId}/cancellations)",
|
|
123
|
+
"description": "Each action becomes a noun resource that records it, created with POST and readable afterwards, so paths stay verb-free as the Zalando guidelines require. Pick it when the record of the action matters (who cancelled, when, why) or the organisation follows the Zalando guidelines."
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"value": "patch",
|
|
127
|
+
"label": "status changes by PATCH",
|
|
128
|
+
"description": "An action is a write of the resource's status field, checked against the allowed transitions; a transition that is not allowed answers 409. Pick it when actions are mostly moves through a lifecycle with no input beyond the new status, and the API should stay plain create, read, update and delete."
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"key": "LRO",
|
|
134
|
+
"title": "Long-running work",
|
|
135
|
+
"label": "How does work that takes longer than a request report its outcome?",
|
|
136
|
+
"hint": "Gateways and load balancers cut long requests off (Amazon API Gateway after 29 seconds by default, a load balancer's idle timeout often after 60), and clients give up sooner. Work that can take longer must answer at once and report its outcome another way. The limit in seconds is set in the details.",
|
|
137
|
+
"defaultValue": "operation",
|
|
138
|
+
"options": [
|
|
139
|
+
{
|
|
140
|
+
"value": "operation",
|
|
141
|
+
"label": "an operation resource to poll",
|
|
142
|
+
"description": "The request answers 202 Accepted with an Operation-Location header; the caller polls /operations/{operationId} until its status is Succeeded, Failed or Canceled. This is the Azure status monitor and Google's AIP-151 operation. Pick it by default: any caller can follow it, with nothing of its own to host."
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"value": "callback",
|
|
146
|
+
"label": "a signed callback when the work ends",
|
|
147
|
+
"description": "The request answers 202 Accepted; when the work ends, its outcome is POSTed to the https URL the calling system registered, signed as the Standard Webhooks specification describes, and retried until it is accepted. Pick it for partners who run servers of their own and would otherwise poll many operations."
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"value": "none",
|
|
151
|
+
"label": "no long-running operations",
|
|
152
|
+
"description": "Every operation finishes within the request and answers with its result; nothing answers 202. Pick it when no operation comes near the limit, and record it so that the first slow one becomes a decision, not a surprise."
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"key": "MAX_LEVELS",
|
|
158
|
+
"label": "How many collections deep may a path go, the top-level collection included?",
|
|
159
|
+
"defaultValue": "3",
|
|
160
|
+
"type": "number"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"key": "SYNC_SECONDS",
|
|
164
|
+
"label": "Above how many seconds must work run as a long-running operation? (a bucket boundary of the request-duration histogram)",
|
|
165
|
+
"defaultValue": "10",
|
|
166
|
+
"type": "number"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"key": "OPERATION_DAYS",
|
|
170
|
+
"label": "For how many days can a finished operation still be read? (an operation resource to poll only)",
|
|
171
|
+
"defaultValue": "30",
|
|
172
|
+
"type": "number"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"key": "CALLBACK_HOURS",
|
|
176
|
+
"label": "For how many hours is a failed callback retried? (a signed callback only)",
|
|
177
|
+
"defaultValue": "72",
|
|
178
|
+
"type": "number"
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
},
|
|
182
|
+
"nodes": [
|
|
183
|
+
{
|
|
184
|
+
"id": "need",
|
|
185
|
+
"type": "need",
|
|
186
|
+
"label": "Callers can predict the API",
|
|
187
|
+
"x": 0,
|
|
188
|
+
"y": 0,
|
|
189
|
+
"kind": "brief",
|
|
190
|
+
"source": "Hub concern pack: Resource design",
|
|
191
|
+
"description": "Other parts of the system and outside systems call this element over HTTP and JSON. Each caller learns the API's conventions once and builds on them: a field named in another style, a path that hides a verb, a GET that changes something, a 200 where a 201 or a 404 belongs, or a request that hangs for minutes each costs every caller a special case, a retry that does harm, or a timeout. The snippets assume the OpenAPI document at api/openapi.yaml, linted by Spectral with the ruleset .spectral.yaml at the repository root (each check adds its rules to it), the application exported by src/app, and the HTTP tests under test/api with their fixtures in test/api/fixtures.ts."
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"id": "req-casing",
|
|
195
|
+
"type": "requirement",
|
|
196
|
+
"label": "One casing for fields",
|
|
197
|
+
"x": 260,
|
|
198
|
+
"y": 0,
|
|
199
|
+
"ears_type": "ubiquitous",
|
|
200
|
+
"action": "name every property of a request or response body and every query parameter in {{CASING}}, with acronyms cased as ordinary words, so that 0 names in the published contract break the rule",
|
|
201
|
+
"rationale": "One casing across every operation lets callers map fields mechanically and keeps generated clients uniform; Microsoft and Google write JSON fields in camelCase, Zalando in snake_case (Azure REST API Guidelines, JSON field name casing; Google AIP-140; Zalando rules 118 and 130)."
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"id": "req-paths",
|
|
205
|
+
"type": "requirement",
|
|
206
|
+
"label": "Paths are plural nouns",
|
|
207
|
+
"x": 260,
|
|
208
|
+
"y": 130,
|
|
209
|
+
"ears_type": "ubiquitous",
|
|
210
|
+
"action": "address every resource as a collection named by a plural noun followed by its identifier in braces (/orders/{orderId}), with {{PATHS}}, at most {{MAX_LEVELS}} collections deep, with no trailing slash and no verb as a path segment",
|
|
211
|
+
"rationale": "Predictable paths let a caller guess the next one; deep nesting makes long URLs that break when ownership changes (Zalando rules 129, 134, 141 and 147; Azure REST API Guidelines, URL casing; Google AIP-122)."
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"id": "req-methods",
|
|
215
|
+
"type": "requirement",
|
|
216
|
+
"label": "Methods mean what HTTP says",
|
|
217
|
+
"x": 260,
|
|
218
|
+
"y": 260,
|
|
219
|
+
"ears_type": "ubiquitous",
|
|
220
|
+
"action": "use GET and HEAD only for reads that change nothing and carry no request body, make PUT and DELETE idempotent so that repeating one leaves the resource as the first left it, answer a successful DELETE with 204 and no body, and from then on answer a read of the deleted resource with 404, or 410 where the deletion is recorded",
|
|
221
|
+
"rationale": "Caches, proxies and client retries rely on safe and idempotent methods meaning what RFC 9110 says (RFC 9110 9.2.1, 9.2.2, 15.3.5, 15.5.5 and 15.5.11; Zalando rule 148)."
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"id": "req-create",
|
|
225
|
+
"type": "requirement",
|
|
226
|
+
"label": "Created resources located",
|
|
227
|
+
"x": 260,
|
|
228
|
+
"y": 390,
|
|
229
|
+
"ears_type": "event-driven",
|
|
230
|
+
"trigger": "a POST to a collection creates a resource",
|
|
231
|
+
"action": "answer 201 Created with a Location header holding the new resource's URL and the resource in the body",
|
|
232
|
+
"rationale": "The Location header is how a caller learns the identifier the server chose without parsing the body (RFC 9110 15.3.2 and 10.2.2; Azure REST API Guidelines, POST returns 201 with the URL of the created resource)."
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"id": "req-unsupported",
|
|
236
|
+
"type": "requirement",
|
|
237
|
+
"label": "Unsupported requests refused",
|
|
238
|
+
"x": 260,
|
|
239
|
+
"y": 520,
|
|
240
|
+
"ears_type": "unwanted-behaviour",
|
|
241
|
+
"unwanted_condition": "a request uses a method its path does not support, or sends a body in a media type the operation does not accept",
|
|
242
|
+
"action": "answer 405 with an Allow header that lists the supported methods, or 415, before any part of the operation runs, with the error body the Errors pack decides",
|
|
243
|
+
"rationale": "A precise status tells the caller what to fix; RFC 9110 requires the Allow header with 405 (RFC 9110 15.5.6, 15.5.16 and 10.2.1; Zalando rule 220, most specific status codes)."
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"id": "req-formats",
|
|
247
|
+
"type": "requirement",
|
|
248
|
+
"label": "Timestamps in UTC, identifiers as strings",
|
|
249
|
+
"x": 260,
|
|
250
|
+
"y": 650,
|
|
251
|
+
"ears_type": "ubiquitous",
|
|
252
|
+
"action": "write every timestamp as an RFC 3339 date-time in UTC ending in Z (2026-10-29T14:05:00Z), declared with format date-time in the contract, and every identifier as an opaque string the server generates, declared as type string and never as a number",
|
|
253
|
+
"rationale": "One timestamp format parses the same in every language, and UTC removes offsets from comparisons; numeric identifiers overflow in JavaScript and invite callers to guess or sort them (RFC 3339 section 5.6; Azure REST API Guidelines, RFC 3339 for date and time; Zalando rules 169 and 174)."
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"id": "req-sync",
|
|
257
|
+
"type": "requirement",
|
|
258
|
+
"label": "Requests answered in time",
|
|
259
|
+
"x": 260,
|
|
260
|
+
"y": 780,
|
|
261
|
+
"ears_type": "ubiquitous",
|
|
262
|
+
"action": "answer at least 99% of the requests to each route within {{SYNC_SECONDS}} seconds, measured over any 5 minutes, and make any work that can take longer either faster or, where the decision on long-running work allows it, a long-running operation",
|
|
263
|
+
"rationale": "A request held longer than the gateway or the client waits fails without a result while the work may still go on; long work answers at once instead (RFC 9110 15.3.3; Google AIP-151; Azure REST API Guidelines, long-running operations)."
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
"id": "req-actions-custom",
|
|
267
|
+
"type": "requirement",
|
|
268
|
+
"label": "Actions as custom methods",
|
|
269
|
+
"x": 260,
|
|
270
|
+
"y": 910,
|
|
271
|
+
"ears_type": "ubiquitous",
|
|
272
|
+
"action": "expose each operation that is not create, read, update, delete or list as a custom method, a path ending in a colon and a camelCase verb (POST /orders/{orderId}:cancel, POST /orders:import), called with POST, or with GET when it only reads, and never with PUT, PATCH or DELETE",
|
|
273
|
+
"rationale": "A custom method keeps the verb out of the resource hierarchy and its HTTP method honest about side effects (Google AIP-136; Azure REST API Guidelines, action operations).",
|
|
274
|
+
"hubWhen": {
|
|
275
|
+
"ACTIONS": [
|
|
276
|
+
"custom"
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
"id": "req-actions-resource",
|
|
282
|
+
"type": "requirement",
|
|
283
|
+
"label": "Actions as resources",
|
|
284
|
+
"x": 260,
|
|
285
|
+
"y": 1040,
|
|
286
|
+
"ears_type": "ubiquitous",
|
|
287
|
+
"action": "model each operation that is not create, read, update, delete or list as a noun resource that records it (POST /orders/{orderId}/cancellations creates a cancellation and answers 201 with its Location), so that 0 paths carry a verb or a colon",
|
|
288
|
+
"rationale": "The API describes resources and the only place for actions is the HTTP method; a letter box for each action keeps URLs verb-free and leaves a record (Zalando rules 138 and 141).",
|
|
289
|
+
"hubWhen": {
|
|
290
|
+
"ACTIONS": [
|
|
291
|
+
"resource"
|
|
292
|
+
]
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
"id": "req-actions-patch",
|
|
297
|
+
"type": "requirement",
|
|
298
|
+
"label": "Actions as status changes",
|
|
299
|
+
"x": 260,
|
|
300
|
+
"y": 1170,
|
|
301
|
+
"ears_type": "unwanted-behaviour",
|
|
302
|
+
"unwanted_condition": "a PATCH asks for a status its resource cannot move to from the current one",
|
|
303
|
+
"action": "answer 409 Conflict and leave the resource unchanged; change state otherwise only by a PATCH of the status field (JSON Merge Patch), with no action paths",
|
|
304
|
+
"rationale": "A forbidden transition conflicts with the resource's current state, which is what 409 says; Merge Patch keeps the write a plain update (RFC 9110 15.5.10; RFC 7396; Zalando rule 148).",
|
|
305
|
+
"hubWhen": {
|
|
306
|
+
"ACTIONS": [
|
|
307
|
+
"patch"
|
|
308
|
+
]
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"id": "req-lro-operation",
|
|
313
|
+
"type": "requirement",
|
|
314
|
+
"label": "Long work polled as an operation",
|
|
315
|
+
"x": 260,
|
|
316
|
+
"y": 1300,
|
|
317
|
+
"ears_type": "event-driven",
|
|
318
|
+
"trigger": "an operation is started that can take longer than {{SYNC_SECONDS}} seconds",
|
|
319
|
+
"action": "answer 202 Accepted at once with an Operation-Location header naming /operations/{operationId}, whose GET returns the status (NotStarted, Running, Succeeded, Failed or Canceled) with a Retry-After header until the work ends, the error when it failed, and stays readable for {{OPERATION_DAYS}} days after it ended",
|
|
320
|
+
"rationale": "The caller gets an answer before any timeout and a resource it can poll at the pace the server sets (Azure REST API Guidelines, long-running operations and status monitor; Google AIP-151, including its rule of thumb of 30 days before an operation expires; Zalando rule 253; RFC 9110 15.3.3).",
|
|
321
|
+
"hubWhen": {
|
|
322
|
+
"LRO": [
|
|
323
|
+
"operation"
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
"id": "req-lro-callback",
|
|
329
|
+
"type": "requirement",
|
|
330
|
+
"label": "Long work reported by callback",
|
|
331
|
+
"x": 260,
|
|
332
|
+
"y": 1430,
|
|
333
|
+
"ears_type": "event-driven",
|
|
334
|
+
"trigger": "an operation that can take longer than {{SYNC_SECONDS}} seconds is started and later ends",
|
|
335
|
+
"action": "answer the start with 202 Accepted and the operation's id, then POST the outcome to the https URL registered for the calling system, signed as Standard Webhooks specifies (webhook-id, webhook-timestamp and an HMAC-SHA256 webhook-signature), and retry with the same webhook-id for {{CALLBACK_HOURS}} hours until the receiver answers 2xx",
|
|
336
|
+
"rationale": "The receiver can prove the message came from us and was not replayed, and drop a retried one by its id; a schedule over days survives the receiver's outages (Standard Webhooks specification: signatures, retries, idempotency; RFC 9110 15.3.3).",
|
|
337
|
+
"hubWhen": {
|
|
338
|
+
"LRO": [
|
|
339
|
+
"callback"
|
|
340
|
+
]
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
"id": "sc-casing",
|
|
345
|
+
"type": "scenario",
|
|
346
|
+
"label": "Other casing refused",
|
|
347
|
+
"x": 520,
|
|
348
|
+
"y": 0,
|
|
349
|
+
"given": "the OpenAPI document of the API",
|
|
350
|
+
"when": "a pull request adds a property and a query parameter named in another casing",
|
|
351
|
+
"then": "the lint step fails and names both"
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
"id": "sc-paths",
|
|
355
|
+
"type": "scenario",
|
|
356
|
+
"label": "Bad paths refused",
|
|
357
|
+
"x": 520,
|
|
358
|
+
"y": 130,
|
|
359
|
+
"given": "the OpenAPI document of the API",
|
|
360
|
+
"when": "a pull request adds a singular collection, a path ending in a slash, a path with /cancel as a segment, and one nested a collection deeper than {{MAX_LEVELS}}",
|
|
361
|
+
"then": "the lint step fails for each of the four"
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
"id": "sc-methods",
|
|
365
|
+
"type": "scenario",
|
|
366
|
+
"label": "Methods behave",
|
|
367
|
+
"x": 520,
|
|
368
|
+
"y": 260,
|
|
369
|
+
"given": "an existing order",
|
|
370
|
+
"when": "it is read twice, replaced twice with the same body, deleted, and read again",
|
|
371
|
+
"then": "both reads return the same body, both replacements leave the same state, the delete answers 204 without a body, and the last read answers 404 or 410"
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
"id": "sc-create",
|
|
375
|
+
"type": "scenario",
|
|
376
|
+
"label": "Create answers 201",
|
|
377
|
+
"x": 520,
|
|
378
|
+
"y": 390,
|
|
379
|
+
"given": "a valid new order",
|
|
380
|
+
"when": "it is posted to /orders",
|
|
381
|
+
"then": "the answer is 201 with a Location header, and a GET of that URL returns the order"
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
"id": "sc-unsupported",
|
|
385
|
+
"type": "scenario",
|
|
386
|
+
"label": "Wrong method and media type",
|
|
387
|
+
"x": 520,
|
|
388
|
+
"y": 520,
|
|
389
|
+
"given": "the /orders collection, which supports GET and POST",
|
|
390
|
+
"when": "it is sent a PATCH, and a POST with Content-Type text/plain",
|
|
391
|
+
"then": "the PATCH answers 405 with Allow naming GET and POST, and the POST answers 415"
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
"id": "sc-formats",
|
|
395
|
+
"type": "scenario",
|
|
396
|
+
"label": "Formats hold",
|
|
397
|
+
"x": 520,
|
|
398
|
+
"y": 650,
|
|
399
|
+
"given": "an order read from the API and the contract that describes it",
|
|
400
|
+
"when": "its timestamps and identifiers are checked",
|
|
401
|
+
"then": "every timestamp ends in Z and is declared date-time, and every identifier is a string in the answer and in the contract"
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
"id": "sc-sync",
|
|
405
|
+
"type": "scenario",
|
|
406
|
+
"label": "Slow route flagged",
|
|
407
|
+
"x": 520,
|
|
408
|
+
"y": 780,
|
|
409
|
+
"given": "a route whose requests take longer than {{SYNC_SECONDS}} seconds for more than 1% of them",
|
|
410
|
+
"when": "15 minutes pass",
|
|
411
|
+
"then": "an alert names the route"
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
"id": "sc-actions-custom",
|
|
415
|
+
"type": "scenario",
|
|
416
|
+
"label": "Custom method shape",
|
|
417
|
+
"x": 520,
|
|
418
|
+
"y": 910,
|
|
419
|
+
"given": "the OpenAPI document of the API",
|
|
420
|
+
"when": "a pull request adds PUT /orders/{orderId}:cancel and POST /orders/{orderId}/cancel",
|
|
421
|
+
"then": "the lint step fails for both; POST /orders/{orderId}:cancel passes",
|
|
422
|
+
"hubWhen": {
|
|
423
|
+
"ACTIONS": [
|
|
424
|
+
"custom"
|
|
425
|
+
]
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
"id": "sc-actions-resource",
|
|
430
|
+
"type": "scenario",
|
|
431
|
+
"label": "Action recorded as resource",
|
|
432
|
+
"x": 520,
|
|
433
|
+
"y": 1040,
|
|
434
|
+
"given": "the OpenAPI document of the API",
|
|
435
|
+
"when": "a pull request adds POST /orders/{orderId}:cancel, and another adds POST /orders/{orderId}/cancellations answering 201 with Location",
|
|
436
|
+
"then": "the lint step fails for the first and passes the second",
|
|
437
|
+
"hubWhen": {
|
|
438
|
+
"ACTIONS": [
|
|
439
|
+
"resource"
|
|
440
|
+
]
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
"id": "sc-actions-patch",
|
|
445
|
+
"type": "scenario",
|
|
446
|
+
"label": "Forbidden transition refused",
|
|
447
|
+
"x": 520,
|
|
448
|
+
"y": 1170,
|
|
449
|
+
"given": "a cancelled order",
|
|
450
|
+
"when": "a PATCH sets its status to shipped",
|
|
451
|
+
"then": "the answer is 409 and the order is still cancelled",
|
|
452
|
+
"hubWhen": {
|
|
453
|
+
"ACTIONS": [
|
|
454
|
+
"patch"
|
|
455
|
+
]
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
"id": "sc-lro-operation",
|
|
460
|
+
"type": "scenario",
|
|
461
|
+
"label": "Operation polled to the end",
|
|
462
|
+
"x": 520,
|
|
463
|
+
"y": 1300,
|
|
464
|
+
"given": "a report that takes a minute to build",
|
|
465
|
+
"when": "it is requested and the Operation-Location is polled as Retry-After says",
|
|
466
|
+
"then": "the request answers 202 at once, the polls show Running and then Succeeded, and the operation is still readable {{OPERATION_DAYS}} days later",
|
|
467
|
+
"hubWhen": {
|
|
468
|
+
"LRO": [
|
|
469
|
+
"operation"
|
|
470
|
+
]
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
"id": "sc-lro-callback",
|
|
475
|
+
"type": "scenario",
|
|
476
|
+
"label": "Callback retried and signed",
|
|
477
|
+
"x": 520,
|
|
478
|
+
"y": 1430,
|
|
479
|
+
"given": "a registered receiver that fails its first delivery",
|
|
480
|
+
"when": "a long operation is started and ends",
|
|
481
|
+
"then": "the start answers 202, and the receiver gets the outcome twice with the same webhook-id and a valid signature",
|
|
482
|
+
"hubWhen": {
|
|
483
|
+
"LRO": [
|
|
484
|
+
"callback"
|
|
485
|
+
]
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
"id": "adr-camel",
|
|
490
|
+
"type": "adr",
|
|
491
|
+
"label": "Resource conventions with camelCase fields",
|
|
492
|
+
"x": 780,
|
|
493
|
+
"y": 0,
|
|
494
|
+
"concern": "api-resource-design",
|
|
495
|
+
"status": "accepted",
|
|
496
|
+
"date": "",
|
|
497
|
+
"context": "Other parts of the system and outside systems call this element over HTTP, and each caller learns its conventions once and then expects them everywhere. The forces: field and path names that change style from one operation to the next make every client mapping a special case; methods that do not mean what HTTP says break caches, proxies and retries (a GET that changes state is repeated by anything on the way, a POST retried after a timeout creates twice); status codes chosen by taste make every caller write its own handling; operations that are not create, read, update or delete need a home that does not turn the API into remote procedure calls; work that takes longer than a gateway waits needs a way to finish without holding the connection; and conventions hold only while a linter enforces them on every pull request. Which published guide the API follows as a whole is decided in the API style guide pack; error bodies, collections, and idempotency keys with preconditions in the Errors, Collections, and Idempotency and concurrency packs; versions and deprecation in the API evolution pack; 429 and request limits in the Rate limiting pack.",
|
|
498
|
+
"decision": "The API's resources follow one set of conventions, enforced on api/openapi.yaml by Spectral in every pull request and tested on the running API. Fields and query parameters are camelCase, acronyms as words (customerId, httpUrl), as the Azure guidelines and Google's JSON mapping write them. Paths: {{PATHS}}, collections as plural nouns, identifiers in braces, at most {{MAX_LEVELS}} collections deep. Methods as RFC 9110 defines them: GET and HEAD safe, PUT and DELETE idempotent, a POST that creates answers 201 with Location, DELETE answers 204, an unknown resource 404, an unsupported method 405 with Allow, a media type not accepted 415. Timestamps are RFC 3339 in UTC (format date-time), identifiers opaque strings. Operations that are not create, read, update, delete or list: {{ACTIONS}}. Long-running work: {{LRO}}.",
|
|
499
|
+
"consequences": "• JavaScript, Java (Jackson) and .NET (System.Text.Json with web defaults) produce camelCase by default, so most clients need no naming policy.\n• Python and Ruby services map names at the edge (pydantic's to_camel alias generator, for one), and database columns in snake_case never leak into the contract.\n• Spectral fails the pull request on any break of the rules; an existing API in another casing needs a new version or a recorded exception, decided in the API evolution pack.\n• The rules check the contract; the HTTP tests check that the running API matches it.",
|
|
500
|
+
"alternatives": "1. snake_case fields, as Zalando requires: natural for Python and SQL, but every JavaScript, Java and .NET client configures a naming policy.\n2. Each service its own casing: no decision to make, and callers of two services learn two styles.\n3. PascalCase, as older OData services use: unusual in JSON and a third style for callers.",
|
|
501
|
+
"hubWhen": {
|
|
502
|
+
"CASING": [
|
|
503
|
+
"camel"
|
|
504
|
+
]
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
"id": "adr-snake",
|
|
509
|
+
"type": "adr",
|
|
510
|
+
"label": "Resource conventions with snake_case fields",
|
|
511
|
+
"x": 780,
|
|
512
|
+
"y": 130,
|
|
513
|
+
"concern": "api-resource-design",
|
|
514
|
+
"status": "accepted",
|
|
515
|
+
"date": "",
|
|
516
|
+
"context": "Other parts of the system and outside systems call this element over HTTP, and each caller learns its conventions once and then expects them everywhere. The forces: field and path names that change style from one operation to the next make every client mapping a special case; methods that do not mean what HTTP says break caches, proxies and retries (a GET that changes state is repeated by anything on the way, a POST retried after a timeout creates twice); status codes chosen by taste make every caller write its own handling; operations that are not create, read, update or delete need a home that does not turn the API into remote procedure calls; work that takes longer than a gateway waits needs a way to finish without holding the connection; and conventions hold only while a linter enforces them on every pull request. Which published guide the API follows as a whole is decided in the API style guide pack; error bodies, collections, and idempotency keys with preconditions in the Errors, Collections, and Idempotency and concurrency packs; versions and deprecation in the API evolution pack; 429 and request limits in the Rate limiting pack.",
|
|
517
|
+
"decision": "The API's resources follow one set of conventions, enforced on api/openapi.yaml by Spectral in every pull request and tested on the running API. Fields and query parameters are snake_case (customer_id, created_at), as the Zalando guidelines require. Paths: {{PATHS}}, collections as plural nouns, identifiers in braces, at most {{MAX_LEVELS}} collections deep. Methods as RFC 9110 defines them: GET and HEAD safe, PUT and DELETE idempotent, a POST that creates answers 201 with Location, DELETE answers 204, an unknown resource 404, an unsupported method 405 with Allow, a media type not accepted 415. Timestamps are RFC 3339 in UTC (format date-time), identifiers opaque strings. Operations that are not create, read, update, delete or list: {{ACTIONS}}. Long-running work: {{LRO}}.",
|
|
518
|
+
"consequences": "• Python, Ruby and column names carry over without mapping.\n• JavaScript, Java and .NET clients configure a naming policy (Jackson's PropertyNamingStrategies.SNAKE_CASE, JsonNamingPolicy.SnakeCaseLower in .NET 8) or work with snake_case properties.\n• Callers that also use Microsoft or Google APIs meet two casings.\n• Spectral fails the pull request on any break of the rules; an existing API in another casing needs a new version or a recorded exception, decided in the API evolution pack.",
|
|
519
|
+
"alternatives": "1. camelCase fields, as the Azure guidelines and Google's JSON mapping use: no naming policy in JavaScript, Java or .NET, but a mapping in Python and Ruby.\n2. Each service its own casing: no decision to make, and callers of two services learn two styles.",
|
|
520
|
+
"hubWhen": {
|
|
521
|
+
"CASING": [
|
|
522
|
+
"snake"
|
|
523
|
+
]
|
|
524
|
+
}
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
"id": "adr-actions-custom",
|
|
528
|
+
"type": "adr",
|
|
529
|
+
"label": "Actions as custom methods",
|
|
530
|
+
"x": 780,
|
|
531
|
+
"y": 260,
|
|
532
|
+
"concern": "api-resource-design",
|
|
533
|
+
"status": "accepted",
|
|
534
|
+
"date": "",
|
|
535
|
+
"context": "Other parts of the system and outside systems call this element over HTTP, and each caller learns its conventions once and then expects them everywhere. The forces: field and path names that change style from one operation to the next make every client mapping a special case; methods that do not mean what HTTP says break caches, proxies and retries (a GET that changes state is repeated by anything on the way, a POST retried after a timeout creates twice); status codes chosen by taste make every caller write its own handling; operations that are not create, read, update or delete need a home that does not turn the API into remote procedure calls; work that takes longer than a gateway waits needs a way to finish without holding the connection; and conventions hold only while a linter enforces them on every pull request. Which published guide the API follows as a whole is decided in the API style guide pack; error bodies, collections, and idempotency keys with preconditions in the Errors, Collections, and Idempotency and concurrency packs; versions and deprecation in the API evolution pack; 429 and request limits in the Rate limiting pack.",
|
|
536
|
+
"decision": "An operation that is not create, read, update, delete or list is a custom method: the resource's path followed by a colon and a camelCase verb, called with POST (POST /orders/{orderId}:cancel; on a collection, POST /orders:import), or with GET when it only reads. The body carries the method's input and the answer the resource after the change. A custom method is used only where a standard method cannot express the operation (Google AIP-136; Azure guidelines, action operations), identifiers never contain a colon, and no path segment is a verb.",
|
|
537
|
+
"consequences": "• The verb shows in the path, in access logs and in authorization rules per operation.\n• Some routers and gateways read a colon in a path as a parameter marker; check once that yours match /orders/{orderId}:cancel, and escape or rewrite the route if not.\n• Nothing records that the action happened unless the resource or an audit log does.",
|
|
538
|
+
"alternatives": "1. Action resources (POST /orders/{orderId}/cancellations): verb-free and recorded, but a noun for every action.\n2. Status changes by PATCH: no new paths, but side effects hide behind a field write.\n3. A verb as a sub-resource (POST /orders/{orderId}/cancel), as OData actions do: familiar, but it looks like a collection and breaks the verb-free path rule.",
|
|
539
|
+
"hubWhen": {
|
|
540
|
+
"ACTIONS": [
|
|
541
|
+
"custom"
|
|
542
|
+
]
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
"id": "adr-actions-resource",
|
|
547
|
+
"type": "adr",
|
|
548
|
+
"label": "Actions as resources",
|
|
549
|
+
"x": 780,
|
|
550
|
+
"y": 390,
|
|
551
|
+
"concern": "api-resource-design",
|
|
552
|
+
"status": "accepted",
|
|
553
|
+
"date": "",
|
|
554
|
+
"context": "Other parts of the system and outside systems call this element over HTTP, and each caller learns its conventions once and then expects them everywhere. The forces: field and path names that change style from one operation to the next make every client mapping a special case; methods that do not mean what HTTP says break caches, proxies and retries (a GET that changes state is repeated by anything on the way, a POST retried after a timeout creates twice); status codes chosen by taste make every caller write its own handling; operations that are not create, read, update or delete need a home that does not turn the API into remote procedure calls; work that takes longer than a gateway waits needs a way to finish without holding the connection; and conventions hold only while a linter enforces them on every pull request. Which published guide the API follows as a whole is decided in the API style guide pack; error bodies, collections, and idempotency keys with preconditions in the Errors, Collections, and Idempotency and concurrency packs; versions and deprecation in the API evolution pack; 429 and request limits in the Rate limiting pack.",
|
|
555
|
+
"decision": "An operation that is not create, read, update, delete or list is modelled as a resource that records it: POST /orders/{orderId}/cancellations creates a cancellation (201 with Location, the reason and the actor in the body) and GET lists them. Paths carry no verbs and no colons (Zalando rules 138 and 141).",
|
|
556
|
+
"consequences": "• Every action leaves a record that can be read, listed and audited.\n• A noun has to be found for every action, and some are awkward (a recalculation, a resend).\n• Each action resource is one more thing to secure, page and keep.",
|
|
557
|
+
"alternatives": "1. Custom methods (POST /orders/{orderId}:cancel): the verb is plain to see, but the path is no longer verb-free and nothing is recorded.\n2. Status changes by PATCH: fewer paths, but no room for the action's own input.",
|
|
558
|
+
"hubWhen": {
|
|
559
|
+
"ACTIONS": [
|
|
560
|
+
"resource"
|
|
561
|
+
]
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
"id": "adr-actions-patch",
|
|
566
|
+
"type": "adr",
|
|
567
|
+
"label": "Actions as status changes",
|
|
568
|
+
"x": 780,
|
|
569
|
+
"y": 520,
|
|
570
|
+
"concern": "api-resource-design",
|
|
571
|
+
"status": "accepted",
|
|
572
|
+
"date": "",
|
|
573
|
+
"context": "Other parts of the system and outside systems call this element over HTTP, and each caller learns its conventions once and then expects them everywhere. The forces: field and path names that change style from one operation to the next make every client mapping a special case; methods that do not mean what HTTP says break caches, proxies and retries (a GET that changes state is repeated by anything on the way, a POST retried after a timeout creates twice); status codes chosen by taste make every caller write its own handling; operations that are not create, read, update or delete need a home that does not turn the API into remote procedure calls; work that takes longer than a gateway waits needs a way to finish without holding the connection; and conventions hold only while a linter enforces them on every pull request. Which published guide the API follows as a whole is decided in the API style guide pack; error bodies, collections, and idempotency keys with preconditions in the Errors, Collections, and Idempotency and concurrency packs; versions and deprecation in the API evolution pack; 429 and request limits in the Rate limiting pack.",
|
|
574
|
+
"decision": "A change of state is a write of the resource's status field with PATCH and application/merge-patch+json (RFC 7396): PATCH /orders/{orderId} with {\"status\": \"cancelled\"}. The allowed transitions are kept in one table in the code and listed in the status field's description in the contract; a transition the table does not allow answers 409 Conflict and changes nothing. There are no action paths.",
|
|
575
|
+
"consequences": "• No new paths: the API stays create, read, update and delete.\n• Side effects (a refund, an e-mail) hang off a field write, so they must be described on the field.\n• Input an action needs beyond the new status (a reason, an amount) goes into the same PATCH body, or does not fit.\n• Two callers changing the status at once need a precondition, decided in the Idempotency and concurrency pack.",
|
|
576
|
+
"alternatives": "1. Custom methods (POST /orders/{orderId}:cancel): room for the action's input, at the cost of a path per action.\n2. Action resources (POST /orders/{orderId}/cancellations): a record of each action, at the cost of a resource per action.",
|
|
577
|
+
"hubWhen": {
|
|
578
|
+
"ACTIONS": [
|
|
579
|
+
"patch"
|
|
580
|
+
]
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
"id": "adr-lro-operation",
|
|
585
|
+
"type": "adr",
|
|
586
|
+
"label": "Long work as operations to poll",
|
|
587
|
+
"x": 780,
|
|
588
|
+
"y": 650,
|
|
589
|
+
"concern": "api-resource-design",
|
|
590
|
+
"status": "accepted",
|
|
591
|
+
"date": "",
|
|
592
|
+
"context": "Other parts of the system and outside systems call this element over HTTP, and each caller learns its conventions once and then expects them everywhere. The forces: field and path names that change style from one operation to the next make every client mapping a special case; methods that do not mean what HTTP says break caches, proxies and retries (a GET that changes state is repeated by anything on the way, a POST retried after a timeout creates twice); status codes chosen by taste make every caller write its own handling; operations that are not create, read, update or delete need a home that does not turn the API into remote procedure calls; work that takes longer than a gateway waits needs a way to finish without holding the connection; and conventions hold only while a linter enforces them on every pull request. Which published guide the API follows as a whole is decided in the API style guide pack; error bodies, collections, and idempotency keys with preconditions in the Errors, Collections, and Idempotency and concurrency packs; versions and deprecation in the API evolution pack; 429 and request limits in the Rate limiting pack.",
|
|
593
|
+
"decision": "Work that can take longer than {{SYNC_SECONDS}} seconds answers 202 Accepted at once with an absolute Operation-Location header naming /operations/{operationId}. The operation carries id, status (NotStarted, Running, Succeeded, Failed or Canceled), and the result or the error when it ends; its GET sends Retry-After while the work runs, and a finished operation stays readable for {{OPERATION_DAYS}} days. This is the Azure guidelines' status monitor; Google's AIP-151 operation (name, done, response or error) is the same shape under other names.",
|
|
594
|
+
"consequences": "• Any caller can follow it with plain GETs, and nothing has to be hosted on the caller's side.\n• Callers poll; Retry-After keeps the polling at the pace the server chooses.\n• Operations are stored for {{OPERATION_DAYS}} days and need their own clean-up and access control: only the caller that started one may read it.",
|
|
595
|
+
"alternatives": "1. A signed callback when the work ends: no polling, but the caller must run a reachable endpoint.\n2. Holding the request open: simple, and cut off by the first gateway timeout.",
|
|
596
|
+
"hubWhen": {
|
|
597
|
+
"LRO": [
|
|
598
|
+
"operation"
|
|
599
|
+
]
|
|
600
|
+
}
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
"id": "adr-lro-callback",
|
|
604
|
+
"type": "adr",
|
|
605
|
+
"label": "Long work reported by signed callbacks",
|
|
606
|
+
"x": 780,
|
|
607
|
+
"y": 780,
|
|
608
|
+
"concern": "api-resource-design",
|
|
609
|
+
"status": "accepted",
|
|
610
|
+
"date": "",
|
|
611
|
+
"context": "Other parts of the system and outside systems call this element over HTTP, and each caller learns its conventions once and then expects them everywhere. The forces: field and path names that change style from one operation to the next make every client mapping a special case; methods that do not mean what HTTP says break caches, proxies and retries (a GET that changes state is repeated by anything on the way, a POST retried after a timeout creates twice); status codes chosen by taste make every caller write its own handling; operations that are not create, read, update or delete need a home that does not turn the API into remote procedure calls; work that takes longer than a gateway waits needs a way to finish without holding the connection; and conventions hold only while a linter enforces them on every pull request. Which published guide the API follows as a whole is decided in the API style guide pack; error bodies, collections, and idempotency keys with preconditions in the Errors, Collections, and Idempotency and concurrency packs; versions and deprecation in the API evolution pack; 429 and request limits in the Rate limiting pack.",
|
|
612
|
+
"decision": "Work that can take longer than {{SYNC_SECONDS}} seconds answers 202 Accepted with the operation's id. When it ends, its outcome is POSTed to the https URL registered for the calling system (never a URL taken from the request), signed as the Standard Webhooks specification describes (webhook-id, webhook-timestamp and webhook-signature, HMAC-SHA256 with a secret per caller), and retried with exponential backoff for {{CALLBACK_HOURS}} hours until the receiver answers 2xx. The webhook-id stays the same across retries so the receiver can drop duplicates.",
|
|
613
|
+
"consequences": "• Callers learn the outcome without polling.\n• Callers need a reachable https endpoint and must verify signatures and timestamps.\n• A callback still undelivered after {{CALLBACK_HOURS}} hours is lost unless the caller can ask; tell the caller's owner when that happens.\n• Requests to callers' URLs are a server-side request forgery risk; URLs registered ahead per caller, never taken from a request, keep it bounded.",
|
|
614
|
+
"alternatives": "1. An operation resource to poll: nothing to host on the caller's side, at the cost of polling.\n2. Callbacks without signatures: simpler, and anyone who learns the URL can forge an outcome.",
|
|
615
|
+
"hubWhen": {
|
|
616
|
+
"LRO": [
|
|
617
|
+
"callback"
|
|
618
|
+
]
|
|
619
|
+
}
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
"id": "adr-lro-none",
|
|
623
|
+
"type": "adr",
|
|
624
|
+
"label": "No long-running operations",
|
|
625
|
+
"x": 780,
|
|
626
|
+
"y": 910,
|
|
627
|
+
"concern": "api-resource-design",
|
|
628
|
+
"status": "accepted",
|
|
629
|
+
"date": "",
|
|
630
|
+
"context": "Other parts of the system and outside systems call this element over HTTP, and each caller learns its conventions once and then expects them everywhere. The forces: field and path names that change style from one operation to the next make every client mapping a special case; methods that do not mean what HTTP says break caches, proxies and retries (a GET that changes state is repeated by anything on the way, a POST retried after a timeout creates twice); status codes chosen by taste make every caller write its own handling; operations that are not create, read, update or delete need a home that does not turn the API into remote procedure calls; work that takes longer than a gateway waits needs a way to finish without holding the connection; and conventions hold only while a linter enforces them on every pull request. Which published guide the API follows as a whole is decided in the API style guide pack; error bodies, collections, and idempotency keys with preconditions in the Errors, Collections, and Idempotency and concurrency packs; versions and deprecation in the API evolution pack; 429 and request limits in the Rate limiting pack.",
|
|
631
|
+
"decision": "Every operation finishes within {{SYNC_SECONDS}} seconds and answers with its final result; no operation answers 202. Work that would take longer is made smaller or split, or moved out of the API (a large export becomes a scheduled file). The first operation that cannot finish in time supersedes this decision.",
|
|
632
|
+
"consequences": "• Callers handle one kind of answer, and there is no operation store to keep.\n• Every operation must stay fast as data grows; the latency alert shows the first one that does not.\n• Adding long-running work later is a new decision, and its operations a change to the contract.",
|
|
633
|
+
"alternatives": "1. An operation resource to poll: room for slow work, at the cost of an operation store.\n2. A signed callback: room for slow work, at the cost of endpoints on the callers' side.",
|
|
634
|
+
"hubWhen": {
|
|
635
|
+
"LRO": [
|
|
636
|
+
"none"
|
|
637
|
+
]
|
|
638
|
+
}
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
"id": "ff-casing-camel",
|
|
642
|
+
"type": "fitness-fn",
|
|
643
|
+
"label": "Fields camelCase, formats declared",
|
|
644
|
+
"x": 1040,
|
|
645
|
+
"y": 0,
|
|
646
|
+
"characteristic": "maintainability",
|
|
647
|
+
"scope": "atomic",
|
|
648
|
+
"cadence": "triggered",
|
|
649
|
+
"trigger": "pull-request",
|
|
650
|
+
"invocation": "automated",
|
|
651
|
+
"description": "Spectral lints the OpenAPI document in the pull-request build and fails on any error. Identifiers are the properties named id or ending in Id; timestamps those ending in At or Time.\n\nThreshold: 0 properties or query parameters outside camelCase, 0 identifiers not typed string, 0 timestamp properties without format date-time, and 0 date-time examples outside UTC in api/openapi.yaml\n\nTool: Spectral CLI (spectral lint api/openapi.yaml --fail-severity=error)\n\n```yaml\n# .spectral.yaml, with the path and contract rules beside these\nformats: [oas3]\nrules:\n field-names-camel-case:\n severity: error\n given: '$..properties[*]~'\n then: { function: casing, functionOptions: { type: camel } }\n query-parameters-camel-case:\n severity: error\n given: \"$..parameters[?(@.in == 'query')].name\"\n then: { function: casing, functionOptions: { type: camel } }\n ids-are-strings:\n severity: error\n given: '$..properties[?(@property.match(/^id$|Id$/))]'\n then: { field: type, function: enumeration, functionOptions: { values: [string] } }\n timestamps-are-date-time:\n severity: error\n given: '$..properties[?(@property.match(/(At|Time)$/))]'\n then: { function: schema, functionOptions: { schema: { required: [format], properties: { format: { const: date-time } } } } }\n timestamp-examples-in-utc:\n severity: error\n given: \"$..properties[?(@.format == 'date-time')].example\"\n then: { function: pattern, functionOptions: { match: '^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$' } }\n```",
|
|
652
|
+
"hubWhen": {
|
|
653
|
+
"CASING": [
|
|
654
|
+
"camel"
|
|
655
|
+
]
|
|
656
|
+
}
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
"id": "ff-casing-snake",
|
|
660
|
+
"type": "fitness-fn",
|
|
661
|
+
"label": "Fields snake_case, formats declared",
|
|
662
|
+
"x": 1040,
|
|
663
|
+
"y": 130,
|
|
664
|
+
"characteristic": "maintainability",
|
|
665
|
+
"scope": "atomic",
|
|
666
|
+
"cadence": "triggered",
|
|
667
|
+
"trigger": "pull-request",
|
|
668
|
+
"invocation": "automated",
|
|
669
|
+
"description": "Spectral lints the OpenAPI document in the pull-request build and fails on any error. Identifiers are the properties named id or ending in _id; timestamps those ending in _at or _time.\n\nThreshold: 0 properties or query parameters outside snake_case, 0 identifiers not typed string, 0 timestamp properties without format date-time, and 0 date-time examples outside UTC in api/openapi.yaml\n\nTool: Spectral CLI (spectral lint api/openapi.yaml --fail-severity=error)\n\n```yaml\n# .spectral.yaml, with the path and contract rules beside these\nformats: [oas3]\nrules:\n field-names-snake-case:\n severity: error\n given: '$..properties[*]~'\n then: { function: casing, functionOptions: { type: snake } }\n query-parameters-snake-case:\n severity: error\n given: \"$..parameters[?(@.in == 'query')].name\"\n then: { function: casing, functionOptions: { type: snake } }\n ids-are-strings:\n severity: error\n given: '$..properties[?(@property.match(/^id$|_id$/))]'\n then: { field: type, function: enumeration, functionOptions: { values: [string] } }\n timestamps-are-date-time:\n severity: error\n given: '$..properties[?(@property.match(/(_at|_time)$/))]'\n then: { function: schema, functionOptions: { schema: { required: [format], properties: { format: { const: date-time } } } } }\n timestamp-examples-in-utc:\n severity: error\n given: \"$..properties[?(@.format == 'date-time')].example\"\n then: { function: pattern, functionOptions: { match: '^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$' } }\n```",
|
|
670
|
+
"hubWhen": {
|
|
671
|
+
"CASING": [
|
|
672
|
+
"snake"
|
|
673
|
+
]
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
"id": "ff-paths-kebab",
|
|
678
|
+
"type": "fitness-fn",
|
|
679
|
+
"label": "Paths kebab-case, plural, shallow",
|
|
680
|
+
"x": 1040,
|
|
681
|
+
"y": 260,
|
|
682
|
+
"characteristic": "maintainability",
|
|
683
|
+
"scope": "atomic",
|
|
684
|
+
"cadence": "triggered",
|
|
685
|
+
"trigger": "pull-request",
|
|
686
|
+
"invocation": "automated",
|
|
687
|
+
"description": "Spectral checks every path of the OpenAPI document: segments are kebab-case words or {parameters}, collections end in s or are on the list of irregular plurals and singletons in the rule, and no path is deeper than the limit. A custom method's :verb at the end is let through here; the actions check decides whether it is allowed.\n\nThreshold: 0 paths in api/openapi.yaml with a segment outside kebab-case, a trailing slash, a collection that is not plural, or more than {{MAX_LEVELS}} collections\n\nTool: Spectral CLI (spectral lint api/openapi.yaml --fail-severity=error)\n\n```yaml\n# .spectral.yaml, with the casing and contract rules beside these\nformats: [oas3]\nrules:\n path-segments-kebab-case:\n severity: error\n given: '$.paths[*]~'\n then: { function: pattern, functionOptions: { match: '^(/([a-z][a-z0-9]*(-[a-z0-9]+)*|\\{[a-z][A-Za-z0-9_]*\\}))+(:[a-z][A-Za-z]*)?$' } }\n path-collections-plural:\n message: '{{property}}: a collection is not a plural noun (add irregular plurals and singletons to the list)'\n severity: error\n given: '$.paths[*]~'\n then: { function: pattern, functionOptions: { match: '^(/([a-z0-9-]*s|people|children|data|media|me|\\{[^}]+\\}))+(:[A-Za-z]+)?$' } }\n path-nesting-depth:\n message: '{{property}} is more than {{MAX_LEVELS}} collections deep'\n severity: error\n given: '$.paths[*]~'\n then: { function: pattern, functionOptions: { notMatch: '^(/[^/{]+(/\\{[^}]+\\})?){{{MAX_LEVELS}}}/[^/{]' } }\n```",
|
|
688
|
+
"hubWhen": {
|
|
689
|
+
"PATHS": [
|
|
690
|
+
"kebab"
|
|
691
|
+
]
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
"id": "ff-paths-camel",
|
|
696
|
+
"type": "fitness-fn",
|
|
697
|
+
"label": "Paths camelCase, plural, shallow",
|
|
698
|
+
"x": 1040,
|
|
699
|
+
"y": 390,
|
|
700
|
+
"characteristic": "maintainability",
|
|
701
|
+
"scope": "atomic",
|
|
702
|
+
"cadence": "triggered",
|
|
703
|
+
"trigger": "pull-request",
|
|
704
|
+
"invocation": "automated",
|
|
705
|
+
"description": "Spectral checks every path of the OpenAPI document: segments are camelCase words or {parameters}, collections end in s or are on the list of irregular plurals and singletons in the rule, and no path is deeper than the limit. A custom method's :verb at the end is let through here; the actions check decides whether it is allowed.\n\nThreshold: 0 paths in api/openapi.yaml with a segment outside camelCase, a trailing slash, a collection that is not plural, or more than {{MAX_LEVELS}} collections\n\nTool: Spectral CLI (spectral lint api/openapi.yaml --fail-severity=error)\n\n```yaml\n# .spectral.yaml, with the casing and contract rules beside these\nformats: [oas3]\nrules:\n path-segments-camel-case:\n severity: error\n given: '$.paths[*]~'\n then: { function: pattern, functionOptions: { match: '^(/([a-z][a-zA-Z0-9]*|\\{[a-z][A-Za-z0-9_]*\\}))+(:[a-z][A-Za-z]*)?$' } }\n path-collections-plural:\n message: '{{property}}: a collection is not a plural noun (add irregular plurals and singletons to the list)'\n severity: error\n given: '$.paths[*]~'\n then: { function: pattern, functionOptions: { match: '^(/([a-zA-Z0-9]*s|people|children|data|media|me|\\{[^}]+\\}))+(:[A-Za-z]+)?$' } }\n path-nesting-depth:\n message: '{{property}} is more than {{MAX_LEVELS}} collections deep'\n severity: error\n given: '$.paths[*]~'\n then: { function: pattern, functionOptions: { notMatch: '^(/[^/{]+(/\\{[^}]+\\})?){{{MAX_LEVELS}}}/[^/{]' } }\n```",
|
|
706
|
+
"hubWhen": {
|
|
707
|
+
"PATHS": [
|
|
708
|
+
"camel"
|
|
709
|
+
]
|
|
710
|
+
}
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
"id": "ff-contract",
|
|
714
|
+
"type": "fitness-fn",
|
|
715
|
+
"label": "Contract follows HTTP semantics",
|
|
716
|
+
"x": 1040,
|
|
717
|
+
"y": 520,
|
|
718
|
+
"characteristic": "compatibility",
|
|
719
|
+
"scope": "atomic",
|
|
720
|
+
"cadence": "triggered",
|
|
721
|
+
"trigger": "pull-request",
|
|
722
|
+
"invocation": "automated",
|
|
723
|
+
"description": "Spectral checks the methods and status codes the OpenAPI document declares against RFC 9110. The verb list is a start; add the verbs of your domain.\n\nThreshold: 0 GET, HEAD or DELETE operations with a request body, 0 responses 201 without a Location header, 0 DELETE operations without a 204 or 202 response, 0 reads of one resource without a 404 response, and 0 paths with a verb as a segment in api/openapi.yaml\n\nTool: Spectral CLI (spectral lint api/openapi.yaml --fail-severity=error)\n\n```yaml\n# .spectral.yaml, with the casing and path rules beside these\nformats: [oas3]\nrules:\n no-body-on-get-head-delete:\n severity: error\n given: '$.paths[*][get,head,delete]'\n then: { field: requestBody, function: falsy }\n created-names-location:\n severity: error\n given: \"$.paths[*][post,put].responses['201']\"\n then: { field: headers.Location, function: truthy }\n delete-answers-204:\n severity: error\n given: '$.paths[*].delete.responses'\n then: { function: or, functionOptions: { properties: ['204', '202'] } }\n read-declares-404:\n severity: error\n given: '$.paths[?(@property.match(/\\}$/))].get.responses'\n then: { field: '404', function: truthy }\n no-verb-segments:\n severity: error\n given: '$.paths[*]~'\n then: { function: pattern, functionOptions: { notMatch: '/(cancel|approve|reject|submit|send|activate|deactivate|archive|restore|publish|retry|start|stop|run|execute)(/|$)' } }\n```"
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
"id": "ff-http",
|
|
727
|
+
"type": "fitness-fn",
|
|
728
|
+
"label": "Running API keeps HTTP semantics",
|
|
729
|
+
"x": 1040,
|
|
730
|
+
"y": 650,
|
|
731
|
+
"characteristic": "compatibility",
|
|
732
|
+
"scope": "atomic",
|
|
733
|
+
"cadence": "triggered",
|
|
734
|
+
"trigger": "pull-request",
|
|
735
|
+
"invocation": "automated",
|
|
736
|
+
"description": "An HTTP test (test/api/semantics.test.ts) runs one resource through its life against the application and checks the status codes, headers and formats RFC 9110 and RFC 3339 prescribe. Timestamps are left out of the comparison of the two PUTs, since an update time may move.\n\nThreshold: POST /orders answers 201 with the order and a Location whose GET returns the same order; two GETs and two PUTs of it return the same state; its timestamps end in Z and its id is a string; DELETE answers 204 without a body and the next GET 404 or 410; PATCH /orders answers 405 with Allow naming GET and POST; a text/plain POST answers 415\n\nTool: Vitest with supertest (or the test runner and HTTP client of your stack: JUnit with MockMvc, xUnit with WebApplicationFactory)\n\n```ts\nimport request from 'supertest'\nimport { expect, it } from 'vitest'\nimport { app } from '../../src/app'\nimport { newOrder } from './fixtures' // a valid body for POST /orders\n\nconst TIME = /(At|_at|Time|_time)$/\nconst untimed = (body: object) => Object.fromEntries(Object.entries(body).filter(([name]) => !TIME.test(name)))\nit('creates, reads, replaces and deletes as RFC 9110 says', async () => {\n const { headers: { location: url }, body: posted } = await request(app).post('/orders').send(newOrder()).expect(201)\n const read = (await request(app).get(url).expect(200)).body\n expect(read).toEqual(posted)\n expect(typeof read.id).toBe('string')\n for (const [name, value] of Object.entries(read)) if (TIME.test(name)) expect(value, name).toMatch(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$/)\n expect((await request(app).get(url)).body).toEqual(read)\n const once = (await request(app).put(url).send(read).expect(200)).body\n expect(untimed((await request(app).put(url).send(read).expect(200)).body)).toEqual(untimed(once))\n expect((await request(app).delete(url).expect(204)).text).toBe('')\n expect([404, 410]).toContain((await request(app).get(url)).status)\n})\n\nit('refuses an unsupported method with 405 and Allow, a media type it does not accept with 415', async () => {\n const wrong = await request(app).patch('/orders').send({}).expect(405)\n expect(wrong.headers.allow.split(/,\\s*/)).toEqual(expect.arrayContaining(['GET', 'POST']))\n await request(app).post('/orders').set('Content-Type', 'text/plain').send('id=1').expect(415)\n})\n```"
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
"id": "ff-custom-methods",
|
|
740
|
+
"type": "fitness-fn",
|
|
741
|
+
"label": "Custom methods well-formed",
|
|
742
|
+
"x": 1040,
|
|
743
|
+
"y": 780,
|
|
744
|
+
"characteristic": "maintainability",
|
|
745
|
+
"scope": "atomic",
|
|
746
|
+
"cadence": "triggered",
|
|
747
|
+
"trigger": "pull-request",
|
|
748
|
+
"invocation": "automated",
|
|
749
|
+
"description": "Spectral checks that a path ending in :verb is only called with POST or GET and that the verb is camelCase; the contract check already refuses a verb as a path segment.\n\nThreshold: 0 paths in api/openapi.yaml with a colon that offer PUT, PATCH or DELETE, and 0 custom-method verbs outside camelCase\n\nTool: Spectral CLI (spectral lint api/openapi.yaml --fail-severity=error)\n\n```yaml\n# .spectral.yaml, with the casing, path and contract rules beside these\nformats: [oas3]\nrules:\n custom-method-post-or-get:\n severity: error\n given: '$.paths[?(@property.match(/:/))]'\n then:\n - { field: put, function: falsy }\n - { field: patch, function: falsy }\n - { field: delete, function: falsy }\n custom-method-verb-camel-case:\n severity: error\n given: '$.paths[*]~'\n then: { function: pattern, functionOptions: { match: '^[^:]*(:[a-z][A-Za-z]*)?$' } }\n```",
|
|
750
|
+
"hubWhen": {
|
|
751
|
+
"ACTIONS": [
|
|
752
|
+
"custom"
|
|
753
|
+
]
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
"id": "ff-action-paths",
|
|
758
|
+
"type": "fitness-fn",
|
|
759
|
+
"label": "No action paths",
|
|
760
|
+
"x": 1040,
|
|
761
|
+
"y": 910,
|
|
762
|
+
"characteristic": "maintainability",
|
|
763
|
+
"scope": "atomic",
|
|
764
|
+
"cadence": "triggered",
|
|
765
|
+
"trigger": "pull-request",
|
|
766
|
+
"invocation": "automated",
|
|
767
|
+
"description": "Spectral refuses custom methods, so an action is either a resource created by POST on its collection or a PATCH of the status field; the contract check already refuses a verb as a path segment.\n\nThreshold: 0 paths in api/openapi.yaml with a colon, and 0 POST operations on a collection without a 201 or 202 response\n\nTool: Spectral CLI (spectral lint api/openapi.yaml --fail-severity=error)\n\n```yaml\n# .spectral.yaml, with the casing, path and contract rules beside these\nformats: [oas3]\nrules:\n no-custom-methods:\n severity: error\n given: '$.paths[*]~'\n then: { function: pattern, functionOptions: { notMatch: ':' } }\n post-on-collection-creates:\n severity: error\n given: '$.paths[?(!@property.match(/\\}$/))].post.responses'\n then: { function: or, functionOptions: { properties: ['201', '202'] } }\n```",
|
|
768
|
+
"hubWhen": {
|
|
769
|
+
"ACTIONS": [
|
|
770
|
+
"resource",
|
|
771
|
+
"patch"
|
|
772
|
+
]
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
"id": "ff-transitions",
|
|
777
|
+
"type": "fitness-fn",
|
|
778
|
+
"label": "Forbidden transitions refused",
|
|
779
|
+
"x": 1040,
|
|
780
|
+
"y": 1040,
|
|
781
|
+
"characteristic": "functional-suitability",
|
|
782
|
+
"scope": "atomic",
|
|
783
|
+
"cadence": "triggered",
|
|
784
|
+
"trigger": "pull-request",
|
|
785
|
+
"invocation": "automated",
|
|
786
|
+
"description": "An HTTP test (test/api/transitions.test.ts) reads the transition table from the code, so a new status or transition is tested without editing the test, and tries every pair of statuses with a Merge Patch of the status field.\n\nThreshold: Every transition the lifecycle table allows answers 200; every other one answers 409 and leaves the status as it was\n\nTool: Vitest with supertest (or the test runner and HTTP client of your stack)\n\n```ts\nimport request from 'supertest'\nimport { expect, it } from 'vitest'\nimport { app } from '../../src/app'\nimport { TRANSITIONS } from '../../src/orders/lifecycle' // { placed: ['paid', 'cancelled'], paid: ['shipped', 'cancelled'], ... }\nimport { orderIn } from './fixtures' // creates an order in a status and returns its URL\n\nconst statuses = Object.keys(TRANSITIONS)\nconst pairs = statuses.flatMap((from) => statuses.filter((to) => to !== from).map((to) => ({ from, to, allowed: TRANSITIONS[from].includes(to) })))\nconst patch = (url: string, status: string) =>\n request(app).patch(url).set('Content-Type', 'application/merge-patch+json').send(JSON.stringify({ status }))\n\nit.each(pairs)('$from → $to (allowed: $allowed)', async ({ from, to, allowed }) => {\n const url = await orderIn(from)\n const res = await patch(url, to)\n expect(res.status).toBe(allowed ? 200 : 409)\n expect((await request(app).get(url)).body.status).toBe(allowed ? to : from)\n})\n```",
|
|
787
|
+
"hubWhen": {
|
|
788
|
+
"ACTIONS": [
|
|
789
|
+
"patch"
|
|
790
|
+
]
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
"id": "ff-operation-poll",
|
|
795
|
+
"type": "fitness-fn",
|
|
796
|
+
"label": "Long work polled to the end",
|
|
797
|
+
"x": 1040,
|
|
798
|
+
"y": 1170,
|
|
799
|
+
"characteristic": "compatibility",
|
|
800
|
+
"scope": "atomic",
|
|
801
|
+
"cadence": "triggered",
|
|
802
|
+
"trigger": "pull-request",
|
|
803
|
+
"invocation": "automated",
|
|
804
|
+
"description": "An HTTP test (test/api/operations.test.ts) starts the slowest operation the API has, follows Operation-Location at the pace Retry-After sets, and reads an operation the fixtures stored as ended just inside the retention period.\n\nThreshold: A long request answers 202 with an Operation-Location under /operations; every poll shows one of the five statuses, with Retry-After until the end; the work ends within 60 polls; an operation that ended {{OPERATION_DAYS}} days ago less one hour is still readable\n\nTool: Vitest with supertest (or the test runner and HTTP client of your stack)\n\n```ts\nimport request from 'supertest'\nimport { expect, it } from 'vitest'\nimport { app } from '../../src/app'\nimport { operationEndedHoursAgo, startLongRunning } from './fixtures' // e.g. POST /reports; a stored, finished operation\n\nconst ENDED = ['Succeeded', 'Failed', 'Canceled']\nit('answers 202 and an operation that can be polled to its end', async () => {\n const started = await startLongRunning(request(app)).expect(202)\n const monitor = new URL(started.headers['operation-location']).pathname\n expect(monitor).toMatch(/^\\/operations\\/[^/]+$/)\n for (let poll = 0; poll < 60; poll++) {\n const res = await request(app).get(monitor).expect(200)\n expect([...ENDED, 'NotStarted', 'Running']).toContain(res.body.status)\n if (res.body.status === 'Failed') expect(res.body.error).toBeDefined()\n if (ENDED.includes(res.body.status)) return\n expect(Number(res.headers['retry-after'])).toBeGreaterThan(0)\n await new Promise((resolve) => setTimeout(resolve, Number(res.headers['retry-after']) * 1000))\n }\n throw new Error('the operation did not end within 60 polls')\n})\n\nit('keeps a finished operation readable for {{OPERATION_DAYS}} days', async () => {\n const id = await operationEndedHoursAgo({{OPERATION_DAYS}} * 24 - 1)\n await request(app).get('/operations/' + id).expect(200)\n})\n```",
|
|
805
|
+
"hubWhen": {
|
|
806
|
+
"LRO": [
|
|
807
|
+
"operation"
|
|
808
|
+
]
|
|
809
|
+
}
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
"id": "ff-callback",
|
|
813
|
+
"type": "fitness-fn",
|
|
814
|
+
"label": "Callbacks signed and retried",
|
|
815
|
+
"x": 1040,
|
|
816
|
+
"y": 1300,
|
|
817
|
+
"characteristic": "security",
|
|
818
|
+
"scope": "atomic",
|
|
819
|
+
"cadence": "triggered",
|
|
820
|
+
"trigger": "pull-request",
|
|
821
|
+
"invocation": "automated",
|
|
822
|
+
"description": "An HTTP test (test/api/callbacks.test.ts) registers a local receiver that refuses the first delivery, starts a long operation, and verifies each delivery's signature as the Standard Webhooks specification computes it (HMAC-SHA256 over id.timestamp.body with the base64 secret after whsec_). The test allows a plain-http loopback receiver; production registers https URLs only.\n\nThreshold: A long request answers 202; a delivery the receiver refuses with 500 is retried with the same webhook-id; every delivery carries a valid v1 HMAC-SHA256 signature; the retry schedule spans at least {{CALLBACK_HOURS}} hours\n\nTool: Vitest with supertest and node:http (or the test runner and HTTP client of your stack)\n\n```ts\nimport { createHmac } from 'node:crypto'\nimport { createServer, type IncomingHttpHeaders } from 'node:http'\nimport request from 'supertest'\nimport { expect, it } from 'vitest'\nimport { app } from '../../src/app'\nimport { RETRY_DELAYS_SECONDS } from '../../src/callbacks' // the delivery schedule of the decision\nimport { registerCallback, startLongRunning } from './fixtures' // registers the receiver's URL and secret for the test client\nit('posts the outcome signed, and retries a refused delivery with the same id', async () => {\n const secret = 'whsec_' + Buffer.from('a secret for the test client').toString('base64')\n const got: Array<{ headers: IncomingHttpHeaders; body: string }> = []\n const receiver = createServer((req, res) => {\n let body = ''\n req.on('data', (chunk) => (body += chunk)).on('end', () => { got.push({ headers: req.headers, body }); res.writeHead(got.length === 1 ? 500 : 204).end() })\n }).listen(0)\n await registerCallback('http://127.0.0.1:' + (receiver.address() as { port: number }).port + '/done', secret)\n await startLongRunning(request(app)).expect(202)\n await expect.poll(() => got.length, { timeout: 30_000 }).toBeGreaterThanOrEqual(2)\n for (const { headers, body } of got) {\n const signed = createHmac('sha256', Buffer.from(secret.slice('whsec_'.length), 'base64')).update(headers['webhook-id'] + '.' + headers['webhook-timestamp'] + '.' + body).digest('base64')\n expect(String(headers['webhook-signature']).split(' ')).toContain('v1,' + signed)\n }\n expect(got[1].headers['webhook-id']).toBe(got[0].headers['webhook-id'])\n expect(RETRY_DELAYS_SECONDS.reduce((sum, s) => sum + s, 0)).toBeGreaterThanOrEqual({{CALLBACK_HOURS}} * 3600)\n receiver.close()\n})\n```",
|
|
823
|
+
"hubWhen": {
|
|
824
|
+
"LRO": [
|
|
825
|
+
"callback"
|
|
826
|
+
]
|
|
827
|
+
}
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
"id": "ff-latency",
|
|
831
|
+
"type": "fitness-fn",
|
|
832
|
+
"label": "Slow routes alerted",
|
|
833
|
+
"x": 1040,
|
|
834
|
+
"y": 1430,
|
|
835
|
+
"characteristic": "performance-efficiency",
|
|
836
|
+
"scope": "holistic",
|
|
837
|
+
"cadence": "continual",
|
|
838
|
+
"invocation": "automated",
|
|
839
|
+
"description": "A Prometheus alerting rule over the OpenTelemetry HTTP server duration histogram computes, per route, the share of requests slower than the limit. The limit must be a bucket boundary of the histogram (the OpenTelemetry default boundaries end at 10 seconds); le is matched with and without .0, since Prometheus 3 may write bucket bounds as floats.\n\nThreshold: An alert fires for any route where more than 1% of requests took longer than {{SYNC_SECONDS}} seconds over 5 minutes, sustained for 15 minutes\n\nTool: Prometheus alerting rules (promtool check rules), on the http.server.request.duration metric of OpenTelemetry\n\n```yaml\n# prometheus/rules/api-resource-design.yml\ngroups:\n - name: api-resource-design\n rules:\n - alert: RequestsSlowerThanTheLimit\n expr: |\n 1 - (\n sum by (http_route) (rate(http_server_request_duration_seconds_bucket{job=\"order-api\", le=~\"{{SYNC_SECONDS}}|{{SYNC_SECONDS}}.0\"}[5m]))\n / sum by (http_route) (rate(http_server_request_duration_seconds_count{job=\"order-api\"}[5m]))\n ) > 0.01\n for: 15m\n labels:\n severity: ticket\n annotations:\n summary: 'More than 1% of {{ $labels.http_route }} takes over {{SYNC_SECONDS}} s: make it faster or a long-running operation'\n```"
|
|
840
|
+
}
|
|
841
|
+
],
|
|
842
|
+
"relations": [
|
|
843
|
+
{
|
|
844
|
+
"id": "req-casing--derives--need",
|
|
845
|
+
"sourceId": "req-casing",
|
|
846
|
+
"targetId": "need",
|
|
847
|
+
"relationType": "derives"
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
"id": "req-paths--derives--need",
|
|
851
|
+
"sourceId": "req-paths",
|
|
852
|
+
"targetId": "need",
|
|
853
|
+
"relationType": "derives"
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
"id": "req-methods--derives--need",
|
|
857
|
+
"sourceId": "req-methods",
|
|
858
|
+
"targetId": "need",
|
|
859
|
+
"relationType": "derives"
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
"id": "req-create--derives--need",
|
|
863
|
+
"sourceId": "req-create",
|
|
864
|
+
"targetId": "need",
|
|
865
|
+
"relationType": "derives"
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
"id": "req-unsupported--derives--need",
|
|
869
|
+
"sourceId": "req-unsupported",
|
|
870
|
+
"targetId": "need",
|
|
871
|
+
"relationType": "derives"
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
"id": "req-formats--derives--need",
|
|
875
|
+
"sourceId": "req-formats",
|
|
876
|
+
"targetId": "need",
|
|
877
|
+
"relationType": "derives"
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
"id": "req-sync--derives--need",
|
|
881
|
+
"sourceId": "req-sync",
|
|
882
|
+
"targetId": "need",
|
|
883
|
+
"relationType": "derives"
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
"id": "req-actions-custom--derives--need",
|
|
887
|
+
"sourceId": "req-actions-custom",
|
|
888
|
+
"targetId": "need",
|
|
889
|
+
"relationType": "derives"
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
"id": "req-actions-resource--derives--need",
|
|
893
|
+
"sourceId": "req-actions-resource",
|
|
894
|
+
"targetId": "need",
|
|
895
|
+
"relationType": "derives"
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
"id": "req-actions-patch--derives--need",
|
|
899
|
+
"sourceId": "req-actions-patch",
|
|
900
|
+
"targetId": "need",
|
|
901
|
+
"relationType": "derives"
|
|
902
|
+
},
|
|
903
|
+
{
|
|
904
|
+
"id": "req-lro-operation--derives--need",
|
|
905
|
+
"sourceId": "req-lro-operation",
|
|
906
|
+
"targetId": "need",
|
|
907
|
+
"relationType": "derives"
|
|
908
|
+
},
|
|
909
|
+
{
|
|
910
|
+
"id": "req-lro-callback--derives--need",
|
|
911
|
+
"sourceId": "req-lro-callback",
|
|
912
|
+
"targetId": "need",
|
|
913
|
+
"relationType": "derives"
|
|
914
|
+
},
|
|
915
|
+
{
|
|
916
|
+
"id": "sc-casing--verifies--req-casing",
|
|
917
|
+
"sourceId": "sc-casing",
|
|
918
|
+
"targetId": "req-casing",
|
|
919
|
+
"relationType": "verifies"
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
"id": "sc-paths--verifies--req-paths",
|
|
923
|
+
"sourceId": "sc-paths",
|
|
924
|
+
"targetId": "req-paths",
|
|
925
|
+
"relationType": "verifies"
|
|
926
|
+
},
|
|
927
|
+
{
|
|
928
|
+
"id": "sc-methods--verifies--req-methods",
|
|
929
|
+
"sourceId": "sc-methods",
|
|
930
|
+
"targetId": "req-methods",
|
|
931
|
+
"relationType": "verifies"
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
"id": "sc-create--verifies--req-create",
|
|
935
|
+
"sourceId": "sc-create",
|
|
936
|
+
"targetId": "req-create",
|
|
937
|
+
"relationType": "verifies"
|
|
938
|
+
},
|
|
939
|
+
{
|
|
940
|
+
"id": "sc-unsupported--verifies--req-unsupported",
|
|
941
|
+
"sourceId": "sc-unsupported",
|
|
942
|
+
"targetId": "req-unsupported",
|
|
943
|
+
"relationType": "verifies"
|
|
944
|
+
},
|
|
945
|
+
{
|
|
946
|
+
"id": "sc-formats--verifies--req-formats",
|
|
947
|
+
"sourceId": "sc-formats",
|
|
948
|
+
"targetId": "req-formats",
|
|
949
|
+
"relationType": "verifies"
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
"id": "sc-sync--verifies--req-sync",
|
|
953
|
+
"sourceId": "sc-sync",
|
|
954
|
+
"targetId": "req-sync",
|
|
955
|
+
"relationType": "verifies"
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
"id": "sc-actions-custom--verifies--req-actions-custom",
|
|
959
|
+
"sourceId": "sc-actions-custom",
|
|
960
|
+
"targetId": "req-actions-custom",
|
|
961
|
+
"relationType": "verifies"
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
"id": "sc-actions-resource--verifies--req-actions-resource",
|
|
965
|
+
"sourceId": "sc-actions-resource",
|
|
966
|
+
"targetId": "req-actions-resource",
|
|
967
|
+
"relationType": "verifies"
|
|
968
|
+
},
|
|
969
|
+
{
|
|
970
|
+
"id": "sc-actions-patch--verifies--req-actions-patch",
|
|
971
|
+
"sourceId": "sc-actions-patch",
|
|
972
|
+
"targetId": "req-actions-patch",
|
|
973
|
+
"relationType": "verifies"
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
"id": "sc-lro-operation--verifies--req-lro-operation",
|
|
977
|
+
"sourceId": "sc-lro-operation",
|
|
978
|
+
"targetId": "req-lro-operation",
|
|
979
|
+
"relationType": "verifies"
|
|
980
|
+
},
|
|
981
|
+
{
|
|
982
|
+
"id": "sc-lro-callback--verifies--req-lro-callback",
|
|
983
|
+
"sourceId": "sc-lro-callback",
|
|
984
|
+
"targetId": "req-lro-callback",
|
|
985
|
+
"relationType": "verifies"
|
|
986
|
+
},
|
|
987
|
+
{
|
|
988
|
+
"id": "ff-casing-camel--implements--adr-camel",
|
|
989
|
+
"sourceId": "ff-casing-camel",
|
|
990
|
+
"targetId": "adr-camel",
|
|
991
|
+
"relationType": "implements"
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
"id": "ff-casing-snake--implements--adr-snake",
|
|
995
|
+
"sourceId": "ff-casing-snake",
|
|
996
|
+
"targetId": "adr-snake",
|
|
997
|
+
"relationType": "implements"
|
|
998
|
+
},
|
|
999
|
+
{
|
|
1000
|
+
"id": "ff-paths-kebab--implements--adr-camel",
|
|
1001
|
+
"sourceId": "ff-paths-kebab",
|
|
1002
|
+
"targetId": "adr-camel",
|
|
1003
|
+
"relationType": "implements"
|
|
1004
|
+
},
|
|
1005
|
+
{
|
|
1006
|
+
"id": "ff-paths-kebab--implements--adr-snake",
|
|
1007
|
+
"sourceId": "ff-paths-kebab",
|
|
1008
|
+
"targetId": "adr-snake",
|
|
1009
|
+
"relationType": "implements"
|
|
1010
|
+
},
|
|
1011
|
+
{
|
|
1012
|
+
"id": "ff-paths-camel--implements--adr-camel",
|
|
1013
|
+
"sourceId": "ff-paths-camel",
|
|
1014
|
+
"targetId": "adr-camel",
|
|
1015
|
+
"relationType": "implements"
|
|
1016
|
+
},
|
|
1017
|
+
{
|
|
1018
|
+
"id": "ff-paths-camel--implements--adr-snake",
|
|
1019
|
+
"sourceId": "ff-paths-camel",
|
|
1020
|
+
"targetId": "adr-snake",
|
|
1021
|
+
"relationType": "implements"
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
"id": "ff-contract--implements--adr-camel",
|
|
1025
|
+
"sourceId": "ff-contract",
|
|
1026
|
+
"targetId": "adr-camel",
|
|
1027
|
+
"relationType": "implements"
|
|
1028
|
+
},
|
|
1029
|
+
{
|
|
1030
|
+
"id": "ff-contract--implements--adr-snake",
|
|
1031
|
+
"sourceId": "ff-contract",
|
|
1032
|
+
"targetId": "adr-snake",
|
|
1033
|
+
"relationType": "implements"
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
"id": "ff-http--implements--adr-camel",
|
|
1037
|
+
"sourceId": "ff-http",
|
|
1038
|
+
"targetId": "adr-camel",
|
|
1039
|
+
"relationType": "implements"
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
"id": "ff-http--implements--adr-snake",
|
|
1043
|
+
"sourceId": "ff-http",
|
|
1044
|
+
"targetId": "adr-snake",
|
|
1045
|
+
"relationType": "implements"
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
"id": "ff-custom-methods--implements--adr-actions-custom",
|
|
1049
|
+
"sourceId": "ff-custom-methods",
|
|
1050
|
+
"targetId": "adr-actions-custom",
|
|
1051
|
+
"relationType": "implements"
|
|
1052
|
+
},
|
|
1053
|
+
{
|
|
1054
|
+
"id": "ff-action-paths--implements--adr-actions-resource",
|
|
1055
|
+
"sourceId": "ff-action-paths",
|
|
1056
|
+
"targetId": "adr-actions-resource",
|
|
1057
|
+
"relationType": "implements"
|
|
1058
|
+
},
|
|
1059
|
+
{
|
|
1060
|
+
"id": "ff-action-paths--implements--adr-actions-patch",
|
|
1061
|
+
"sourceId": "ff-action-paths",
|
|
1062
|
+
"targetId": "adr-actions-patch",
|
|
1063
|
+
"relationType": "implements"
|
|
1064
|
+
},
|
|
1065
|
+
{
|
|
1066
|
+
"id": "ff-transitions--implements--adr-actions-patch",
|
|
1067
|
+
"sourceId": "ff-transitions",
|
|
1068
|
+
"targetId": "adr-actions-patch",
|
|
1069
|
+
"relationType": "implements"
|
|
1070
|
+
},
|
|
1071
|
+
{
|
|
1072
|
+
"id": "ff-operation-poll--implements--adr-lro-operation",
|
|
1073
|
+
"sourceId": "ff-operation-poll",
|
|
1074
|
+
"targetId": "adr-lro-operation",
|
|
1075
|
+
"relationType": "implements"
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
"id": "ff-callback--implements--adr-lro-callback",
|
|
1079
|
+
"sourceId": "ff-callback",
|
|
1080
|
+
"targetId": "adr-lro-callback",
|
|
1081
|
+
"relationType": "implements"
|
|
1082
|
+
},
|
|
1083
|
+
{
|
|
1084
|
+
"id": "ff-latency--implements--adr-camel",
|
|
1085
|
+
"sourceId": "ff-latency",
|
|
1086
|
+
"targetId": "adr-camel",
|
|
1087
|
+
"relationType": "implements"
|
|
1088
|
+
},
|
|
1089
|
+
{
|
|
1090
|
+
"id": "ff-latency--implements--adr-snake",
|
|
1091
|
+
"sourceId": "ff-latency",
|
|
1092
|
+
"targetId": "adr-snake",
|
|
1093
|
+
"relationType": "implements"
|
|
1094
|
+
},
|
|
1095
|
+
{
|
|
1096
|
+
"id": "ff-latency--implements--adr-lro-none",
|
|
1097
|
+
"sourceId": "ff-latency",
|
|
1098
|
+
"targetId": "adr-lro-none",
|
|
1099
|
+
"relationType": "implements"
|
|
1100
|
+
}
|
|
1101
|
+
]
|
|
1102
|
+
}
|