adorn-api 1.0.1 → 1.0.2
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 +4 -1
- package/dist/adapters/express/createApp.d.ts +149 -11
- package/dist/adapters/express/createApp.d.ts.map +1 -1
- package/dist/adapters/express/createApp.js +112 -6
- package/dist/adapters/express/createApp.js.map +1 -1
- package/dist/adapters/express/middleware/errorHandler.d.ts +193 -2
- package/dist/adapters/express/middleware/errorHandler.d.ts.map +1 -1
- package/dist/adapters/express/middleware/errorHandler.js +164 -3
- package/dist/adapters/express/middleware/errorHandler.js.map +1 -1
- package/dist/adapters/express/router.d.ts +1 -1
- package/dist/adapters/express/router.d.ts.map +1 -1
- package/dist/adapters/express/router.js +6 -4
- package/dist/adapters/express/router.js.map +1 -1
- package/dist/adapters/express/transport/request.js.map +1 -1
- package/dist/adapters/express/transport/response.d.ts +1 -1
- package/dist/adapters/express/transport/response.d.ts.map +1 -1
- package/dist/adapters/express/transport/response.js.map +1 -1
- package/dist/contracts/openapi-v3.d.ts +461 -0
- package/dist/contracts/openapi-v3.d.ts.map +1 -1
- package/dist/contracts/reply.d.ts +109 -1
- package/dist/contracts/reply.d.ts.map +1 -1
- package/dist/contracts/reply.js +40 -1
- package/dist/contracts/reply.js.map +1 -1
- package/dist/contracts/response-types.d.ts +5 -5
- package/dist/contracts/response-types.d.ts.map +1 -1
- package/dist/contracts/responses.d.ts +84 -4
- package/dist/contracts/responses.d.ts.map +1 -1
- package/dist/contracts/route-options.d.ts +134 -3
- package/dist/contracts/route-options.d.ts.map +1 -1
- package/dist/contracts/validator.d.ts +121 -0
- package/dist/contracts/validator.d.ts.map +1 -1
- package/dist/core/binding/binder.d.ts +56 -1
- package/dist/core/binding/binder.d.ts.map +1 -1
- package/dist/core/binding/binder.js +33 -0
- package/dist/core/binding/binder.js.map +1 -1
- package/dist/core/binding/coerce/primitives.d.ts +68 -1
- package/dist/core/binding/coerce/primitives.d.ts.map +1 -1
- package/dist/core/binding/coerce/primitives.js +82 -12
- package/dist/core/binding/coerce/primitives.js.map +1 -1
- package/dist/core/errors/http-error.d.ts +54 -0
- package/dist/core/errors/http-error.d.ts.map +1 -1
- package/dist/core/errors/http-error.js +54 -0
- package/dist/core/errors/http-error.js.map +1 -1
- package/dist/core/errors/validation-error.d.ts +65 -0
- package/dist/core/errors/validation-error.d.ts.map +1 -1
- package/dist/core/errors/validation-error.js +65 -0
- package/dist/core/errors/validation-error.js.map +1 -1
- package/dist/core/openapi/buildOpenApi.d.ts +65 -0
- package/dist/core/openapi/buildOpenApi.d.ts.map +1 -1
- package/dist/core/openapi/buildOpenApi.js +66 -4
- package/dist/core/openapi/buildOpenApi.js.map +1 -1
- package/dist/core/openapi/schema/registry.d.ts +1 -1
- package/dist/core/openapi/schema/registry.d.ts.map +1 -1
- package/dist/core/openapi/schema/registry.js.map +1 -1
- package/dist/core/registry/buildRegistry.d.ts.map +1 -1
- package/dist/core/registry/buildRegistry.js +49 -5
- package/dist/core/registry/buildRegistry.js.map +1 -1
- package/dist/core/registry/types.d.ts +194 -1
- package/dist/core/registry/types.d.ts.map +1 -1
- package/dist/core/reply/reply.d.ts +94 -0
- package/dist/core/reply/reply.d.ts.map +1 -1
- package/dist/core/reply/reply.js +87 -0
- package/dist/core/reply/reply.js.map +1 -1
- package/dist/core/reply/typed.d.ts +137 -3
- package/dist/core/reply/typed.d.ts.map +1 -1
- package/dist/core/reply/typed.js +137 -2
- package/dist/core/reply/typed.js.map +1 -1
- package/dist/core/responses/helpers.d.ts +1 -1
- package/dist/core/responses/helpers.d.ts.map +1 -1
- package/dist/core/responses/normalize.d.ts.map +1 -1
- package/dist/core/responses/normalize.js +2 -1
- package/dist/core/responses/normalize.js.map +1 -1
- package/dist/core/route/defineRoute.d.ts +48 -1
- package/dist/core/route/defineRoute.d.ts.map +1 -1
- package/dist/core/route/defineRoute.js +42 -1
- package/dist/core/route/defineRoute.js.map +1 -1
- package/dist/decorators/binding.d.ts +1 -1
- package/dist/decorators/binding.d.ts.map +1 -1
- package/dist/decorators/binding.js.map +1 -1
- package/dist/decorators/controller.d.ts +1 -1
- package/dist/decorators/controller.d.ts.map +1 -1
- package/dist/decorators/controller.js.map +1 -1
- package/dist/decorators/docs.d.ts +6 -0
- package/dist/decorators/docs.d.ts.map +1 -1
- package/dist/decorators/docs.js +45 -2
- package/dist/decorators/docs.js.map +1 -1
- package/dist/decorators/index.d.ts +3 -0
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +3 -0
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/methods.d.ts +128 -6
- package/dist/decorators/methods.d.ts.map +1 -1
- package/dist/decorators/methods.js +124 -0
- package/dist/decorators/methods.js.map +1 -1
- package/dist/decorators/responses.d.ts +5 -0
- package/dist/decorators/responses.d.ts.map +1 -1
- package/dist/decorators/responses.js +43 -2
- package/dist/decorators/responses.js.map +1 -1
- package/dist/decorators/security.d.ts +6 -0
- package/dist/decorators/security.d.ts.map +1 -1
- package/dist/decorators/security.js +38 -2
- package/dist/decorators/security.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/metal-orm/schema/column-map.d.ts +91 -0
- package/dist/integrations/metal-orm/schema/column-map.d.ts.map +1 -1
- package/dist/integrations/metal-orm/schema/column-map.js +129 -2
- package/dist/integrations/metal-orm/schema/column-map.js.map +1 -1
- package/dist/integrations/metal-orm/schema/dto.d.ts +2 -2
- package/dist/integrations/metal-orm/schema/dto.d.ts.map +1 -1
- package/dist/integrations/metal-orm/schema/dto.js.map +1 -1
- package/dist/integrations/metal-orm/schema/entity.d.ts +90 -8
- package/dist/integrations/metal-orm/schema/entity.d.ts.map +1 -1
- package/dist/integrations/metal-orm/schema/entity.js +78 -6
- package/dist/integrations/metal-orm/schema/entity.js.map +1 -1
- package/dist/integrations/metal-orm/schema/filters.d.ts +1 -1
- package/dist/integrations/metal-orm/schema/filters.d.ts.map +1 -1
- package/dist/integrations/metal-orm/schema/filters.js +2 -1
- package/dist/integrations/metal-orm/schema/filters.js.map +1 -1
- package/dist/integrations/metal-orm/schema/tabledef.d.ts +1 -1
- package/dist/integrations/metal-orm/schema/tabledef.d.ts.map +1 -1
- package/dist/metadata/bag.d.ts +2 -1
- package/dist/metadata/bag.d.ts.map +1 -1
- package/dist/metadata/bag.js +2 -1
- package/dist/metadata/bag.js.map +1 -1
- package/dist/metadata/keys.d.ts +203 -1
- package/dist/metadata/keys.d.ts.map +1 -1
- package/dist/metadata/keys.js +3 -9
- package/dist/metadata/keys.js.map +1 -1
- package/dist/metadata/merge.d.ts.map +1 -1
- package/dist/metadata/merge.js +4 -1
- package/dist/metadata/merge.js.map +1 -1
- package/dist/validation/native/schema.d.ts +2 -2
- package/dist/validation/native/schema.d.ts.map +1 -1
- package/dist/validation/native/validator.d.ts +1 -1
- package/dist/validation/native/validator.d.ts.map +1 -1
- package/package.json +6 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binder.js","sourceRoot":"","sources":["../../../src/core/binding/binder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"binder.js","sourceRoot":"","sources":["../../../src/core/binding/binder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,M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EAAE,oBAAoB;oBAC1B,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE;iBAC5D,CAAC,CAAC;YACL,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC;QAED,KAAK,MAAM,CAAC,CAAC,CAAC;YACZ,MAAM,EAAE,GAAG,4EAA4E,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClG,IAAI,CAAC,EAAE,EAAE,CAAC;gBACR,MAAM,IAAI,SAAS,CAAC,GAAG,EAAE,gCAAgC,SAAS,IAAI,GAAG,GAAG,EAAE;oBAC5E,IAAI,EAAE,oBAAoB;oBAC1B,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE;iBAC1D,CAAC,CAAC;YACL,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QAED;YACE,OAAO,GAAG,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coercion modes for automatic type conversion.
|
|
3
|
+
*
|
|
4
|
+
* Controls how primitive values are automatically converted
|
|
5
|
+
* during parameter binding.
|
|
6
|
+
*
|
|
7
|
+
* - `'none'` - No coercion; values remain as provided
|
|
8
|
+
* - `'smart'` - Intelligent type inference from string values
|
|
9
|
+
*/
|
|
1
10
|
export type CoerceMode = 'none' | 'smart';
|
|
2
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Smart coercion for primitive values.
|
|
13
|
+
*
|
|
14
|
+
* Automatically converts string values to appropriate primitive types:
|
|
15
|
+
*
|
|
16
|
+
* | Input | Output |
|
|
17
|
+
* |----------------------------|---------------------|
|
|
18
|
+
* | `'null'` | `null` |
|
|
19
|
+
* | `'true'` / `'false'` | `boolean` |
|
|
20
|
+
* | `'42'`, `'3.14'`, `'-10'` | `number` |
|
|
21
|
+
* | Other strings | `string` (trimmed) |
|
|
22
|
+
*
|
|
23
|
+
* @param value - Value to coerce
|
|
24
|
+
* @returns Coerced primitive value
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* - Whitespace is trimmed before type detection
|
|
28
|
+
* - Non-string values pass through unchanged
|
|
29
|
+
* - Leading zeros preserve string type (`'007'` → `'007'`)
|
|
30
|
+
* - Special values (`Infinity`, `NaN`) are not coerced
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Boolean coercion
|
|
35
|
+
* coercePrimitiveSmart('true'); // → true
|
|
36
|
+
* coercePrimitiveSmart('false'); // → false
|
|
37
|
+
*
|
|
38
|
+
* // Numeric coercion
|
|
39
|
+
* coercePrimitiveSmart('42'); // → 42
|
|
40
|
+
* coercePrimitiveSmart('3.14'); // → 3.14
|
|
41
|
+
* coercePrimitiveSmart('-10'); // → -10
|
|
42
|
+
*
|
|
43
|
+
* // Null coercion
|
|
44
|
+
* coercePrimitiveSmart('null'); // → null
|
|
45
|
+
*
|
|
46
|
+
* // String handling
|
|
47
|
+
* coercePrimitiveSmart(' hello '); // → 'hello'
|
|
48
|
+
* coercePrimitiveSmart('007'); // → '007' (preserved)
|
|
49
|
+
*
|
|
50
|
+
* // Non-string pass-through
|
|
51
|
+
* coercePrimitiveSmart(42); // → 42
|
|
52
|
+
* coercePrimitiveSmart(null); // → null
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function coercePrimitiveSmart(value: unknown): unknown;
|
|
56
|
+
/**
|
|
57
|
+
* Coerce a value based on the specified mode.
|
|
58
|
+
*
|
|
59
|
+
* @param value - Value to coerce
|
|
60
|
+
* @param mode - Coercion mode to apply
|
|
61
|
+
* @returns Coerced value (or original if mode is 'none')
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* coercePrimitive('42', 'smart'); // → 42
|
|
66
|
+
* coercePrimitive('42', 'none'); // → '42'
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function coercePrimitive(value: unknown, mode: CoerceMode): unknown;
|
|
3
70
|
//# sourceMappingURL=primitives.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../../../src/core/binding/coerce/primitives.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../../../src/core/binding/coerce/primitives.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;AAS1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAqB5D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAEzE"}
|
|
@@ -1,18 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Pattern for valid numeric strings.
|
|
3
|
+
* Matches integers and decimals with optional negative sign.
|
|
4
|
+
* Rejects leading zeros to preserve string IDs (e.g., '007').
|
|
5
|
+
*/
|
|
6
|
+
const NUMERIC_RE = /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/;
|
|
7
|
+
/**
|
|
8
|
+
* Smart coercion for primitive values.
|
|
9
|
+
*
|
|
10
|
+
* Automatically converts string values to appropriate primitive types:
|
|
11
|
+
*
|
|
12
|
+
* | Input | Output |
|
|
13
|
+
* |----------------------------|---------------------|
|
|
14
|
+
* | `'null'` | `null` |
|
|
15
|
+
* | `'true'` / `'false'` | `boolean` |
|
|
16
|
+
* | `'42'`, `'3.14'`, `'-10'` | `number` |
|
|
17
|
+
* | Other strings | `string` (trimmed) |
|
|
18
|
+
*
|
|
19
|
+
* @param value - Value to coerce
|
|
20
|
+
* @returns Coerced primitive value
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* - Whitespace is trimmed before type detection
|
|
24
|
+
* - Non-string values pass through unchanged
|
|
25
|
+
* - Leading zeros preserve string type (`'007'` → `'007'`)
|
|
26
|
+
* - Special values (`Infinity`, `NaN`) are not coerced
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Boolean coercion
|
|
31
|
+
* coercePrimitiveSmart('true'); // → true
|
|
32
|
+
* coercePrimitiveSmart('false'); // → false
|
|
33
|
+
*
|
|
34
|
+
* // Numeric coercion
|
|
35
|
+
* coercePrimitiveSmart('42'); // → 42
|
|
36
|
+
* coercePrimitiveSmart('3.14'); // → 3.14
|
|
37
|
+
* coercePrimitiveSmart('-10'); // → -10
|
|
38
|
+
*
|
|
39
|
+
* // Null coercion
|
|
40
|
+
* coercePrimitiveSmart('null'); // → null
|
|
41
|
+
*
|
|
42
|
+
* // String handling
|
|
43
|
+
* coercePrimitiveSmart(' hello '); // → 'hello'
|
|
44
|
+
* coercePrimitiveSmart('007'); // → '007' (preserved)
|
|
45
|
+
*
|
|
46
|
+
* // Non-string pass-through
|
|
47
|
+
* coercePrimitiveSmart(42); // → 42
|
|
48
|
+
* coercePrimitiveSmart(null); // → null
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function coercePrimitiveSmart(value) {
|
|
52
|
+
if (typeof value !== 'string') {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
const trimmed = value.trim();
|
|
56
|
+
// Special literal values
|
|
57
|
+
if (trimmed === 'null')
|
|
6
58
|
return null;
|
|
7
|
-
if (
|
|
59
|
+
if (trimmed === 'true')
|
|
8
60
|
return true;
|
|
9
|
-
if (
|
|
61
|
+
if (trimmed === 'false')
|
|
10
62
|
return false;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
63
|
+
// Numeric conversion (excludes leading zeros and special values)
|
|
64
|
+
if (trimmed !== '' && NUMERIC_RE.test(trimmed)) {
|
|
65
|
+
const num = Number(trimmed);
|
|
66
|
+
if (Number.isFinite(num)) {
|
|
67
|
+
return num;
|
|
68
|
+
}
|
|
15
69
|
}
|
|
16
|
-
return
|
|
70
|
+
return trimmed;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Coerce a value based on the specified mode.
|
|
74
|
+
*
|
|
75
|
+
* @param value - Value to coerce
|
|
76
|
+
* @param mode - Coercion mode to apply
|
|
77
|
+
* @returns Coerced value (or original if mode is 'none')
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* coercePrimitive('42', 'smart'); // → 42
|
|
82
|
+
* coercePrimitive('42', 'none'); // → '42'
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export function coercePrimitive(value, mode) {
|
|
86
|
+
return mode === 'smart' ? coercePrimitiveSmart(value) : value;
|
|
17
87
|
}
|
|
18
88
|
//# sourceMappingURL=primitives.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../../../src/core/binding/coerce/primitives.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../../../src/core/binding/coerce/primitives.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,MAAM,UAAU,GAAG,8BAA8B,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAE7B,yBAAyB;IACzB,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,OAAO,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAEtC,iEAAiE;IACjE,IAAI,OAAO,KAAK,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/C,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc,EAAE,IAAgB;IAC9D,OAAO,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAChE,CAAC"}
|
|
@@ -1,9 +1,63 @@
|
|
|
1
1
|
import type { HttpErrorLike, HttpErrorOptions } from '../../contracts/errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP Error class for representing HTTP errors with status codes.
|
|
4
|
+
*
|
|
5
|
+
* This class extends the native Error class and implements HttpErrorLike interface.
|
|
6
|
+
* It's used throughout the framework to represent HTTP errors that should be
|
|
7
|
+
* returned to clients with appropriate status codes and error details.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Basic usage
|
|
12
|
+
* throw new HttpError(404, 'User not found');
|
|
13
|
+
*
|
|
14
|
+
* // With error code and details
|
|
15
|
+
* throw new HttpError(400, 'Invalid input', {
|
|
16
|
+
* code: 'INVALID_INPUT',
|
|
17
|
+
* details: { field: 'email', reason: 'must be valid email' }
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // For internal server errors (not exposed to client by default)
|
|
21
|
+
* throw new HttpError(500, 'Database connection failed', {
|
|
22
|
+
* expose: false
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // In a controller
|
|
29
|
+
* @Get('/users/:id')
|
|
30
|
+
* async getUser(id: string) {
|
|
31
|
+
* const user = await userService.findById(id);
|
|
32
|
+
* if (!user) {
|
|
33
|
+
* throw new HttpError(404, 'User not found', {
|
|
34
|
+
* code: 'USER_NOT_FOUND',
|
|
35
|
+
* details: { id }
|
|
36
|
+
* });
|
|
37
|
+
* }
|
|
38
|
+
* return user;
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
2
42
|
export declare class HttpError extends Error implements HttpErrorLike {
|
|
43
|
+
/** HTTP status code (e.g., 404, 500) */
|
|
3
44
|
readonly status: number;
|
|
45
|
+
/** Optional error code for programmatic handling */
|
|
4
46
|
readonly code?: string;
|
|
47
|
+
/** Additional error details (can be any type) */
|
|
5
48
|
readonly details?: unknown;
|
|
49
|
+
/** Whether to expose this error to clients */
|
|
6
50
|
readonly expose: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new HttpError instance.
|
|
53
|
+
*
|
|
54
|
+
* @param status - HTTP status code
|
|
55
|
+
* @param message - Error message
|
|
56
|
+
* @param options - Additional error options
|
|
57
|
+
* @param options.code - Optional error code
|
|
58
|
+
* @param options.details - Additional error details
|
|
59
|
+
* @param options.expose - Whether to expose to clients (default: true for 4xx, false for 5xx)
|
|
60
|
+
*/
|
|
7
61
|
constructor(status: number, message: string, options?: HttpErrorOptions);
|
|
8
62
|
}
|
|
9
63
|
//# sourceMappingURL=http-error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-error.d.ts","sourceRoot":"","sources":["../../../src/core/errors/http-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAEjF,qBAAa,SAAU,SAAQ,KAAM,YAAW,aAAa;IAC3D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClC,SAAgB,MAAM,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"http-error.d.ts","sourceRoot":"","sources":["../../../src/core/errors/http-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,SAAU,SAAQ,KAAM,YAAW,aAAa;IAC3D,wCAAwC;IACxC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,oDAAoD;IACpD,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAC9B,iDAAiD;IACjD,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClC,8CAA8C;IAC9C,SAAgB,MAAM,EAAE,OAAO,CAAC;IAEhC;;;;;;;;;OASG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB;CAU5E"}
|
|
@@ -1,8 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Error class for representing HTTP errors with status codes.
|
|
3
|
+
*
|
|
4
|
+
* This class extends the native Error class and implements HttpErrorLike interface.
|
|
5
|
+
* It's used throughout the framework to represent HTTP errors that should be
|
|
6
|
+
* returned to clients with appropriate status codes and error details.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic usage
|
|
11
|
+
* throw new HttpError(404, 'User not found');
|
|
12
|
+
*
|
|
13
|
+
* // With error code and details
|
|
14
|
+
* throw new HttpError(400, 'Invalid input', {
|
|
15
|
+
* code: 'INVALID_INPUT',
|
|
16
|
+
* details: { field: 'email', reason: 'must be valid email' }
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // For internal server errors (not exposed to client by default)
|
|
20
|
+
* throw new HttpError(500, 'Database connection failed', {
|
|
21
|
+
* expose: false
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // In a controller
|
|
28
|
+
* @Get('/users/:id')
|
|
29
|
+
* async getUser(id: string) {
|
|
30
|
+
* const user = await userService.findById(id);
|
|
31
|
+
* if (!user) {
|
|
32
|
+
* throw new HttpError(404, 'User not found', {
|
|
33
|
+
* code: 'USER_NOT_FOUND',
|
|
34
|
+
* details: { id }
|
|
35
|
+
* });
|
|
36
|
+
* }
|
|
37
|
+
* return user;
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
1
41
|
export class HttpError extends Error {
|
|
42
|
+
/** HTTP status code (e.g., 404, 500) */
|
|
2
43
|
status;
|
|
44
|
+
/** Optional error code for programmatic handling */
|
|
3
45
|
code;
|
|
46
|
+
/** Additional error details (can be any type) */
|
|
4
47
|
details;
|
|
48
|
+
/** Whether to expose this error to clients */
|
|
5
49
|
expose;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new HttpError instance.
|
|
52
|
+
*
|
|
53
|
+
* @param status - HTTP status code
|
|
54
|
+
* @param message - Error message
|
|
55
|
+
* @param options - Additional error options
|
|
56
|
+
* @param options.code - Optional error code
|
|
57
|
+
* @param options.details - Additional error details
|
|
58
|
+
* @param options.expose - Whether to expose to clients (default: true for 4xx, false for 5xx)
|
|
59
|
+
*/
|
|
6
60
|
constructor(status, message, options = {}) {
|
|
7
61
|
super(message);
|
|
8
62
|
this.name = 'HttpError';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-error.js","sourceRoot":"","sources":["../../../src/core/errors/http-error.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,SAAU,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"http-error.js","sourceRoot":"","sources":["../../../src/core/errors/http-error.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,wCAAwC;IACxB,MAAM,CAAS;IAC/B,oDAAoD;IACpC,IAAI,CAAU;IAC9B,iDAAiD;IACjC,OAAO,CAAW;IAClC,8CAA8C;IAC9B,MAAM,CAAU;IAEhC;;;;;;;;;OASG;IACH,YAAY,MAAc,EAAE,OAAe,EAAE,UAA4B,EAAE;QACzE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,CAAC,CAAC;IAClE,CAAC;CACF"}
|
|
@@ -1,8 +1,73 @@
|
|
|
1
1
|
import { HttpError } from './http-error.js';
|
|
2
2
|
import type { ValidationIssue } from '../../contracts/validator.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validation Error class for representing validation failures.
|
|
5
|
+
*
|
|
6
|
+
* This class extends HttpError and is specifically used for validation errors.
|
|
7
|
+
* It includes an array of validation issues that provide detailed information
|
|
8
|
+
* about what validation failed and where.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Manual creation
|
|
13
|
+
* const error = new ValidationError('Invalid user data', [
|
|
14
|
+
* { path: ['body', 'email'], message: 'Email is required' },
|
|
15
|
+
* { path: ['body', 'password'], message: 'Password must be at least 8 characters' }
|
|
16
|
+
* ]);
|
|
17
|
+
*
|
|
18
|
+
* throw error;
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Using the convenience method
|
|
24
|
+
* const issues = [
|
|
25
|
+
* { path: ['query', 'limit'], message: 'Limit must be a number' },
|
|
26
|
+
* { path: ['query', 'offset'], message: 'Offset must be a positive integer' }
|
|
27
|
+
* ];
|
|
28
|
+
*
|
|
29
|
+
* throw ValidationError.fromIssues(issues, 'Invalid query parameters');
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // In a controller with validation
|
|
35
|
+
* @Post('/users')
|
|
36
|
+
* async createUser(@Body() userData: CreateUserDto) {
|
|
37
|
+
* const validationResult = await validator.validate(userData);
|
|
38
|
+
*
|
|
39
|
+
* if (!validationResult.valid) {
|
|
40
|
+
* throw ValidationError.fromIssues(validationResult.issues);
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* return await userService.create(userData);
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
3
47
|
export declare class ValidationError extends HttpError {
|
|
48
|
+
/** Array of validation issues with paths and messages */
|
|
4
49
|
readonly issues: ValidationIssue[];
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new ValidationError instance.
|
|
52
|
+
*
|
|
53
|
+
* @param message - Overall validation error message
|
|
54
|
+
* @param issues - Array of validation issues
|
|
55
|
+
*/
|
|
5
56
|
constructor(message: string, issues: ValidationIssue[]);
|
|
57
|
+
/**
|
|
58
|
+
* Convenience method to create a ValidationError from issues.
|
|
59
|
+
*
|
|
60
|
+
* @param issues - Array of validation issues
|
|
61
|
+
* @param message - Optional custom message (default: 'Validation failed')
|
|
62
|
+
* @returns New ValidationError instance
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const error = ValidationError.fromIssues([
|
|
67
|
+
* { path: ['body', 'email'], message: 'Invalid email format' }
|
|
68
|
+
* ]);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
6
71
|
static fromIssues(issues: ValidationIssue[], message?: string): ValidationError;
|
|
7
72
|
}
|
|
8
73
|
//# sourceMappingURL=validation-error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation-error.d.ts","sourceRoot":"","sources":["../../../src/core/errors/validation-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,qBAAa,eAAgB,SAAQ,SAAS;IAC5C,SAAgB,MAAM,EAAE,eAAe,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"validation-error.d.ts","sourceRoot":"","sources":["../../../src/core/errors/validation-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,qBAAa,eAAgB,SAAQ,SAAS;IAC5C,yDAAyD;IACzD,SAAgB,MAAM,EAAE,eAAe,EAAE,CAAC;IAE1C;;;;;OAKG;gBACS,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE;IAUtD;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,eAAe,EAAE,EAAE,OAAO,SAAsB,GAAG,eAAe;CAG7F"}
|
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
import { HttpError } from './http-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validation Error class for representing validation failures.
|
|
4
|
+
*
|
|
5
|
+
* This class extends HttpError and is specifically used for validation errors.
|
|
6
|
+
* It includes an array of validation issues that provide detailed information
|
|
7
|
+
* about what validation failed and where.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Manual creation
|
|
12
|
+
* const error = new ValidationError('Invalid user data', [
|
|
13
|
+
* { path: ['body', 'email'], message: 'Email is required' },
|
|
14
|
+
* { path: ['body', 'password'], message: 'Password must be at least 8 characters' }
|
|
15
|
+
* ]);
|
|
16
|
+
*
|
|
17
|
+
* throw error;
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Using the convenience method
|
|
23
|
+
* const issues = [
|
|
24
|
+
* { path: ['query', 'limit'], message: 'Limit must be a number' },
|
|
25
|
+
* { path: ['query', 'offset'], message: 'Offset must be a positive integer' }
|
|
26
|
+
* ];
|
|
27
|
+
*
|
|
28
|
+
* throw ValidationError.fromIssues(issues, 'Invalid query parameters');
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // In a controller with validation
|
|
34
|
+
* @Post('/users')
|
|
35
|
+
* async createUser(@Body() userData: CreateUserDto) {
|
|
36
|
+
* const validationResult = await validator.validate(userData);
|
|
37
|
+
*
|
|
38
|
+
* if (!validationResult.valid) {
|
|
39
|
+
* throw ValidationError.fromIssues(validationResult.issues);
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* return await userService.create(userData);
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
2
46
|
export class ValidationError extends HttpError {
|
|
47
|
+
/** Array of validation issues with paths and messages */
|
|
3
48
|
issues;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new ValidationError instance.
|
|
51
|
+
*
|
|
52
|
+
* @param message - Overall validation error message
|
|
53
|
+
* @param issues - Array of validation issues
|
|
54
|
+
*/
|
|
4
55
|
constructor(message, issues) {
|
|
5
56
|
super(400, message, {
|
|
6
57
|
code: 'VALIDATION_ERROR',
|
|
@@ -10,6 +61,20 @@ export class ValidationError extends HttpError {
|
|
|
10
61
|
this.name = 'ValidationError';
|
|
11
62
|
this.issues = issues;
|
|
12
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Convenience method to create a ValidationError from issues.
|
|
66
|
+
*
|
|
67
|
+
* @param issues - Array of validation issues
|
|
68
|
+
* @param message - Optional custom message (default: 'Validation failed')
|
|
69
|
+
* @returns New ValidationError instance
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const error = ValidationError.fromIssues([
|
|
74
|
+
* { path: ['body', 'email'], message: 'Invalid email format' }
|
|
75
|
+
* ]);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
13
78
|
static fromIssues(issues, message = 'Validation failed') {
|
|
14
79
|
return new ValidationError(message, issues);
|
|
15
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../../../src/core/errors/validation-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;
|
|
1
|
+
{"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../../../src/core/errors/validation-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,yDAAyD;IACzC,MAAM,CAAoB;IAE1C;;;;;OAKG;IACH,YAAY,OAAe,EAAE,MAAyB;QACpD,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE;YAClB,IAAI,EAAE,kBAAkB;YACxB,OAAO,EAAE,EAAE,MAAM,EAAE;YACnB,MAAM,EAAE,IAAI;SACb,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,UAAU,CAAC,MAAyB,EAAE,OAAO,GAAG,mBAAmB;QACxE,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -1,14 +1,79 @@
|
|
|
1
1
|
import type { OpenApiDocument } from '../../contracts/openapi-v3.js';
|
|
2
2
|
import type { Registry } from '../registry/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Options for building OpenAPI documentation.
|
|
5
|
+
*
|
|
6
|
+
* These options configure the basic metadata and behavior of the generated
|
|
7
|
+
* OpenAPI specification.
|
|
8
|
+
*/
|
|
3
9
|
export type OpenApiBuildOptions = {
|
|
10
|
+
/** Title of the API */
|
|
4
11
|
title: string;
|
|
12
|
+
/** Version of the API */
|
|
5
13
|
version: string;
|
|
14
|
+
/** Array of server objects with URLs and descriptions */
|
|
6
15
|
servers?: {
|
|
7
16
|
url: string;
|
|
8
17
|
description?: string;
|
|
9
18
|
}[];
|
|
19
|
+
/** Default content type for request bodies */
|
|
10
20
|
defaultRequestContentType?: string;
|
|
21
|
+
/** Default content type for response bodies */
|
|
11
22
|
defaultResponseContentType?: string;
|
|
12
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Builds a complete OpenAPI 3.0.3 specification document from the route registry.
|
|
26
|
+
*
|
|
27
|
+
* This function generates a comprehensive OpenAPI specification by analyzing
|
|
28
|
+
* the route registry and extracting all necessary information including paths,
|
|
29
|
+
* operations, parameters, request/response bodies, and security schemes.
|
|
30
|
+
*
|
|
31
|
+
* @param registry - Route registry containing all registered routes and metadata
|
|
32
|
+
* @param opts - OpenAPI build options including title, version, and servers
|
|
33
|
+
* @returns Complete OpenAPI 3.0.3 document ready for serving or serialization
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { buildRegistry } from './registry';
|
|
38
|
+
* import { buildOpenApi } from './openapi';
|
|
39
|
+
*
|
|
40
|
+
* // Build route registry from controllers
|
|
41
|
+
* const registry = buildRegistry([UserController, ProductController]);
|
|
42
|
+
*
|
|
43
|
+
* // Generate OpenAPI specification
|
|
44
|
+
* const openApiDoc = buildOpenApi(registry, {
|
|
45
|
+
* title: 'My API',
|
|
46
|
+
* version: '1.0.0',
|
|
47
|
+
* servers: [
|
|
48
|
+
* { url: 'https://api.example.com/v1', description: 'Production server' },
|
|
49
|
+
* { url: 'https://staging.api.example.com/v1', description: 'Staging server' }
|
|
50
|
+
* ],
|
|
51
|
+
* defaultRequestContentType: 'application/json',
|
|
52
|
+
* defaultResponseContentType: 'application/json'
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // Serve the OpenAPI JSON
|
|
56
|
+
* app.get('/openapi.json', (req, res) => {
|
|
57
|
+
* res.json(openApiDoc);
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // With custom content types
|
|
64
|
+
* const openApiDoc = buildOpenApi(registry, {
|
|
65
|
+
* title: 'Multi-format API',
|
|
66
|
+
* version: '2.0.0',
|
|
67
|
+
* defaultRequestContentType: 'application/json',
|
|
68
|
+
* defaultResponseContentType: 'application/problem+json'
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* // The generated spec will use application/problem+json for error responses
|
|
72
|
+
* // and application/json for successful responses by default
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @see Registry for route registry structure
|
|
76
|
+
* @see OpenApiDocument for the returned document structure
|
|
77
|
+
*/
|
|
13
78
|
export declare function buildOpenApi(registry: Registry, opts: OpenApiBuildOptions): OpenApiDocument;
|
|
14
79
|
//# sourceMappingURL=buildOpenApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildOpenApi.d.ts","sourceRoot":"","sources":["../../../src/core/openapi/buildOpenApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,
|
|
1
|
+
{"version":3,"file":"buildOpenApi.d.ts","sourceRoot":"","sources":["../../../src/core/openapi/buildOpenApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAMhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,sBAAsB,CAAC;AASjE;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,OAAO,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAClD,8CAA8C;IAC9C,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,+CAA+C;IAC/C,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,mBAAmB,GAAG,eAAe,CAoD3F"}
|