http-response-kit 1.0.0 → 2.0.0
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/LICENSE +21 -21
- package/README.md +357 -272
- package/dist/chunk-373JVXMN.mjs +1199 -0
- package/dist/chunk-373JVXMN.mjs.map +1 -0
- package/dist/chunk-FFRB2EUE.mjs +36 -0
- package/dist/chunk-FFRB2EUE.mjs.map +1 -0
- package/dist/express.d.mts +50 -0
- package/dist/express.d.ts +50 -0
- package/dist/express.js +1155 -0
- package/dist/express.js.map +1 -0
- package/dist/express.mjs +28 -0
- package/dist/express.mjs.map +1 -0
- package/dist/fastify.d.mts +45 -0
- package/dist/fastify.d.ts +45 -0
- package/dist/fastify.js +1170 -0
- package/dist/fastify.js.map +1 -0
- package/dist/fastify.mjs +43 -0
- package/dist/fastify.mjs.map +1 -0
- package/dist/hono.d.mts +33 -0
- package/dist/hono.d.ts +33 -0
- package/dist/hono.js +1139 -0
- package/dist/hono.js.map +1 -0
- package/dist/hono.mjs +18 -0
- package/dist/hono.mjs.map +1 -0
- package/dist/index.d.mts +75 -493
- package/dist/index.d.ts +75 -493
- package/dist/index.js +480 -180
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +18 -891
- package/dist/index.mjs.map +1 -0
- package/dist/kit-nHfihlKE.d.mts +753 -0
- package/dist/kit-nHfihlKE.d.ts +753 -0
- package/dist/koa.d.mts +38 -0
- package/dist/koa.d.ts +38 -0
- package/dist/koa.js +1150 -0
- package/dist/koa.js.map +1 -0
- package/dist/koa.mjs +24 -0
- package/dist/koa.mjs.map +1 -0
- package/dist/schemas.d.mts +452 -0
- package/dist/schemas.d.ts +452 -0
- package/dist/schemas.js +124 -0
- package/dist/schemas.js.map +1 -0
- package/dist/schemas.mjs +119 -0
- package/dist/schemas.mjs.map +1 -0
- package/dist/shared-Czwmz6Xa.d.ts +22 -0
- package/dist/shared-DYq1Fic4.d.mts +22 -0
- package/package.json +104 -49
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Response Kit - JSON Schemas
|
|
3
|
+
*
|
|
4
|
+
* Machine-readable JSON Schema (draft 2020-12) definitions of the response
|
|
5
|
+
* shapes, usable for contract testing, gateway validation, and OpenAPI specs.
|
|
6
|
+
*
|
|
7
|
+
* Import from the dedicated subpath to keep your main bundle lean:
|
|
8
|
+
* `import { errorResponseSchema } from 'http-response-kit/schemas'`
|
|
9
|
+
*
|
|
10
|
+
* @module schemas
|
|
11
|
+
*/
|
|
12
|
+
/** JSON Schema for the standard success envelope */
|
|
13
|
+
declare const successResponseSchema: {
|
|
14
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
15
|
+
readonly $id: "https://github.com/matteo-teodori/http-response-kit/schemas/success-response.json";
|
|
16
|
+
readonly title: "SuccessResponse";
|
|
17
|
+
readonly type: "object";
|
|
18
|
+
readonly required: readonly ["success", "status_code"];
|
|
19
|
+
readonly properties: {
|
|
20
|
+
readonly success: {
|
|
21
|
+
readonly const: true;
|
|
22
|
+
};
|
|
23
|
+
readonly status_code: {
|
|
24
|
+
readonly type: "integer";
|
|
25
|
+
readonly minimum: 100;
|
|
26
|
+
readonly maximum: 399;
|
|
27
|
+
};
|
|
28
|
+
readonly timestamp: {
|
|
29
|
+
readonly type: "string";
|
|
30
|
+
readonly format: "date-time";
|
|
31
|
+
};
|
|
32
|
+
readonly request_id: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
};
|
|
35
|
+
readonly data: {};
|
|
36
|
+
readonly message: {
|
|
37
|
+
readonly type: "string";
|
|
38
|
+
};
|
|
39
|
+
readonly metadata: {
|
|
40
|
+
readonly type: "object";
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/** JSON Schema for the standard error envelope */
|
|
45
|
+
declare const errorResponseSchema: {
|
|
46
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
47
|
+
readonly $id: "https://github.com/matteo-teodori/http-response-kit/schemas/error-response.json";
|
|
48
|
+
readonly title: "ErrorResponse";
|
|
49
|
+
readonly type: "object";
|
|
50
|
+
readonly required: readonly ["success", "status_code", "error"];
|
|
51
|
+
readonly properties: {
|
|
52
|
+
readonly success: {
|
|
53
|
+
readonly const: false;
|
|
54
|
+
};
|
|
55
|
+
readonly status_code: {
|
|
56
|
+
readonly type: "integer";
|
|
57
|
+
readonly minimum: 400;
|
|
58
|
+
readonly maximum: 599;
|
|
59
|
+
};
|
|
60
|
+
readonly timestamp: {
|
|
61
|
+
readonly type: "string";
|
|
62
|
+
readonly format: "date-time";
|
|
63
|
+
};
|
|
64
|
+
readonly request_id: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
};
|
|
67
|
+
readonly retry_after: {
|
|
68
|
+
readonly type: "number";
|
|
69
|
+
};
|
|
70
|
+
readonly error: {
|
|
71
|
+
readonly type: "object";
|
|
72
|
+
readonly required: readonly ["type", "title", "message"];
|
|
73
|
+
readonly properties: {
|
|
74
|
+
readonly type: {
|
|
75
|
+
readonly type: "string";
|
|
76
|
+
};
|
|
77
|
+
readonly title: {
|
|
78
|
+
readonly type: "string";
|
|
79
|
+
};
|
|
80
|
+
readonly message: {
|
|
81
|
+
readonly type: "string";
|
|
82
|
+
};
|
|
83
|
+
readonly code: {
|
|
84
|
+
readonly type: "string";
|
|
85
|
+
};
|
|
86
|
+
readonly details: {
|
|
87
|
+
readonly type: "string";
|
|
88
|
+
};
|
|
89
|
+
readonly errors: {
|
|
90
|
+
readonly type: "array";
|
|
91
|
+
readonly items: {
|
|
92
|
+
readonly type: "object";
|
|
93
|
+
readonly required: readonly ["field", "message"];
|
|
94
|
+
readonly properties: {
|
|
95
|
+
readonly field: {
|
|
96
|
+
readonly type: "string";
|
|
97
|
+
readonly description: "Field/path that failed validation";
|
|
98
|
+
};
|
|
99
|
+
readonly message: {
|
|
100
|
+
readonly type: "string";
|
|
101
|
+
readonly description: "Human-readable description";
|
|
102
|
+
};
|
|
103
|
+
readonly code: {
|
|
104
|
+
readonly type: "string";
|
|
105
|
+
readonly description: "Stable machine-readable code";
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
readonly additionalProperties: false;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
readonly stack: {
|
|
112
|
+
readonly type: "string";
|
|
113
|
+
};
|
|
114
|
+
readonly causes: {
|
|
115
|
+
readonly type: "array";
|
|
116
|
+
readonly items: {
|
|
117
|
+
readonly type: "string";
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
readonly metadata: {
|
|
123
|
+
readonly type: "object";
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
/** JSON Schema for RFC 9457 Problem Details (with common extensions) */
|
|
128
|
+
declare const problemDetailsSchema: {
|
|
129
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
130
|
+
readonly $id: "https://github.com/matteo-teodori/http-response-kit/schemas/problem-details.json";
|
|
131
|
+
readonly title: "ProblemDetails";
|
|
132
|
+
readonly description: "RFC 9457 Problem Details for HTTP APIs";
|
|
133
|
+
readonly type: "object";
|
|
134
|
+
readonly required: readonly ["type", "title", "status"];
|
|
135
|
+
readonly properties: {
|
|
136
|
+
readonly type: {
|
|
137
|
+
readonly type: "string";
|
|
138
|
+
readonly format: "uri-reference";
|
|
139
|
+
readonly default: "about:blank";
|
|
140
|
+
};
|
|
141
|
+
readonly title: {
|
|
142
|
+
readonly type: "string";
|
|
143
|
+
};
|
|
144
|
+
readonly status: {
|
|
145
|
+
readonly type: "integer";
|
|
146
|
+
readonly minimum: 100;
|
|
147
|
+
readonly maximum: 599;
|
|
148
|
+
};
|
|
149
|
+
readonly detail: {
|
|
150
|
+
readonly type: "string";
|
|
151
|
+
};
|
|
152
|
+
readonly instance: {
|
|
153
|
+
readonly type: "string";
|
|
154
|
+
readonly format: "uri-reference";
|
|
155
|
+
};
|
|
156
|
+
readonly code: {
|
|
157
|
+
readonly type: "string";
|
|
158
|
+
};
|
|
159
|
+
readonly errors: {
|
|
160
|
+
readonly type: "array";
|
|
161
|
+
readonly items: {
|
|
162
|
+
readonly type: "object";
|
|
163
|
+
readonly required: readonly ["field", "message"];
|
|
164
|
+
readonly properties: {
|
|
165
|
+
readonly field: {
|
|
166
|
+
readonly type: "string";
|
|
167
|
+
readonly description: "Field/path that failed validation";
|
|
168
|
+
};
|
|
169
|
+
readonly message: {
|
|
170
|
+
readonly type: "string";
|
|
171
|
+
readonly description: "Human-readable description";
|
|
172
|
+
};
|
|
173
|
+
readonly code: {
|
|
174
|
+
readonly type: "string";
|
|
175
|
+
readonly description: "Stable machine-readable code";
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
readonly additionalProperties: false;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
readonly request_id: {
|
|
182
|
+
readonly type: "string";
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Ready-to-merge OpenAPI 3.1 `components` fragment.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* const spec = { openapi: '3.1.0', ...yourSpec, components: { schemas: { ...openApiComponents.schemas } } };
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare const openApiComponents: {
|
|
195
|
+
readonly schemas: {
|
|
196
|
+
readonly SuccessResponse: {
|
|
197
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
198
|
+
readonly $id: "https://github.com/matteo-teodori/http-response-kit/schemas/success-response.json";
|
|
199
|
+
readonly title: "SuccessResponse";
|
|
200
|
+
readonly type: "object";
|
|
201
|
+
readonly required: readonly ["success", "status_code"];
|
|
202
|
+
readonly properties: {
|
|
203
|
+
readonly success: {
|
|
204
|
+
readonly const: true;
|
|
205
|
+
};
|
|
206
|
+
readonly status_code: {
|
|
207
|
+
readonly type: "integer";
|
|
208
|
+
readonly minimum: 100;
|
|
209
|
+
readonly maximum: 399;
|
|
210
|
+
};
|
|
211
|
+
readonly timestamp: {
|
|
212
|
+
readonly type: "string";
|
|
213
|
+
readonly format: "date-time";
|
|
214
|
+
};
|
|
215
|
+
readonly request_id: {
|
|
216
|
+
readonly type: "string";
|
|
217
|
+
};
|
|
218
|
+
readonly data: {};
|
|
219
|
+
readonly message: {
|
|
220
|
+
readonly type: "string";
|
|
221
|
+
};
|
|
222
|
+
readonly metadata: {
|
|
223
|
+
readonly type: "object";
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
readonly ErrorResponse: {
|
|
228
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
229
|
+
readonly $id: "https://github.com/matteo-teodori/http-response-kit/schemas/error-response.json";
|
|
230
|
+
readonly title: "ErrorResponse";
|
|
231
|
+
readonly type: "object";
|
|
232
|
+
readonly required: readonly ["success", "status_code", "error"];
|
|
233
|
+
readonly properties: {
|
|
234
|
+
readonly success: {
|
|
235
|
+
readonly const: false;
|
|
236
|
+
};
|
|
237
|
+
readonly status_code: {
|
|
238
|
+
readonly type: "integer";
|
|
239
|
+
readonly minimum: 400;
|
|
240
|
+
readonly maximum: 599;
|
|
241
|
+
};
|
|
242
|
+
readonly timestamp: {
|
|
243
|
+
readonly type: "string";
|
|
244
|
+
readonly format: "date-time";
|
|
245
|
+
};
|
|
246
|
+
readonly request_id: {
|
|
247
|
+
readonly type: "string";
|
|
248
|
+
};
|
|
249
|
+
readonly retry_after: {
|
|
250
|
+
readonly type: "number";
|
|
251
|
+
};
|
|
252
|
+
readonly error: {
|
|
253
|
+
readonly type: "object";
|
|
254
|
+
readonly required: readonly ["type", "title", "message"];
|
|
255
|
+
readonly properties: {
|
|
256
|
+
readonly type: {
|
|
257
|
+
readonly type: "string";
|
|
258
|
+
};
|
|
259
|
+
readonly title: {
|
|
260
|
+
readonly type: "string";
|
|
261
|
+
};
|
|
262
|
+
readonly message: {
|
|
263
|
+
readonly type: "string";
|
|
264
|
+
};
|
|
265
|
+
readonly code: {
|
|
266
|
+
readonly type: "string";
|
|
267
|
+
};
|
|
268
|
+
readonly details: {
|
|
269
|
+
readonly type: "string";
|
|
270
|
+
};
|
|
271
|
+
readonly errors: {
|
|
272
|
+
readonly type: "array";
|
|
273
|
+
readonly items: {
|
|
274
|
+
readonly type: "object";
|
|
275
|
+
readonly required: readonly ["field", "message"];
|
|
276
|
+
readonly properties: {
|
|
277
|
+
readonly field: {
|
|
278
|
+
readonly type: "string";
|
|
279
|
+
readonly description: "Field/path that failed validation";
|
|
280
|
+
};
|
|
281
|
+
readonly message: {
|
|
282
|
+
readonly type: "string";
|
|
283
|
+
readonly description: "Human-readable description";
|
|
284
|
+
};
|
|
285
|
+
readonly code: {
|
|
286
|
+
readonly type: "string";
|
|
287
|
+
readonly description: "Stable machine-readable code";
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
readonly additionalProperties: false;
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
readonly stack: {
|
|
294
|
+
readonly type: "string";
|
|
295
|
+
};
|
|
296
|
+
readonly causes: {
|
|
297
|
+
readonly type: "array";
|
|
298
|
+
readonly items: {
|
|
299
|
+
readonly type: "string";
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
readonly metadata: {
|
|
305
|
+
readonly type: "object";
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
readonly ProblemDetails: {
|
|
310
|
+
readonly $schema: "https://json-schema.org/draft/2020-12/schema";
|
|
311
|
+
readonly $id: "https://github.com/matteo-teodori/http-response-kit/schemas/problem-details.json";
|
|
312
|
+
readonly title: "ProblemDetails";
|
|
313
|
+
readonly description: "RFC 9457 Problem Details for HTTP APIs";
|
|
314
|
+
readonly type: "object";
|
|
315
|
+
readonly required: readonly ["type", "title", "status"];
|
|
316
|
+
readonly properties: {
|
|
317
|
+
readonly type: {
|
|
318
|
+
readonly type: "string";
|
|
319
|
+
readonly format: "uri-reference";
|
|
320
|
+
readonly default: "about:blank";
|
|
321
|
+
};
|
|
322
|
+
readonly title: {
|
|
323
|
+
readonly type: "string";
|
|
324
|
+
};
|
|
325
|
+
readonly status: {
|
|
326
|
+
readonly type: "integer";
|
|
327
|
+
readonly minimum: 100;
|
|
328
|
+
readonly maximum: 599;
|
|
329
|
+
};
|
|
330
|
+
readonly detail: {
|
|
331
|
+
readonly type: "string";
|
|
332
|
+
};
|
|
333
|
+
readonly instance: {
|
|
334
|
+
readonly type: "string";
|
|
335
|
+
readonly format: "uri-reference";
|
|
336
|
+
};
|
|
337
|
+
readonly code: {
|
|
338
|
+
readonly type: "string";
|
|
339
|
+
};
|
|
340
|
+
readonly errors: {
|
|
341
|
+
readonly type: "array";
|
|
342
|
+
readonly items: {
|
|
343
|
+
readonly type: "object";
|
|
344
|
+
readonly required: readonly ["field", "message"];
|
|
345
|
+
readonly properties: {
|
|
346
|
+
readonly field: {
|
|
347
|
+
readonly type: "string";
|
|
348
|
+
readonly description: "Field/path that failed validation";
|
|
349
|
+
};
|
|
350
|
+
readonly message: {
|
|
351
|
+
readonly type: "string";
|
|
352
|
+
readonly description: "Human-readable description";
|
|
353
|
+
};
|
|
354
|
+
readonly code: {
|
|
355
|
+
readonly type: "string";
|
|
356
|
+
readonly description: "Stable machine-readable code";
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
readonly additionalProperties: false;
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
readonly request_id: {
|
|
363
|
+
readonly type: "string";
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
readonly responses: {
|
|
369
|
+
readonly BadRequest: {
|
|
370
|
+
readonly description: "Bad Request";
|
|
371
|
+
readonly content: {
|
|
372
|
+
readonly 'application/json': {
|
|
373
|
+
readonly schema: {
|
|
374
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
readonly Unauthorized: {
|
|
380
|
+
readonly description: "Unauthorized";
|
|
381
|
+
readonly content: {
|
|
382
|
+
readonly 'application/json': {
|
|
383
|
+
readonly schema: {
|
|
384
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
385
|
+
};
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
readonly Forbidden: {
|
|
390
|
+
readonly description: "Forbidden";
|
|
391
|
+
readonly content: {
|
|
392
|
+
readonly 'application/json': {
|
|
393
|
+
readonly schema: {
|
|
394
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
395
|
+
};
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
readonly NotFound: {
|
|
400
|
+
readonly description: "Not Found";
|
|
401
|
+
readonly content: {
|
|
402
|
+
readonly 'application/json': {
|
|
403
|
+
readonly schema: {
|
|
404
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
};
|
|
409
|
+
readonly UnprocessableEntity: {
|
|
410
|
+
readonly description: "Validation failed";
|
|
411
|
+
readonly content: {
|
|
412
|
+
readonly 'application/json': {
|
|
413
|
+
readonly schema: {
|
|
414
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
415
|
+
};
|
|
416
|
+
};
|
|
417
|
+
};
|
|
418
|
+
};
|
|
419
|
+
readonly TooManyRequests: {
|
|
420
|
+
readonly description: "Too Many Requests";
|
|
421
|
+
readonly content: {
|
|
422
|
+
readonly 'application/json': {
|
|
423
|
+
readonly schema: {
|
|
424
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
readonly InternalServerError: {
|
|
430
|
+
readonly description: "Internal Server Error";
|
|
431
|
+
readonly content: {
|
|
432
|
+
readonly 'application/json': {
|
|
433
|
+
readonly schema: {
|
|
434
|
+
readonly $ref: "#/components/schemas/ErrorResponse";
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
};
|
|
439
|
+
readonly Problem: {
|
|
440
|
+
readonly description: "RFC 9457 Problem Details";
|
|
441
|
+
readonly content: {
|
|
442
|
+
readonly 'application/problem+json': {
|
|
443
|
+
readonly schema: {
|
|
444
|
+
readonly $ref: "#/components/schemas/ProblemDetails";
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
};
|
|
448
|
+
};
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
export { errorResponseSchema, openApiComponents, problemDetailsSchema, successResponseSchema };
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/schemas/index.ts
|
|
4
|
+
var validationIssueSchema = {
|
|
5
|
+
type: "object",
|
|
6
|
+
required: ["field", "message"],
|
|
7
|
+
properties: {
|
|
8
|
+
field: { type: "string", description: "Field/path that failed validation" },
|
|
9
|
+
message: { type: "string", description: "Human-readable description" },
|
|
10
|
+
code: { type: "string", description: "Stable machine-readable code" }
|
|
11
|
+
},
|
|
12
|
+
additionalProperties: false
|
|
13
|
+
};
|
|
14
|
+
var successResponseSchema = {
|
|
15
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
16
|
+
$id: "https://github.com/matteo-teodori/http-response-kit/schemas/success-response.json",
|
|
17
|
+
title: "SuccessResponse",
|
|
18
|
+
type: "object",
|
|
19
|
+
required: ["success", "status_code"],
|
|
20
|
+
properties: {
|
|
21
|
+
success: { const: true },
|
|
22
|
+
status_code: { type: "integer", minimum: 100, maximum: 399 },
|
|
23
|
+
timestamp: { type: "string", format: "date-time" },
|
|
24
|
+
request_id: { type: "string" },
|
|
25
|
+
data: {},
|
|
26
|
+
message: { type: "string" },
|
|
27
|
+
metadata: { type: "object" }
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var errorResponseSchema = {
|
|
31
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
32
|
+
$id: "https://github.com/matteo-teodori/http-response-kit/schemas/error-response.json",
|
|
33
|
+
title: "ErrorResponse",
|
|
34
|
+
type: "object",
|
|
35
|
+
required: ["success", "status_code", "error"],
|
|
36
|
+
properties: {
|
|
37
|
+
success: { const: false },
|
|
38
|
+
status_code: { type: "integer", minimum: 400, maximum: 599 },
|
|
39
|
+
timestamp: { type: "string", format: "date-time" },
|
|
40
|
+
request_id: { type: "string" },
|
|
41
|
+
retry_after: { type: "number" },
|
|
42
|
+
error: {
|
|
43
|
+
type: "object",
|
|
44
|
+
required: ["type", "title", "message"],
|
|
45
|
+
properties: {
|
|
46
|
+
type: { type: "string" },
|
|
47
|
+
title: { type: "string" },
|
|
48
|
+
message: { type: "string" },
|
|
49
|
+
code: { type: "string" },
|
|
50
|
+
details: { type: "string" },
|
|
51
|
+
errors: { type: "array", items: validationIssueSchema },
|
|
52
|
+
stack: { type: "string" },
|
|
53
|
+
causes: { type: "array", items: { type: "string" } }
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
metadata: { type: "object" }
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var problemDetailsSchema = {
|
|
60
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
61
|
+
$id: "https://github.com/matteo-teodori/http-response-kit/schemas/problem-details.json",
|
|
62
|
+
title: "ProblemDetails",
|
|
63
|
+
description: "RFC 9457 Problem Details for HTTP APIs",
|
|
64
|
+
type: "object",
|
|
65
|
+
required: ["type", "title", "status"],
|
|
66
|
+
properties: {
|
|
67
|
+
type: { type: "string", format: "uri-reference", default: "about:blank" },
|
|
68
|
+
title: { type: "string" },
|
|
69
|
+
status: { type: "integer", minimum: 100, maximum: 599 },
|
|
70
|
+
detail: { type: "string" },
|
|
71
|
+
instance: { type: "string", format: "uri-reference" },
|
|
72
|
+
code: { type: "string" },
|
|
73
|
+
errors: { type: "array", items: validationIssueSchema },
|
|
74
|
+
request_id: { type: "string" }
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var openApiComponents = {
|
|
78
|
+
schemas: {
|
|
79
|
+
SuccessResponse: successResponseSchema,
|
|
80
|
+
ErrorResponse: errorResponseSchema,
|
|
81
|
+
ProblemDetails: problemDetailsSchema
|
|
82
|
+
},
|
|
83
|
+
responses: {
|
|
84
|
+
BadRequest: {
|
|
85
|
+
description: "Bad Request",
|
|
86
|
+
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
87
|
+
},
|
|
88
|
+
Unauthorized: {
|
|
89
|
+
description: "Unauthorized",
|
|
90
|
+
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
91
|
+
},
|
|
92
|
+
Forbidden: {
|
|
93
|
+
description: "Forbidden",
|
|
94
|
+
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
95
|
+
},
|
|
96
|
+
NotFound: {
|
|
97
|
+
description: "Not Found",
|
|
98
|
+
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
99
|
+
},
|
|
100
|
+
UnprocessableEntity: {
|
|
101
|
+
description: "Validation failed",
|
|
102
|
+
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
103
|
+
},
|
|
104
|
+
TooManyRequests: {
|
|
105
|
+
description: "Too Many Requests",
|
|
106
|
+
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
107
|
+
},
|
|
108
|
+
InternalServerError: {
|
|
109
|
+
description: "Internal Server Error",
|
|
110
|
+
content: { "application/json": { schema: { $ref: "#/components/schemas/ErrorResponse" } } }
|
|
111
|
+
},
|
|
112
|
+
Problem: {
|
|
113
|
+
description: "RFC 9457 Problem Details",
|
|
114
|
+
content: { "application/problem+json": { schema: { $ref: "#/components/schemas/ProblemDetails" } } }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
exports.errorResponseSchema = errorResponseSchema;
|
|
120
|
+
exports.openApiComponents = openApiComponents;
|
|
121
|
+
exports.problemDetailsSchema = problemDetailsSchema;
|
|
122
|
+
exports.successResponseSchema = successResponseSchema;
|
|
123
|
+
//# sourceMappingURL=schemas.js.map
|
|
124
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/index.ts"],"names":[],"mappings":";;;AAYA,IAAM,qBAAA,GAAwB;AAAA,EAC1B,IAAA,EAAM,QAAA;AAAA,EACN,QAAA,EAAU,CAAC,OAAA,EAAS,SAAS,CAAA;AAAA,EAC7B,UAAA,EAAY;AAAA,IACR,KAAA,EAAO,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,mCAAA,EAAoC;AAAA,IAC1E,OAAA,EAAS,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,4BAAA,EAA6B;AAAA,IACrE,IAAA,EAAM,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,8BAAA;AAA+B,GACxE;AAAA,EACA,oBAAA,EAAsB;AAC1B,CAAA;AAGO,IAAM,qBAAA,GAAwB;AAAA,EACjC,OAAA,EAAS,8CAAA;AAAA,EACT,GAAA,EAAK,mFAAA;AAAA,EACL,KAAA,EAAO,iBAAA;AAAA,EACP,IAAA,EAAM,QAAA;AAAA,EACN,QAAA,EAAU,CAAC,SAAA,EAAW,aAAa,CAAA;AAAA,EACnC,UAAA,EAAY;AAAA,IACR,OAAA,EAAS,EAAE,KAAA,EAAO,IAAA,EAAK;AAAA,IACvB,aAAa,EAAE,IAAA,EAAM,WAAW,OAAA,EAAS,GAAA,EAAK,SAAS,GAAA,EAAI;AAAA,IAC3D,SAAA,EAAW,EAAE,IAAA,EAAM,QAAA,EAAU,QAAQ,WAAA,EAAY;AAAA,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,EAAM,qCAAA,EAAsC,EAAE;AAAE;AACvG;AAER","file":"schemas.js","sourcesContent":["/**\n * HTTP Response Kit - JSON Schemas\n *\n * Machine-readable JSON Schema (draft 2020-12) definitions of the response\n * shapes, usable for contract testing, gateway validation, and OpenAPI specs.\n *\n * Import from the dedicated subpath to keep your main bundle lean:\n * `import { errorResponseSchema } from 'http-response-kit/schemas'`\n *\n * @module schemas\n */\n\nconst validationIssueSchema = {\n type: 'object',\n required: ['field', 'message'],\n properties: {\n field: { type: 'string', description: 'Field/path that failed validation' },\n message: { type: 'string', description: 'Human-readable description' },\n code: { type: 'string', description: 'Stable machine-readable code' },\n },\n additionalProperties: false,\n} as const;\n\n/** JSON Schema for the standard success envelope */\nexport const successResponseSchema = {\n $schema: 'https://json-schema.org/draft/2020-12/schema',\n $id: 'https://github.com/matteo-teodori/http-response-kit/schemas/success-response.json',\n title: 'SuccessResponse',\n type: 'object',\n required: ['success', 'status_code'],\n properties: {\n success: { const: true },\n status_code: { type: 'integer', minimum: 100, maximum: 399 },\n timestamp: { type: 'string', format: 'date-time' },\n request_id: { type: 'string' },\n data: {},\n message: { type: 'string' },\n metadata: { type: 'object' },\n },\n} as const;\n\n/** JSON Schema for the standard error envelope */\nexport const errorResponseSchema = {\n $schema: 'https://json-schema.org/draft/2020-12/schema',\n $id: 'https://github.com/matteo-teodori/http-response-kit/schemas/error-response.json',\n title: 'ErrorResponse',\n type: 'object',\n required: ['success', 'status_code', 'error'],\n properties: {\n success: { const: false },\n status_code: { type: 'integer', minimum: 400, maximum: 599 },\n timestamp: { type: 'string', format: 'date-time' },\n request_id: { type: 'string' },\n retry_after: { type: 'number' },\n error: {\n type: 'object',\n required: ['type', 'title', 'message'],\n properties: {\n type: { type: 'string' },\n title: { type: 'string' },\n message: { type: 'string' },\n code: { type: 'string' },\n details: { type: 'string' },\n errors: { type: 'array', items: validationIssueSchema },\n stack: { type: 'string' },\n causes: { type: 'array', items: { type: 'string' } },\n },\n },\n metadata: { type: 'object' },\n },\n} as const;\n\n/** JSON Schema for RFC 9457 Problem Details (with common extensions) */\nexport const problemDetailsSchema = {\n $schema: 'https://json-schema.org/draft/2020-12/schema',\n $id: 'https://github.com/matteo-teodori/http-response-kit/schemas/problem-details.json',\n title: 'ProblemDetails',\n description: 'RFC 9457 Problem Details for HTTP APIs',\n type: 'object',\n required: ['type', 'title', 'status'],\n properties: {\n type: { type: 'string', format: 'uri-reference', default: 'about:blank' },\n title: { type: 'string' },\n status: { type: 'integer', minimum: 100, maximum: 599 },\n detail: { type: 'string' },\n instance: { type: 'string', format: 'uri-reference' },\n code: { type: 'string' },\n errors: { type: 'array', items: validationIssueSchema },\n request_id: { type: 'string' },\n },\n} as const;\n\n/**\n * Ready-to-merge OpenAPI 3.1 `components` fragment.\n *\n * @example\n * ```ts\n * const spec = { openapi: '3.1.0', ...yourSpec, components: { schemas: { ...openApiComponents.schemas } } };\n * ```\n */\nexport const openApiComponents = {\n schemas: {\n SuccessResponse: successResponseSchema,\n ErrorResponse: errorResponseSchema,\n ProblemDetails: problemDetailsSchema,\n },\n responses: {\n BadRequest: {\n description: 'Bad Request',\n content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } },\n },\n Unauthorized: {\n description: 'Unauthorized',\n content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } },\n },\n Forbidden: {\n description: 'Forbidden',\n content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } },\n },\n NotFound: {\n description: 'Not Found',\n content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } },\n },\n UnprocessableEntity: {\n description: 'Validation failed',\n content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } },\n },\n TooManyRequests: {\n description: 'Too Many Requests',\n content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } },\n },\n InternalServerError: {\n description: 'Internal Server Error',\n content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } },\n },\n Problem: {\n description: 'RFC 9457 Problem Details',\n content: { 'application/problem+json': { schema: { $ref: '#/components/schemas/ProblemDetails' } } },\n },\n },\n} as const;\n"]}
|