kontract 0.1.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/README.md +435 -0
- package/dist/builder/define-controller.d.ts +115 -0
- package/dist/builder/define-controller.d.ts.map +1 -0
- package/dist/builder/define-controller.js +80 -0
- package/dist/builder/define-controller.js.map +1 -0
- package/dist/builder/define-endpoint.d.ts +157 -0
- package/dist/builder/define-endpoint.d.ts.map +1 -0
- package/dist/builder/define-endpoint.js +103 -0
- package/dist/builder/define-endpoint.js.map +1 -0
- package/dist/builder/define-route.d.ts +191 -0
- package/dist/builder/define-route.d.ts.map +1 -0
- package/dist/builder/define-route.js +124 -0
- package/dist/builder/define-route.js.map +1 -0
- package/dist/builder/index.d.ts +5 -0
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +7 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/openapi-builder.d.ts +120 -0
- package/dist/builder/openapi-builder.d.ts.map +1 -0
- package/dist/builder/openapi-builder.js +349 -0
- package/dist/builder/openapi-builder.js.map +1 -0
- package/dist/builder/path-params.d.ts +129 -0
- package/dist/builder/path-params.d.ts.map +1 -0
- package/dist/builder/path-params.js +85 -0
- package/dist/builder/path-params.js.map +1 -0
- package/dist/builder/types.d.ts +149 -0
- package/dist/builder/types.d.ts.map +1 -0
- package/dist/builder/types.js +6 -0
- package/dist/builder/types.js.map +1 -0
- package/dist/config/defaults.d.ts +10 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +28 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/define-config.d.ts +50 -0
- package/dist/config/define-config.d.ts.map +1 -0
- package/dist/config/define-config.js +80 -0
- package/dist/config/define-config.js.map +1 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +5 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +103 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/decorators/api.d.ts +35 -0
- package/dist/decorators/api.d.ts.map +1 -0
- package/dist/decorators/api.js +34 -0
- package/dist/decorators/api.js.map +1 -0
- package/dist/decorators/controller.d.ts +35 -0
- package/dist/decorators/controller.d.ts.map +1 -0
- package/dist/decorators/controller.js +34 -0
- package/dist/decorators/controller.js.map +1 -0
- package/dist/decorators/endpoint.d.ts +93 -0
- package/dist/decorators/endpoint.d.ts.map +1 -0
- package/dist/decorators/endpoint.js +108 -0
- package/dist/decorators/endpoint.js.map +1 -0
- package/dist/decorators/index.d.ts +5 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +6 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/route.d.ts +93 -0
- package/dist/decorators/route.d.ts.map +1 -0
- package/dist/decorators/route.js +108 -0
- package/dist/decorators/route.js.map +1 -0
- package/dist/errors/base.d.ts +8 -0
- package/dist/errors/base.d.ts.map +1 -0
- package/dist/errors/base.js +13 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/configuration.d.ts +22 -0
- package/dist/errors/configuration.d.ts.map +1 -0
- package/dist/errors/configuration.js +33 -0
- package/dist/errors/configuration.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/validation.d.ts +46 -0
- package/dist/errors/validation.d.ts.map +1 -0
- package/dist/errors/validation.js +52 -0
- package/dist/errors/validation.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata/index.d.ts +2 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +2 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/storage.d.ts +50 -0
- package/dist/metadata/storage.d.ts.map +1 -0
- package/dist/metadata/storage.js +100 -0
- package/dist/metadata/storage.js.map +1 -0
- package/dist/metadata/types.d.ts +142 -0
- package/dist/metadata/types.d.ts.map +1 -0
- package/dist/metadata/types.js +2 -0
- package/dist/metadata/types.js.map +1 -0
- package/dist/response/helpers.d.ts +132 -0
- package/dist/response/helpers.d.ts.map +1 -0
- package/dist/response/helpers.js +197 -0
- package/dist/response/helpers.js.map +1 -0
- package/dist/response/index.d.ts +4 -0
- package/dist/response/index.d.ts.map +1 -0
- package/dist/response/index.js +4 -0
- package/dist/response/index.js.map +1 -0
- package/dist/response/types.d.ts +59 -0
- package/dist/response/types.d.ts.map +1 -0
- package/dist/response/types.js +26 -0
- package/dist/response/types.js.map +1 -0
- package/dist/runtime/adapter-types.d.ts +119 -0
- package/dist/runtime/adapter-types.d.ts.map +1 -0
- package/dist/runtime/adapter-types.js +2 -0
- package/dist/runtime/adapter-types.js.map +1 -0
- package/dist/runtime/index.d.ts +12 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/response-helpers.d.ts +138 -0
- package/dist/runtime/response-helpers.d.ts.map +1 -0
- package/dist/runtime/response-helpers.js +105 -0
- package/dist/runtime/response-helpers.js.map +1 -0
- package/dist/runtime/route-utils.d.ts +22 -0
- package/dist/runtime/route-utils.d.ts.map +1 -0
- package/dist/runtime/route-utils.js +47 -0
- package/dist/runtime/route-utils.js.map +1 -0
- package/dist/runtime/types.d.ts +125 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/validation/index.d.ts +3 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +3 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/types.d.ts +55 -0
- package/dist/validation/types.d.ts.map +1 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/types.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path parameter extraction utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides both compile-time type inference and runtime extraction
|
|
5
|
+
* of path parameters from route strings.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Type-level inference
|
|
10
|
+
* type Params = ParamsFromPath<'/users/:userId/posts/:postId'>
|
|
11
|
+
* // Result: { userId: string, postId: string }
|
|
12
|
+
*
|
|
13
|
+
* // Runtime extraction
|
|
14
|
+
* const names = extractParamNames('/users/:userId/posts/:postId')
|
|
15
|
+
* // Result: ['userId', 'postId']
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import { Type } from '@sinclair/typebox';
|
|
19
|
+
// =============================================================================
|
|
20
|
+
// Runtime Extraction
|
|
21
|
+
// =============================================================================
|
|
22
|
+
/**
|
|
23
|
+
* Extract parameter names from a path string at runtime.
|
|
24
|
+
*
|
|
25
|
+
* @param path - Route path with `:param` placeholders
|
|
26
|
+
* @returns Array of parameter names
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* extractParamNames('/users/:id')
|
|
31
|
+
* // Result: ['id']
|
|
32
|
+
*
|
|
33
|
+
* extractParamNames('/users/:userId/posts/:postId')
|
|
34
|
+
* // Result: ['userId', 'postId']
|
|
35
|
+
*
|
|
36
|
+
* extractParamNames('/users')
|
|
37
|
+
* // Result: []
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function extractParamNames(path) {
|
|
41
|
+
const matches = path.matchAll(/:(\w+)/g);
|
|
42
|
+
return [...matches].map((m) => m[1]);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create a TypeBox schema for path parameters.
|
|
46
|
+
* All parameters are `Type.String()` by default.
|
|
47
|
+
*
|
|
48
|
+
* @param paramNames - Array of parameter names
|
|
49
|
+
* @returns TypeBox object schema, or undefined if no params
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* createParamsSchema(['id'])
|
|
54
|
+
* // Result: Type.Object({ id: Type.String() })
|
|
55
|
+
*
|
|
56
|
+
* createParamsSchema(['userId', 'postId'])
|
|
57
|
+
* // Result: Type.Object({ userId: Type.String(), postId: Type.String() })
|
|
58
|
+
*
|
|
59
|
+
* createParamsSchema([])
|
|
60
|
+
* // Result: undefined
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export function createParamsSchema(paramNames) {
|
|
64
|
+
if (paramNames.length === 0)
|
|
65
|
+
return undefined;
|
|
66
|
+
const properties = {};
|
|
67
|
+
for (const name of paramNames) {
|
|
68
|
+
properties[name] = Type.String();
|
|
69
|
+
}
|
|
70
|
+
return Type.Object(properties);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get or create a params schema for a route.
|
|
74
|
+
* Uses explicit schema if provided, otherwise generates from path.
|
|
75
|
+
*
|
|
76
|
+
* @param path - Route path
|
|
77
|
+
* @param explicitSchema - Explicitly provided params schema (optional)
|
|
78
|
+
* @returns TypeBox schema or undefined
|
|
79
|
+
*/
|
|
80
|
+
export function getParamsSchema(path, explicitSchema) {
|
|
81
|
+
if (explicitSchema)
|
|
82
|
+
return explicitSchema;
|
|
83
|
+
return createParamsSchema(extractParamNames(path));
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=path-params.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-params.js","sourceRoot":"","sources":["../../src/builder/path-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,IAAI,EAA4C,MAAM,mBAAmB,CAAA;AAgFlF,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;IACxC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACtC,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAoB;IACrD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAE7C,MAAM,UAAU,GAA4B,EAAE,CAAA;IAC9C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;IAClC,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;AAChC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,cAAwB;IACpE,IAAI,cAAc;QAAE,OAAO,cAAc,CAAA;IACzC,OAAO,kBAAkB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAA;AACpD,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAPI 3.1.0 specification types.
|
|
3
|
+
* Minimal subset needed for the builder.
|
|
4
|
+
*/
|
|
5
|
+
export type OpenApiVersion = '3.1.0' | '3.0.3';
|
|
6
|
+
export interface OpenApiDocument {
|
|
7
|
+
openapi: OpenApiVersion;
|
|
8
|
+
info: OpenApiInfo;
|
|
9
|
+
servers?: OpenApiServer[];
|
|
10
|
+
paths: Record<string, OpenApiPathItem>;
|
|
11
|
+
components?: {
|
|
12
|
+
schemas?: Record<string, OpenApiSchema>;
|
|
13
|
+
securitySchemes?: Record<string, OpenApiSecurityScheme>;
|
|
14
|
+
};
|
|
15
|
+
tags?: OpenApiTag[];
|
|
16
|
+
security?: Array<Record<string, string[]>>;
|
|
17
|
+
}
|
|
18
|
+
export interface OpenApiInfo {
|
|
19
|
+
title: string;
|
|
20
|
+
version: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
termsOfService?: string;
|
|
23
|
+
contact?: {
|
|
24
|
+
name?: string;
|
|
25
|
+
url?: string;
|
|
26
|
+
email?: string;
|
|
27
|
+
};
|
|
28
|
+
license?: {
|
|
29
|
+
name: string;
|
|
30
|
+
url?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface OpenApiServer {
|
|
34
|
+
url: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface OpenApiTag {
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface OpenApiPathItem {
|
|
42
|
+
get?: OpenApiOperation;
|
|
43
|
+
post?: OpenApiOperation;
|
|
44
|
+
put?: OpenApiOperation;
|
|
45
|
+
patch?: OpenApiOperation;
|
|
46
|
+
delete?: OpenApiOperation;
|
|
47
|
+
parameters?: OpenApiParameter[];
|
|
48
|
+
}
|
|
49
|
+
export interface OpenApiOperation {
|
|
50
|
+
operationId?: string;
|
|
51
|
+
summary?: string;
|
|
52
|
+
description?: string;
|
|
53
|
+
tags?: string[];
|
|
54
|
+
deprecated?: boolean;
|
|
55
|
+
security?: Array<Record<string, string[]>>;
|
|
56
|
+
parameters?: OpenApiParameter[];
|
|
57
|
+
requestBody?: OpenApiRequestBody;
|
|
58
|
+
responses: Record<string, OpenApiResponse>;
|
|
59
|
+
}
|
|
60
|
+
export interface OpenApiParameter {
|
|
61
|
+
name: string;
|
|
62
|
+
in: 'query' | 'path' | 'header' | 'cookie';
|
|
63
|
+
description?: string;
|
|
64
|
+
required?: boolean;
|
|
65
|
+
deprecated?: boolean;
|
|
66
|
+
schema?: OpenApiSchema;
|
|
67
|
+
}
|
|
68
|
+
export interface OpenApiRequestBody {
|
|
69
|
+
description?: string;
|
|
70
|
+
required?: boolean;
|
|
71
|
+
content: Record<string, OpenApiMediaType>;
|
|
72
|
+
}
|
|
73
|
+
export interface OpenApiResponse {
|
|
74
|
+
description: string;
|
|
75
|
+
content?: Record<string, OpenApiMediaType>;
|
|
76
|
+
headers?: Record<string, OpenApiHeader>;
|
|
77
|
+
}
|
|
78
|
+
export interface OpenApiMediaType {
|
|
79
|
+
schema?: OpenApiSchema | {
|
|
80
|
+
$ref: string;
|
|
81
|
+
};
|
|
82
|
+
example?: unknown;
|
|
83
|
+
examples?: Record<string, {
|
|
84
|
+
value: unknown;
|
|
85
|
+
summary?: string;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
export interface OpenApiHeader {
|
|
89
|
+
description?: string;
|
|
90
|
+
required?: boolean;
|
|
91
|
+
schema?: OpenApiSchema;
|
|
92
|
+
}
|
|
93
|
+
export interface OpenApiSchema {
|
|
94
|
+
type?: string;
|
|
95
|
+
format?: string;
|
|
96
|
+
title?: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
default?: unknown;
|
|
99
|
+
enum?: unknown[];
|
|
100
|
+
const?: unknown;
|
|
101
|
+
nullable?: boolean;
|
|
102
|
+
readOnly?: boolean;
|
|
103
|
+
writeOnly?: boolean;
|
|
104
|
+
deprecated?: boolean;
|
|
105
|
+
example?: unknown;
|
|
106
|
+
properties?: Record<string, OpenApiSchema>;
|
|
107
|
+
required?: string[];
|
|
108
|
+
additionalProperties?: boolean | OpenApiSchema;
|
|
109
|
+
items?: OpenApiSchema;
|
|
110
|
+
minItems?: number;
|
|
111
|
+
maxItems?: number;
|
|
112
|
+
uniqueItems?: boolean;
|
|
113
|
+
minLength?: number;
|
|
114
|
+
maxLength?: number;
|
|
115
|
+
pattern?: string;
|
|
116
|
+
minimum?: number;
|
|
117
|
+
maximum?: number;
|
|
118
|
+
exclusiveMinimum?: number;
|
|
119
|
+
exclusiveMaximum?: number;
|
|
120
|
+
multipleOf?: number;
|
|
121
|
+
allOf?: OpenApiSchema[];
|
|
122
|
+
anyOf?: OpenApiSchema[];
|
|
123
|
+
oneOf?: OpenApiSchema[];
|
|
124
|
+
not?: OpenApiSchema;
|
|
125
|
+
$ref?: string;
|
|
126
|
+
}
|
|
127
|
+
export interface OpenApiSecurityScheme {
|
|
128
|
+
type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
|
|
129
|
+
description?: string;
|
|
130
|
+
name?: string;
|
|
131
|
+
in?: 'query' | 'header' | 'cookie';
|
|
132
|
+
scheme?: string;
|
|
133
|
+
bearerFormat?: string;
|
|
134
|
+
flows?: OpenApiOAuthFlows;
|
|
135
|
+
openIdConnectUrl?: string;
|
|
136
|
+
}
|
|
137
|
+
export interface OpenApiOAuthFlows {
|
|
138
|
+
implicit?: OpenApiOAuthFlow;
|
|
139
|
+
password?: OpenApiOAuthFlow;
|
|
140
|
+
clientCredentials?: OpenApiOAuthFlow;
|
|
141
|
+
authorizationCode?: OpenApiOAuthFlow;
|
|
142
|
+
}
|
|
143
|
+
export interface OpenApiOAuthFlow {
|
|
144
|
+
authorizationUrl?: string;
|
|
145
|
+
tokenUrl?: string;
|
|
146
|
+
refreshUrl?: string;
|
|
147
|
+
scopes: Record<string, string>;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/builder/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,OAAO,CAAA;AAE9C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,OAAO,CAAC,EAAE,aAAa,EAAE,CAAA;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACtC,UAAU,CAAC,EAAE;QACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;QACvC,eAAe,CAAC,EAAE,MAAM,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,aAAa,EAAE,CAAA;IACvB,KAAK,CAAC,EAAE,aAAa,EAAE,CAAA;IACvB,GAAG,CAAC,EAAE,aAAa,CAAA;IAEnB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,eAAe,CAAA;IACpD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,EAAE,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAA;IAClC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,iBAAiB,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B,iBAAiB,CAAC,EAAE,gBAAgB,CAAA;IACpC,iBAAiB,CAAC,EAAE,gBAAgB,CAAA;CACrC;AAED,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/builder/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { OpenApiDecoratorConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Default runtime configuration values.
|
|
4
|
+
*/
|
|
5
|
+
export declare const defaultRuntimeConfig: Required<OpenApiDecoratorConfig['runtime']>;
|
|
6
|
+
/**
|
|
7
|
+
* Merge user config with defaults.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeWithDefaults(userConfig: Partial<OpenApiDecoratorConfig>): OpenApiDecoratorConfig;
|
|
10
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAExD;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAI5E,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,OAAO,CAAC,sBAAsB,CAAC,GAC1C,sBAAsB,CAexB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default runtime configuration values.
|
|
3
|
+
*/
|
|
4
|
+
export const defaultRuntimeConfig = {
|
|
5
|
+
validateResponses: false,
|
|
6
|
+
validateRequests: true,
|
|
7
|
+
stripUnknownProperties: false,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Merge user config with defaults.
|
|
11
|
+
*/
|
|
12
|
+
export function mergeWithDefaults(userConfig) {
|
|
13
|
+
return {
|
|
14
|
+
openapi: userConfig.openapi ?? {
|
|
15
|
+
info: {
|
|
16
|
+
title: 'API',
|
|
17
|
+
version: '1.0.0',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
runtime: {
|
|
21
|
+
...defaultRuntimeConfig,
|
|
22
|
+
...userConfig.runtime,
|
|
23
|
+
},
|
|
24
|
+
validator: userConfig.validator,
|
|
25
|
+
serializers: userConfig.serializers,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAgD;IAC/E,iBAAiB,EAAE,KAAK;IACxB,gBAAgB,EAAE,IAAI;IACtB,sBAAsB,EAAE,KAAK;CAC9B,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAA2C;IAE3C,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI;YAC7B,IAAI,EAAE;gBACJ,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,OAAO;aACjB;SACF;QACD,OAAO,EAAE;YACP,GAAG,oBAAoB;YACvB,GAAG,UAAU,CAAC,OAAO;SACtB;QACD,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,WAAW,EAAE,UAAU,CAAC,WAAW;KACpC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { OpenApiDecoratorConfig, UserConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Define and register the OpenAPI decorator configuration.
|
|
4
|
+
*
|
|
5
|
+
* This function should be called once at application startup,
|
|
6
|
+
* before any decorated controllers are loaded.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { defineConfig } from 'kontract'
|
|
11
|
+
*
|
|
12
|
+
* defineConfig({
|
|
13
|
+
* openapi: {
|
|
14
|
+
* info: {
|
|
15
|
+
* title: 'My API',
|
|
16
|
+
* version: '1.0.0',
|
|
17
|
+
* description: 'A great API',
|
|
18
|
+
* },
|
|
19
|
+
* servers: [
|
|
20
|
+
* { url: 'https://api.example.com', description: 'Production' },
|
|
21
|
+
* ],
|
|
22
|
+
* },
|
|
23
|
+
* runtime: {
|
|
24
|
+
* validateResponses: process.env.NODE_ENV !== 'production',
|
|
25
|
+
* validateRequests: true,
|
|
26
|
+
* },
|
|
27
|
+
* validator: myAjvValidator,
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function defineConfig(userConfig: UserConfig): OpenApiDecoratorConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Get the current configuration.
|
|
34
|
+
* @throws ConfigurationError if config hasn't been set
|
|
35
|
+
*/
|
|
36
|
+
export declare function getConfig(): OpenApiDecoratorConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Get the current configuration, or undefined if not set.
|
|
39
|
+
* Useful for checking if the library has been configured.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getConfigOrUndefined(): OpenApiDecoratorConfig | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Check if the library has been configured.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isConfigured(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Reset configuration (useful for testing).
|
|
48
|
+
*/
|
|
49
|
+
export declare function resetConfig(): void;
|
|
50
|
+
//# sourceMappingURL=define-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../../src/config/define-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAUpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,sBAAsB,CAW3E;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,sBAAsB,CAOlD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,sBAAsB,GAAG,SAAS,CAEzE;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAMlC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { mergeWithDefaults } from './defaults.js';
|
|
2
|
+
import { configureResponses } from '../response/helpers.js';
|
|
3
|
+
import { ConfigurationError } from '../errors/configuration.js';
|
|
4
|
+
/**
|
|
5
|
+
* Global configuration store.
|
|
6
|
+
*/
|
|
7
|
+
let globalConfig = null;
|
|
8
|
+
/**
|
|
9
|
+
* Define and register the OpenAPI decorator configuration.
|
|
10
|
+
*
|
|
11
|
+
* This function should be called once at application startup,
|
|
12
|
+
* before any decorated controllers are loaded.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { defineConfig } from 'kontract'
|
|
17
|
+
*
|
|
18
|
+
* defineConfig({
|
|
19
|
+
* openapi: {
|
|
20
|
+
* info: {
|
|
21
|
+
* title: 'My API',
|
|
22
|
+
* version: '1.0.0',
|
|
23
|
+
* description: 'A great API',
|
|
24
|
+
* },
|
|
25
|
+
* servers: [
|
|
26
|
+
* { url: 'https://api.example.com', description: 'Production' },
|
|
27
|
+
* ],
|
|
28
|
+
* },
|
|
29
|
+
* runtime: {
|
|
30
|
+
* validateResponses: process.env.NODE_ENV !== 'production',
|
|
31
|
+
* validateRequests: true,
|
|
32
|
+
* },
|
|
33
|
+
* validator: myAjvValidator,
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function defineConfig(userConfig) {
|
|
38
|
+
const config = mergeWithDefaults(userConfig);
|
|
39
|
+
// Configure response helpers with validation settings
|
|
40
|
+
configureResponses({
|
|
41
|
+
validateResponses: config.runtime.validateResponses ?? false,
|
|
42
|
+
validator: config.validator,
|
|
43
|
+
});
|
|
44
|
+
globalConfig = config;
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the current configuration.
|
|
49
|
+
* @throws ConfigurationError if config hasn't been set
|
|
50
|
+
*/
|
|
51
|
+
export function getConfig() {
|
|
52
|
+
if (!globalConfig) {
|
|
53
|
+
throw new ConfigurationError('Configuration not initialized. Call defineConfig() before using decorators.');
|
|
54
|
+
}
|
|
55
|
+
return globalConfig;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the current configuration, or undefined if not set.
|
|
59
|
+
* Useful for checking if the library has been configured.
|
|
60
|
+
*/
|
|
61
|
+
export function getConfigOrUndefined() {
|
|
62
|
+
return globalConfig ?? undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if the library has been configured.
|
|
66
|
+
*/
|
|
67
|
+
export function isConfigured() {
|
|
68
|
+
return globalConfig !== null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Reset configuration (useful for testing).
|
|
72
|
+
*/
|
|
73
|
+
export function resetConfig() {
|
|
74
|
+
globalConfig = null;
|
|
75
|
+
configureResponses({
|
|
76
|
+
validateResponses: false,
|
|
77
|
+
validator: undefined,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=define-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-config.js","sourceRoot":"","sources":["../../src/config/define-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAE/D;;GAEG;AACH,IAAI,YAAY,GAAkC,IAAI,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,YAAY,CAAC,UAAsB;IACjD,MAAM,MAAM,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAA;IAE5C,sDAAsD;IACtD,kBAAkB,CAAC;QACjB,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,IAAI,KAAK;QAC5D,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAC,CAAA;IAEF,YAAY,GAAG,MAAM,CAAA;IACrB,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS;IACvB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,CAC1B,6EAA6E,CAC9E,CAAA;IACH,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,YAAY,IAAI,SAAS,CAAA;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,YAAY,KAAK,IAAI,CAAA;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,YAAY,GAAG,IAAI,CAAA;IACnB,kBAAkB,CAAC;QACjB,iBAAiB,EAAE,KAAK;QACxB,SAAS,EAAE,SAAS;KACrB,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { OpenApiInfo, OpenApiServer, ValidatorFn, SerializerFn, SerializerRegistration, OpenApiDecoratorConfig, UserConfig, } from './types.js';
|
|
2
|
+
export { defaultRuntimeConfig, mergeWithDefaults } from './defaults.js';
|
|
3
|
+
export { defineConfig, getConfig, getConfigOrUndefined, isConfigured, resetConfig, } from './define-config.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,sBAAsB,EACtB,UAAU,GACX,MAAM,YAAY,CAAA;AAGnB,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGvE,OAAO,EACL,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,YAAY,EACZ,WAAW,GACZ,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAWA,WAAW;AACX,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAEvE,wBAAwB;AACxB,OAAO,EACL,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,YAAY,EACZ,WAAW,GACZ,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { TSchema } from '@sinclair/typebox';
|
|
2
|
+
import type { ValidationErrorDetail } from '../errors/validation.js';
|
|
3
|
+
/**
|
|
4
|
+
* OpenAPI document base information.
|
|
5
|
+
*/
|
|
6
|
+
export interface OpenApiInfo {
|
|
7
|
+
title: string;
|
|
8
|
+
version: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
termsOfService?: string;
|
|
11
|
+
contact?: {
|
|
12
|
+
name?: string;
|
|
13
|
+
url?: string;
|
|
14
|
+
email?: string;
|
|
15
|
+
};
|
|
16
|
+
license?: {
|
|
17
|
+
name: string;
|
|
18
|
+
url?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* OpenAPI server configuration.
|
|
23
|
+
*/
|
|
24
|
+
export interface OpenApiServer {
|
|
25
|
+
url: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validator function type.
|
|
30
|
+
* Should return validation errors or undefined/void if valid.
|
|
31
|
+
*/
|
|
32
|
+
export type ValidatorFn = (schema: TSchema, data: unknown) => ValidationErrorDetail[] | void;
|
|
33
|
+
/**
|
|
34
|
+
* Serializer function type.
|
|
35
|
+
* Transforms data before validation and response.
|
|
36
|
+
*/
|
|
37
|
+
export type SerializerFn<T = unknown> = (data: T) => unknown;
|
|
38
|
+
/**
|
|
39
|
+
* Serializer registration with type guard.
|
|
40
|
+
*/
|
|
41
|
+
export interface SerializerRegistration<T = unknown> {
|
|
42
|
+
/** Type guard to check if data should use this serializer */
|
|
43
|
+
check: (data: unknown) => data is T;
|
|
44
|
+
/** Serialization function */
|
|
45
|
+
serialize: SerializerFn<T>;
|
|
46
|
+
/** Optional priority (higher = checked first) */
|
|
47
|
+
priority?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Complete framework configuration.
|
|
51
|
+
*/
|
|
52
|
+
export interface OpenApiDecoratorConfig {
|
|
53
|
+
/**
|
|
54
|
+
* OpenAPI document information.
|
|
55
|
+
*/
|
|
56
|
+
openapi: {
|
|
57
|
+
info: OpenApiInfo;
|
|
58
|
+
servers?: OpenApiServer[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Runtime behavior options.
|
|
62
|
+
*/
|
|
63
|
+
runtime: {
|
|
64
|
+
/**
|
|
65
|
+
* Validate responses against schemas in development.
|
|
66
|
+
* Recommended: true in dev, false in production.
|
|
67
|
+
* @default false
|
|
68
|
+
*/
|
|
69
|
+
validateResponses?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Validate request body, query, and params.
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
validateRequests?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Strip unknown properties from request data.
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
stripUnknownProperties?: boolean;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Custom validator implementation.
|
|
83
|
+
* If not provided, responses won't be validated at runtime.
|
|
84
|
+
*/
|
|
85
|
+
validator?: ValidatorFn;
|
|
86
|
+
/**
|
|
87
|
+
* Custom serializers for transforming data before validation.
|
|
88
|
+
*/
|
|
89
|
+
serializers?: SerializerRegistration[];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Partial config for user input (most fields optional).
|
|
93
|
+
*/
|
|
94
|
+
export type UserConfig = {
|
|
95
|
+
openapi: {
|
|
96
|
+
info: OpenApiInfo;
|
|
97
|
+
servers?: OpenApiServer[];
|
|
98
|
+
};
|
|
99
|
+
runtime?: Partial<OpenApiDecoratorConfig['runtime']>;
|
|
100
|
+
validator?: ValidatorFn;
|
|
101
|
+
serializers?: SerializerRegistration[];
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAEpE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;IACD,OAAO,CAAC,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,CAAC,EAAE,MAAM,CAAA;KACb,CAAA;CACF;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,KAAK,qBAAqB,EAAE,GAAG,IAAI,CAAA;AAE5F;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAA;AAE5D;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,CAAC,GAAG,OAAO;IACjD,6DAA6D;IAC7D,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,IAAI,CAAC,CAAA;IACnC,6BAA6B;IAC7B,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;IAC1B,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,OAAO,EAAE;QACP,IAAI,EAAE,WAAW,CAAA;QACjB,OAAO,CAAC,EAAE,aAAa,EAAE,CAAA;KAC1B,CAAA;IAED;;OAEG;IACH,OAAO,EAAE;QACP;;;;WAIG;QACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;QAE3B;;;WAGG;QACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;QAE1B;;;WAGG;QACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;KACjC,CAAA;IAED;;;OAGG;IACH,SAAS,CAAC,EAAE,WAAW,CAAA;IAEvB;;OAEG;IACH,WAAW,CAAC,EAAE,sBAAsB,EAAE,CAAA;CACvC;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE;QACP,IAAI,EAAE,WAAW,CAAA;QACjB,OAAO,CAAC,EAAE,aAAa,EAAE,CAAA;KAC1B,CAAA;IACD,OAAO,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAA;IACpD,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,WAAW,CAAC,EAAE,sBAAsB,EAAE,CAAA;CACvC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the @Api class decorator.
|
|
3
|
+
*/
|
|
4
|
+
export interface ApiOptions {
|
|
5
|
+
/** OpenAPI tag for grouping endpoints */
|
|
6
|
+
tag: string;
|
|
7
|
+
/** Description of the API group */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Optional path prefix for all endpoints in this controller */
|
|
10
|
+
prefix?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Class decorator that marks a controller for OpenAPI documentation.
|
|
14
|
+
*
|
|
15
|
+
* The tag is used to group endpoints in the OpenAPI spec.
|
|
16
|
+
* The optional prefix is prepended to all endpoint paths in this controller.
|
|
17
|
+
*
|
|
18
|
+
* @example Basic usage
|
|
19
|
+
* ```typescript
|
|
20
|
+
* @Api({ tag: 'Users', description: 'User management endpoints' })
|
|
21
|
+
* export class UsersController {
|
|
22
|
+
* // endpoints...
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example With prefix
|
|
27
|
+
* ```typescript
|
|
28
|
+
* @Api({ tag: 'Admin', description: 'Admin endpoints', prefix: '/admin' })
|
|
29
|
+
* export class AdminController {
|
|
30
|
+
* // All endpoints in this controller will be prefixed with /admin
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function Api(options: ApiOptions): ClassDecorator;
|
|
35
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/decorators/api.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,yCAAyC;IACzC,GAAG,EAAE,MAAM,CAAA;IACX,mCAAmC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,cAAc,CASvD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { setApiMetadata } from '../metadata/storage.js';
|
|
2
|
+
/**
|
|
3
|
+
* Class decorator that marks a controller for OpenAPI documentation.
|
|
4
|
+
*
|
|
5
|
+
* The tag is used to group endpoints in the OpenAPI spec.
|
|
6
|
+
* The optional prefix is prepended to all endpoint paths in this controller.
|
|
7
|
+
*
|
|
8
|
+
* @example Basic usage
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Api({ tag: 'Users', description: 'User management endpoints' })
|
|
11
|
+
* export class UsersController {
|
|
12
|
+
* // endpoints...
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example With prefix
|
|
17
|
+
* ```typescript
|
|
18
|
+
* @Api({ tag: 'Admin', description: 'Admin endpoints', prefix: '/admin' })
|
|
19
|
+
* export class AdminController {
|
|
20
|
+
* // All endpoints in this controller will be prefixed with /admin
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function Api(options) {
|
|
25
|
+
return function (target) {
|
|
26
|
+
const metadata = {
|
|
27
|
+
tag: options.tag,
|
|
28
|
+
description: options.description,
|
|
29
|
+
prefix: options.prefix,
|
|
30
|
+
};
|
|
31
|
+
setApiMetadata(target, metadata);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/decorators/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAevD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,GAAG,CAAC,OAAmB;IACrC,OAAO,UAAU,MAAM;QACrB,MAAM,QAAQ,GAAgB;YAC5B,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAA;QACD,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IAClC,CAAC,CAAA;AACH,CAAC"}
|