@zenofolio/hyper-decor 1.0.4 → 1.0.8
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/.agent/rules/philosophy.md +103 -0
- package/.agent/rules/writing.md +32 -0
- package/README.md +107 -142
- package/dist/__internals/constants.d.ts +1 -58
- package/dist/__internals/constants.js +3 -65
- package/dist/__internals/helpers/lifecycle.helper.d.ts +3 -0
- package/dist/__internals/helpers/lifecycle.helper.js +25 -0
- package/dist/__internals/helpers/merge-metadata.d.ts +2 -3
- package/dist/__internals/helpers/merge-metadata.js +43 -23
- package/dist/__internals/helpers/prepare.helper.d.ts +5 -0
- package/dist/__internals/helpers/prepare.helper.js +392 -0
- package/dist/__internals/stores/hyper.store.d.ts +5 -0
- package/dist/__internals/stores/hyper.store.js +5 -0
- package/dist/__internals/stores/index.d.ts +4 -15
- package/dist/__internals/stores/index.js +18 -35
- package/dist/__internals/stores/meta.store.d.ts +34 -0
- package/dist/__internals/stores/meta.store.js +107 -0
- package/dist/__internals/stores/scope.store.d.ts +14 -0
- package/dist/__internals/stores/scope.store.js +29 -0
- package/dist/__internals/stores/serivces.store.d.ts +1 -0
- package/dist/__internals/stores/{store.interface.js → serivces.store.js} +2 -0
- package/dist/__internals/transform/middleware.transform.d.ts +3 -0
- package/dist/__internals/transform/middleware.transform.js +19 -0
- package/dist/__internals/transform/role.transform.d.ts +1 -1
- package/dist/__internals/transform/role.transform.js +10 -7
- package/dist/__internals/transform/scope.transfrom.d.ts +5 -7
- package/dist/__internals/transform/scope.transfrom.js +53 -39
- package/dist/__internals/transform/transform.registry.d.ts +33 -0
- package/dist/__internals/transform/transform.registry.js +59 -0
- package/dist/__internals/types.d.ts +53 -4
- package/dist/__internals/utils/function.util.d.ts +1 -4
- package/dist/__internals/utils/function.util.js +22 -10
- package/dist/common/bootstrap.d.ts +6 -2
- package/dist/common/bootstrap.js +51 -8
- package/dist/common/helpers/index.d.ts +1 -0
- package/dist/common/helpers/index.js +1 -0
- package/dist/common/helpers/scopes.d.ts +3 -3
- package/dist/common/helpers/scopes.js +7 -8
- package/dist/common/helpers/state.d.ts +17 -0
- package/dist/common/helpers/state.js +44 -0
- package/dist/common/message-bus.d.ts +11 -0
- package/dist/common/message-bus.js +51 -0
- package/dist/common/testing.d.ts +56 -0
- package/dist/common/testing.js +193 -0
- package/dist/common/transport.d.ts +10 -0
- package/dist/common/transport.js +59 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -1
- package/dist/decorators.d.ts +1 -0
- package/dist/{common/openapi/index.js → decorators.js} +1 -2
- package/dist/extension.js +11 -2
- package/dist/index.d.ts +11 -3
- package/dist/index.js +11 -3
- package/dist/lib/event/meta.store.d.ts +4 -0
- package/dist/lib/event/meta.store.js +5 -0
- package/dist/lib/openapi/collectors/class.collector.d.ts +5 -0
- package/dist/lib/openapi/collectors/class.collector.js +10 -0
- package/dist/lib/openapi/collectors/index.d.ts +3 -0
- package/dist/lib/openapi/collectors/index.js +19 -0
- package/dist/lib/openapi/collectors/method.collector.d.ts +7 -0
- package/dist/lib/openapi/collectors/method.collector.js +101 -0
- package/dist/lib/openapi/collectors/schema.collector.d.ts +6 -0
- package/dist/lib/openapi/collectors/schema.collector.js +29 -0
- package/dist/lib/openapi/constants.d.ts +47 -0
- package/dist/lib/openapi/constants.js +61 -0
- package/dist/lib/openapi/decorators.d.ts +16 -0
- package/dist/lib/openapi/decorators.js +93 -0
- package/dist/lib/openapi/index.d.ts +30 -0
- package/dist/lib/openapi/index.js +136 -0
- package/dist/lib/openapi/metadata.d.ts +7 -0
- package/dist/lib/openapi/metadata.js +8 -0
- package/dist/lib/openapi/metadata.registry.d.ts +29 -0
- package/dist/lib/openapi/metadata.registry.js +41 -0
- package/dist/lib/openapi/types.d.ts +131 -0
- package/dist/lib/server/decorators/File.d.ts +37 -0
- package/dist/{decorators → lib/server/decorators}/File.js +62 -75
- package/dist/lib/server/decorators/Http.d.ts +12 -0
- package/dist/lib/server/decorators/Http.js +56 -0
- package/dist/lib/server/decorators/HyperApp.d.ts +7 -0
- package/dist/lib/server/decorators/HyperApp.js +14 -0
- package/dist/lib/server/decorators/HyperController.d.ts +6 -0
- package/dist/lib/server/decorators/HyperController.js +15 -0
- package/dist/lib/server/decorators/HyperModule.d.ts +6 -0
- package/dist/lib/server/decorators/HyperModule.js +13 -0
- package/dist/lib/server/decorators/HyperService.d.ts +12 -0
- package/dist/lib/server/decorators/HyperService.js +30 -0
- package/dist/lib/server/decorators/Messaging.d.ts +8 -0
- package/dist/lib/server/decorators/Messaging.js +19 -0
- package/dist/lib/server/decorators/Middleware.d.ts +18 -0
- package/dist/lib/server/decorators/Middleware.js +52 -0
- package/dist/lib/server/decorators/Output.d.ts +6 -0
- package/dist/lib/server/decorators/Output.js +14 -0
- package/dist/lib/server/decorators/Pass.d.ts +10 -0
- package/dist/lib/server/decorators/Pass.js +13 -0
- package/dist/lib/server/decorators/Role.d.ts +7 -0
- package/dist/lib/server/decorators/Role.js +14 -0
- package/dist/lib/server/decorators/Routes.d.ts +14 -0
- package/dist/lib/server/decorators/Routes.js +39 -0
- package/dist/lib/server/decorators/Scope.d.ts +7 -0
- package/dist/lib/server/decorators/Scope.js +14 -0
- package/dist/{decorators → lib/server/decorators}/index.d.ts +9 -4
- package/dist/{decorators → lib/server/decorators}/index.js +9 -4
- package/dist/lib/server/decorators/metadata.d.ts +1 -0
- package/dist/lib/server/decorators/metadata.js +5 -0
- package/dist/lib/server/decorators/types.d.ts +125 -0
- package/dist/lib/server/decorators/types.js +6 -0
- package/dist/{exeptions → lib/server/exeptions}/HyperException.d.ts +2 -1
- package/dist/{exeptions → lib/server/exeptions}/HyperException.js +2 -1
- package/dist/{exeptions → lib/server/exeptions}/HyperFileException.js +1 -1
- package/dist/{exeptions → lib/server/exeptions}/NotRoleException.js +1 -1
- package/dist/{exeptions → lib/server/exeptions}/NotScopeException.js +1 -1
- package/dist/lib/tree/tree.d.ts +36 -0
- package/dist/lib/tree/tree.js +106 -0
- package/dist/type.d.ts +13 -2
- package/hyper-express-decorators.d.ts +1 -0
- package/package.json +81 -60
- package/scripts/clean.js +56 -0
- package/scripts/test-server.ts +85 -0
- package/tsconfig.json +18 -13
- package/vitest.config.mjs +30 -0
- package/.mocharc.js +0 -5
- package/dist/__internals/creators/request.creator.d.ts +0 -12
- package/dist/__internals/creators/request.creator.js +0 -53
- package/dist/__internals/creators/routes.creator.d.ts +0 -10
- package/dist/__internals/creators/routes.creator.js +0 -37
- package/dist/__internals/decorator-base.d.ts +0 -30
- package/dist/__internals/decorator-base.js +0 -86
- package/dist/__internals/store.d.ts +0 -10
- package/dist/__internals/store.js +0 -17
- package/dist/__internals/stores/middleware.store.d.ts +0 -7
- package/dist/__internals/stores/middleware.store.js +0 -19
- package/dist/__internals/stores/params.store.d.ts +0 -21
- package/dist/__internals/stores/params.store.js +0 -65
- package/dist/__internals/stores/routes.store.d.ts +0 -17
- package/dist/__internals/stores/routes.store.js +0 -43
- package/dist/__internals/stores/store.interface.d.ts +0 -8
- package/dist/__internals/transform/method.transform.d.ts +0 -2
- package/dist/__internals/transform/method.transform.js +0 -20
- package/dist/__internals/transform/pass.transfrom.d.ts +0 -1
- package/dist/__internals/transform/pass.transfrom.js +0 -2
- package/dist/__internals/utils/mixin.utils.d.ts +0 -11
- package/dist/__internals/utils/mixin.utils.js +0 -34
- package/dist/__internals/utils/router.d.ts +0 -1
- package/dist/__internals/utils/router.js +0 -2
- package/dist/common/openapi/collect-class-data.d.ts +0 -21
- package/dist/common/openapi/collect-class-data.js +0 -45
- package/dist/common/openapi/collect-function-data.d.ts +0 -32
- package/dist/common/openapi/collect-function-data.js +0 -70
- package/dist/common/openapi/index.d.ts +0 -2
- package/dist/decorators/File.d.ts +0 -65
- package/dist/decorators/Http.d.ts +0 -55
- package/dist/decorators/Http.js +0 -93
- package/dist/decorators/HyperApp.d.ts +0 -7
- package/dist/decorators/HyperApp.js +0 -262
- package/dist/decorators/HyperController.d.ts +0 -2
- package/dist/decorators/HyperController.js +0 -19
- package/dist/decorators/HyperModule.d.ts +0 -5
- package/dist/decorators/HyperModule.js +0 -14
- package/dist/decorators/Middleware.d.ts +0 -24
- package/dist/decorators/Middleware.js +0 -51
- package/dist/decorators/Pass.d.ts +0 -12
- package/dist/decorators/Pass.js +0 -29
- package/dist/decorators/Role.d.ts +0 -6
- package/dist/decorators/Role.js +0 -34
- package/dist/decorators/Routes.d.ts +0 -14
- package/dist/decorators/Routes.js +0 -21
- package/dist/decorators/Scope.d.ts +0 -6
- package/dist/decorators/Scope.js +0 -25
- package/dist/decorators/types.d.ts +0 -89
- /package/dist/{decorators → lib/openapi}/types.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicateControllerPathException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicateControllerPathException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicatedException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicatedException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicatedHandlerException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicatedHandlerException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/HyperFileException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/MethodNotFountException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/MethodNotFountException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/NotPropertyException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/NotPropertyException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/NotRoleException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/NotScopeException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/WrongPlaceException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/WrongPlaceException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/index.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/index.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/types.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/types.js +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectMethodMetadata = collectMethodMetadata;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const metadata_1 = require("../metadata");
|
|
6
|
+
const metadata_2 = require("../../server/decorators/metadata");
|
|
7
|
+
const transform_registry_1 = require("../../../__internals/transform/transform.registry");
|
|
8
|
+
const constants_1 = require("../../../__internals/constants");
|
|
9
|
+
const schema_collector_1 = require("./schema.collector");
|
|
10
|
+
/**
|
|
11
|
+
* 🛠️ Consolidates framework metadata and OpenAPI decorators into a single Operation object.
|
|
12
|
+
*/
|
|
13
|
+
function collectMethodMetadata(target, propertyKey) {
|
|
14
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
15
|
+
if (!propertyKey)
|
|
16
|
+
return undefined;
|
|
17
|
+
// 1. Get user-defined OpenAPI metadata from decorators
|
|
18
|
+
const baseOperation = metadata_1.SwaggerMeta.get(target, propertyKey);
|
|
19
|
+
// 2. Get framework metadata (params, route, etc.)
|
|
20
|
+
const hyperMeta = metadata_2.HyperMeta.get(target, propertyKey);
|
|
21
|
+
const operation = Object.assign(Object.assign({}, baseOperation), { parameters: [...(baseOperation.parameters || [])], responses: Object.assign({}, (baseOperation.responses || {})) });
|
|
22
|
+
// 3. Bridge Parameters (@Query, @Param, @Headers)
|
|
23
|
+
if ((_a = hyperMeta.params) === null || _a === void 0 ? void 0 : _a.params) {
|
|
24
|
+
hyperMeta.params.params.forEach((param) => {
|
|
25
|
+
const inType = mapParamIn(param.decorator);
|
|
26
|
+
if (!inType)
|
|
27
|
+
return; // Skip 'body' or unknown
|
|
28
|
+
const name = param.picker || param.name || param.decorator || 'param';
|
|
29
|
+
const schema = param.schema
|
|
30
|
+
? (transform_registry_1.transformRegistry.getOpenApiSchema(param.schema) || (0, schema_collector_1.collectSchema)(param.schema))
|
|
31
|
+
: { type: 'string' };
|
|
32
|
+
// If it's an object, we might want to explode it (if it's Query/Headers)
|
|
33
|
+
// Or if it's a DTO (whole source)
|
|
34
|
+
if (schema.type === 'object' && schema.properties && (inType === 'query' || inType === 'header')) {
|
|
35
|
+
Object.entries(schema.properties).forEach(([propName, prop]) => {
|
|
36
|
+
operation.parameters.push({
|
|
37
|
+
name: propName,
|
|
38
|
+
in: inType,
|
|
39
|
+
required: true,
|
|
40
|
+
schema: prop
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
operation.parameters.push({
|
|
46
|
+
name,
|
|
47
|
+
in: inType,
|
|
48
|
+
required: inType === 'path' ? true : undefined,
|
|
49
|
+
schema
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// 4. Bridge Request Body (@Body)
|
|
55
|
+
const bodyParam = (_c = (_b = hyperMeta.params) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.find((p) => p.decorator === 'Body');
|
|
56
|
+
if (bodyParam && !operation.requestBody) {
|
|
57
|
+
let schema = bodyParam.schema
|
|
58
|
+
? (transform_registry_1.transformRegistry.getOpenApiSchema(bodyParam.schema) || (0, schema_collector_1.collectSchema)(bodyParam.schema))
|
|
59
|
+
: { type: 'object' };
|
|
60
|
+
// If a specific picker was requested, wrap the schema in an object
|
|
61
|
+
if (bodyParam.picker && bodyParam.picker !== 'body') {
|
|
62
|
+
schema = {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
[bodyParam.picker]: schema
|
|
66
|
+
},
|
|
67
|
+
required: [bodyParam.picker]
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
operation.requestBody = {
|
|
71
|
+
content: {
|
|
72
|
+
"application/json": { schema }
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// 5. Bridge Responses (@Output)
|
|
77
|
+
const outputSchema = ((_g = (_f = (_e = (_d = baseOperation.responses) === null || _d === void 0 ? void 0 : _d["200"]) === null || _e === void 0 ? void 0 : _e.content) === null || _f === void 0 ? void 0 : _f["application/json"]) === null || _g === void 0 ? void 0 : _g.schema)
|
|
78
|
+
|| hyperMeta[constants_1.KEY_OUTPUT_SCHEMA]
|
|
79
|
+
|| hyperMeta.output;
|
|
80
|
+
if (outputSchema && !operation.responses["200"]) {
|
|
81
|
+
const schema = transform_registry_1.transformRegistry.getOpenApiSchema(outputSchema) || (0, schema_collector_1.collectSchema)(outputSchema);
|
|
82
|
+
operation.responses["200"] = {
|
|
83
|
+
description: "OK",
|
|
84
|
+
content: {
|
|
85
|
+
"application/json": { schema }
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
else if (Object.keys(operation.responses).length === 0) {
|
|
90
|
+
operation.responses["200"] = { description: "OK" };
|
|
91
|
+
}
|
|
92
|
+
return operation;
|
|
93
|
+
}
|
|
94
|
+
function mapParamIn(decorator) {
|
|
95
|
+
switch (decorator.toLowerCase()) {
|
|
96
|
+
case 'query': return 'query';
|
|
97
|
+
case 'param': return 'path';
|
|
98
|
+
case 'headers': return 'header';
|
|
99
|
+
default: return undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectSchema = collectSchema;
|
|
4
|
+
/**
|
|
5
|
+
* 🔍 Extracts a basic OpenAPI schema from a DTO class.
|
|
6
|
+
* This is a fallback when no specific transformer (Zod, etc.) is registered.
|
|
7
|
+
*/
|
|
8
|
+
function collectSchema(Target) {
|
|
9
|
+
if (typeof Target !== 'function') {
|
|
10
|
+
return { type: 'string' };
|
|
11
|
+
}
|
|
12
|
+
const schema = {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {},
|
|
15
|
+
};
|
|
16
|
+
// Note: Standard TS reflection doesn't expose fields without decorators.
|
|
17
|
+
// However, we can try to instantiate or use metadata if available.
|
|
18
|
+
// For now, we provide a placeholder that can be extended.
|
|
19
|
+
// If it's a primitive constructor
|
|
20
|
+
if (Target === String)
|
|
21
|
+
return { type: 'string' };
|
|
22
|
+
if (Target === Number)
|
|
23
|
+
return { type: 'number' };
|
|
24
|
+
if (Target === Boolean)
|
|
25
|
+
return { type: 'boolean' };
|
|
26
|
+
if (Target === Date)
|
|
27
|
+
return { type: 'string', format: 'date-time' };
|
|
28
|
+
return schema;
|
|
29
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare const KEY_OPENAPI = "hyper:openapi";
|
|
2
|
+
export declare const OPENAPI_VERSION = "3.0.0";
|
|
3
|
+
export declare const INFO_TITLE = "openapi:info:title";
|
|
4
|
+
export declare const INFO_DESCRIPTION = "openapi:info:description";
|
|
5
|
+
export declare const INFO_VERSION = "openapi:info:version";
|
|
6
|
+
export declare const INFO_TERMS_OF_SERVICE = "openapi:info:termsOfService";
|
|
7
|
+
export declare const INFO_CONTACT = "openapi:info:contact";
|
|
8
|
+
export declare const INFO_LICENSE = "openapi:info:license";
|
|
9
|
+
export declare const PATHS = "openapi:paths";
|
|
10
|
+
export declare const METHOD_GET = "openapi:method:get";
|
|
11
|
+
export declare const METHOD_POST = "openapi:method:post";
|
|
12
|
+
export declare const METHOD_PUT = "openapi:method:put";
|
|
13
|
+
export declare const METHOD_DELETE = "openapi:method:delete";
|
|
14
|
+
export declare const METHOD_PATCH = "openapi:method:patch";
|
|
15
|
+
export declare const METHOD_HEAD = "openapi:method:head";
|
|
16
|
+
export declare const METHOD_OPTIONS = "openapi:method:options";
|
|
17
|
+
export declare const METHOD_TRACE = "openapi:method:trace";
|
|
18
|
+
export declare const PARAMETERS = "openapi:parameters";
|
|
19
|
+
export declare const PARAM_NAME = "openapi:parameter:name";
|
|
20
|
+
export declare const PARAM_IN = "openapi:parameter:in";
|
|
21
|
+
export declare const PARAM_REQUIRED = "openapi:parameter:required";
|
|
22
|
+
export declare const PARAM_DESCRIPTION = "openapi:parameter:description";
|
|
23
|
+
export declare const PARAM_SCHEMA = "openapi:parameter:schema";
|
|
24
|
+
export declare const REQUEST_BODY = "openapi:requestBody";
|
|
25
|
+
export declare const REQUEST_BODY_DESCRIPTION = "openapi:requestBody:description";
|
|
26
|
+
export declare const REQUEST_BODY_CONTENT = "openapi:requestBody:content";
|
|
27
|
+
export declare const RESPONSES = "openapi:responses";
|
|
28
|
+
export declare const RESPONSE_DESCRIPTION = "openapi:response:description";
|
|
29
|
+
export declare const RESPONSE_CONTENT = "openapi:response:content";
|
|
30
|
+
export declare const RESPONSE_SCHEMA = "openapi:response:schema";
|
|
31
|
+
export declare const SECURITY = "openapi:security";
|
|
32
|
+
export declare const SECURITY_SCHEME = "openapi:security:scheme";
|
|
33
|
+
export declare const TAGS = "openapi:tags";
|
|
34
|
+
export declare const TAG_NAME = "openapi:tag:name";
|
|
35
|
+
export declare const TAG_DESCRIPTION = "openapi:tag:description";
|
|
36
|
+
export declare const METHOD_METADATA = "openapi:method:metadata";
|
|
37
|
+
export declare const METHOD_SUMMARY = "openapi:method:summary";
|
|
38
|
+
export declare const METHOD_OPERATION_ID = "openapi:method:operationId";
|
|
39
|
+
export declare const METHOD_TAGS = "openapi:method:tags";
|
|
40
|
+
export declare const COMPONENTS = "openapi:components";
|
|
41
|
+
export declare const COMPONENTS_SCHEMAS = "openapi:components:schemas";
|
|
42
|
+
export declare const COMPONENTS_RESPONSES = "openapi:components:responses";
|
|
43
|
+
export declare const COMPONENTS_PARAMETERS = "openapi:components:parameters";
|
|
44
|
+
export declare const COMPONENTS_SECURITY_SCHEMES = "openapi:components:securitySchemes";
|
|
45
|
+
export declare const SECURITY_API_KEY = "openapi:security:apiKey";
|
|
46
|
+
export declare const SECURITY_OAUTH2 = "openapi:security:oauth2";
|
|
47
|
+
export declare const SECURITY_OIDC = "openapi:security:oidc";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SECURITY_OIDC = exports.SECURITY_OAUTH2 = exports.SECURITY_API_KEY = exports.COMPONENTS_SECURITY_SCHEMES = exports.COMPONENTS_PARAMETERS = exports.COMPONENTS_RESPONSES = exports.COMPONENTS_SCHEMAS = exports.COMPONENTS = exports.METHOD_TAGS = exports.METHOD_OPERATION_ID = exports.METHOD_SUMMARY = exports.METHOD_METADATA = exports.TAG_DESCRIPTION = exports.TAG_NAME = exports.TAGS = exports.SECURITY_SCHEME = exports.SECURITY = exports.RESPONSE_SCHEMA = exports.RESPONSE_CONTENT = exports.RESPONSE_DESCRIPTION = exports.RESPONSES = exports.REQUEST_BODY_CONTENT = exports.REQUEST_BODY_DESCRIPTION = exports.REQUEST_BODY = exports.PARAM_SCHEMA = exports.PARAM_DESCRIPTION = exports.PARAM_REQUIRED = exports.PARAM_IN = exports.PARAM_NAME = exports.PARAMETERS = exports.METHOD_TRACE = exports.METHOD_OPTIONS = exports.METHOD_HEAD = exports.METHOD_PATCH = exports.METHOD_DELETE = exports.METHOD_PUT = exports.METHOD_POST = exports.METHOD_GET = exports.PATHS = exports.INFO_LICENSE = exports.INFO_CONTACT = exports.INFO_TERMS_OF_SERVICE = exports.INFO_VERSION = exports.INFO_DESCRIPTION = exports.INFO_TITLE = exports.OPENAPI_VERSION = exports.KEY_OPENAPI = void 0;
|
|
4
|
+
exports.KEY_OPENAPI = "hyper:openapi";
|
|
5
|
+
// OpenAPI Version
|
|
6
|
+
exports.OPENAPI_VERSION = "3.0.0";
|
|
7
|
+
// Info Metadata (Información general sobre la API)
|
|
8
|
+
exports.INFO_TITLE = "openapi:info:title";
|
|
9
|
+
exports.INFO_DESCRIPTION = "openapi:info:description";
|
|
10
|
+
exports.INFO_VERSION = "openapi:info:version";
|
|
11
|
+
exports.INFO_TERMS_OF_SERVICE = "openapi:info:termsOfService";
|
|
12
|
+
exports.INFO_CONTACT = "openapi:info:contact";
|
|
13
|
+
exports.INFO_LICENSE = "openapi:info:license";
|
|
14
|
+
// Paths (Rutas de la API)
|
|
15
|
+
exports.PATHS = "openapi:paths";
|
|
16
|
+
exports.METHOD_GET = "openapi:method:get";
|
|
17
|
+
exports.METHOD_POST = "openapi:method:post";
|
|
18
|
+
exports.METHOD_PUT = "openapi:method:put";
|
|
19
|
+
exports.METHOD_DELETE = "openapi:method:delete";
|
|
20
|
+
exports.METHOD_PATCH = "openapi:method:patch";
|
|
21
|
+
exports.METHOD_HEAD = "openapi:method:head";
|
|
22
|
+
exports.METHOD_OPTIONS = "openapi:method:options";
|
|
23
|
+
exports.METHOD_TRACE = "openapi:method:trace";
|
|
24
|
+
// Parameters (Parámetros de los métodos)
|
|
25
|
+
exports.PARAMETERS = "openapi:parameters";
|
|
26
|
+
exports.PARAM_NAME = "openapi:parameter:name";
|
|
27
|
+
exports.PARAM_IN = "openapi:parameter:in"; // query, header, path, cookie
|
|
28
|
+
exports.PARAM_REQUIRED = "openapi:parameter:required";
|
|
29
|
+
exports.PARAM_DESCRIPTION = "openapi:parameter:description";
|
|
30
|
+
exports.PARAM_SCHEMA = "openapi:parameter:schema";
|
|
31
|
+
// RequestBody (Cuerpo de la solicitud)
|
|
32
|
+
exports.REQUEST_BODY = "openapi:requestBody";
|
|
33
|
+
exports.REQUEST_BODY_DESCRIPTION = "openapi:requestBody:description";
|
|
34
|
+
exports.REQUEST_BODY_CONTENT = "openapi:requestBody:content";
|
|
35
|
+
// Responses (Respuestas de los métodos)
|
|
36
|
+
exports.RESPONSES = "openapi:responses";
|
|
37
|
+
exports.RESPONSE_DESCRIPTION = "openapi:response:description";
|
|
38
|
+
exports.RESPONSE_CONTENT = "openapi:response:content";
|
|
39
|
+
exports.RESPONSE_SCHEMA = "openapi:response:schema";
|
|
40
|
+
// Security (Esquemas de seguridad)
|
|
41
|
+
exports.SECURITY = "openapi:security";
|
|
42
|
+
exports.SECURITY_SCHEME = "openapi:security:scheme"; // Esquemas de seguridad como apiKey, oauth2, etc.
|
|
43
|
+
// Tags (Etiquetas de los métodos)
|
|
44
|
+
exports.TAGS = "openapi:tags";
|
|
45
|
+
exports.TAG_NAME = "openapi:tag:name";
|
|
46
|
+
exports.TAG_DESCRIPTION = "openapi:tag:description";
|
|
47
|
+
// Method Metadata (Metadatos adicionales de los métodos)
|
|
48
|
+
exports.METHOD_METADATA = "openapi:method:metadata";
|
|
49
|
+
exports.METHOD_SUMMARY = "openapi:method:summary";
|
|
50
|
+
exports.METHOD_OPERATION_ID = "openapi:method:operationId";
|
|
51
|
+
exports.METHOD_TAGS = "openapi:method:tags";
|
|
52
|
+
// Components (Componentes reutilizables)
|
|
53
|
+
exports.COMPONENTS = "openapi:components";
|
|
54
|
+
exports.COMPONENTS_SCHEMAS = "openapi:components:schemas"; // Esquemas reutilizables de parámetros y respuestas
|
|
55
|
+
exports.COMPONENTS_RESPONSES = "openapi:components:responses"; // Respuestas reutilizables
|
|
56
|
+
exports.COMPONENTS_PARAMETERS = "openapi:components:parameters"; // Parámetros reutilizables
|
|
57
|
+
exports.COMPONENTS_SECURITY_SCHEMES = "openapi:components:securitySchemes"; // Esquemas de seguridad reutilizables
|
|
58
|
+
// Security Schemes (Esquemas de seguridad)
|
|
59
|
+
exports.SECURITY_API_KEY = "openapi:security:apiKey";
|
|
60
|
+
exports.SECURITY_OAUTH2 = "openapi:security:oauth2";
|
|
61
|
+
exports.SECURITY_OIDC = "openapi:security:oidc"; // OpenID Connect
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Tag, OpenApiResponses, OpenApiParameter, RequestBody, SecurityRequirement, Operation } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* 📝 OpenAPI Decorators consolidated for better performance and clean imports.
|
|
4
|
+
*/
|
|
5
|
+
export declare function ApiSummary(summary: string): (target: any, propertyKey: any) => void;
|
|
6
|
+
export declare function ApiDescription(description: string): (target: any, propertyKey: any) => void;
|
|
7
|
+
export declare function ApiOperationId(operationId: string): (target: any, propertyKey: any) => void;
|
|
8
|
+
export declare function ApiTag(options: Tag | string): (target: any, propertyKey?: any) => void;
|
|
9
|
+
export declare function ApiResponse(options: OpenApiResponses): (target: any, propertyKey?: any) => void;
|
|
10
|
+
export declare function ApiParameter(options: OpenApiParameter): (target: any, propertyKey: any) => void;
|
|
11
|
+
export declare function ApiRequestBody(options: RequestBody): (target: any, propertyKey: any) => void;
|
|
12
|
+
export declare function ApiSecurity(options: SecurityRequirement): (target: any, propertyKey?: any) => void;
|
|
13
|
+
export declare function ApiBearerAuth(name?: string): (target: any, propertyKey?: any) => void;
|
|
14
|
+
export declare function ApiMethod(options: Partial<Operation>): (target: any, propertyKey: any) => void;
|
|
15
|
+
export declare function ApiNamespace(name: string): (target: any, propertyKey?: any) => void;
|
|
16
|
+
export declare function ApiIgnore(): (target: any, propertyKey?: any) => void;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiSummary = ApiSummary;
|
|
4
|
+
exports.ApiDescription = ApiDescription;
|
|
5
|
+
exports.ApiOperationId = ApiOperationId;
|
|
6
|
+
exports.ApiTag = ApiTag;
|
|
7
|
+
exports.ApiResponse = ApiResponse;
|
|
8
|
+
exports.ApiParameter = ApiParameter;
|
|
9
|
+
exports.ApiRequestBody = ApiRequestBody;
|
|
10
|
+
exports.ApiSecurity = ApiSecurity;
|
|
11
|
+
exports.ApiBearerAuth = ApiBearerAuth;
|
|
12
|
+
exports.ApiMethod = ApiMethod;
|
|
13
|
+
exports.ApiNamespace = ApiNamespace;
|
|
14
|
+
exports.ApiIgnore = ApiIgnore;
|
|
15
|
+
const metadata_1 = require("./metadata");
|
|
16
|
+
/**
|
|
17
|
+
* 📝 OpenAPI Decorators consolidated for better performance and clean imports.
|
|
18
|
+
*/
|
|
19
|
+
function ApiSummary(summary) {
|
|
20
|
+
return (target, propertyKey) => {
|
|
21
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, { summary });
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function ApiDescription(description) {
|
|
25
|
+
return (target, propertyKey) => {
|
|
26
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, { description });
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function ApiOperationId(operationId) {
|
|
30
|
+
return (target, propertyKey) => {
|
|
31
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, { operationId });
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function ApiTag(options) {
|
|
35
|
+
const tag = typeof options === 'string' ? { name: options } : options;
|
|
36
|
+
return (target, propertyKey) => {
|
|
37
|
+
if (propertyKey) {
|
|
38
|
+
const current = metadata_1.SwaggerMeta.get(target, propertyKey);
|
|
39
|
+
const tags = [...(current.tags || []), tag];
|
|
40
|
+
// Use Map to deduplicate by name
|
|
41
|
+
const uniqueTags = Array.from(new Map(tags.map(t => [t.name, t])).values());
|
|
42
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, { tags: uniqueTags });
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const current = metadata_1.SwaggerMeta.get(target);
|
|
46
|
+
const tags = [...(current.tags || []), tag];
|
|
47
|
+
const uniqueTags = Array.from(new Map(tags.map(t => [t.name, t])).values());
|
|
48
|
+
metadata_1.SwaggerMeta.set(target, undefined, { tags: uniqueTags });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function ApiResponse(options) {
|
|
53
|
+
return (target, propertyKey) => {
|
|
54
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, { responses: options });
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function ApiParameter(options) {
|
|
58
|
+
return (target, propertyKey) => {
|
|
59
|
+
const current = metadata_1.SwaggerMeta.get(target, propertyKey);
|
|
60
|
+
const parameters = [...(current.parameters || []), options];
|
|
61
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, { parameters });
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function ApiRequestBody(options) {
|
|
65
|
+
return (target, propertyKey) => {
|
|
66
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, { requestBody: options });
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function ApiSecurity(options) {
|
|
70
|
+
return (target, propertyKey) => {
|
|
71
|
+
const current = metadata_1.SwaggerMeta.get(target, propertyKey);
|
|
72
|
+
const security = [...(current.security || []), options];
|
|
73
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, { security });
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function ApiBearerAuth(name = 'bearerAuth') {
|
|
77
|
+
return ApiSecurity({ [name]: [] });
|
|
78
|
+
}
|
|
79
|
+
function ApiMethod(options) {
|
|
80
|
+
return (target, propertyKey) => {
|
|
81
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, options);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function ApiNamespace(name) {
|
|
85
|
+
return (target, propertyKey) => {
|
|
86
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, { namespace: name });
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function ApiIgnore() {
|
|
90
|
+
return (target, propertyKey) => {
|
|
91
|
+
metadata_1.SwaggerMeta.set(target, propertyKey, { ignore: true });
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
import { ApiBearerAuth, ApiDescription, ApiOperationId, ApiParameter, ApiRequestBody, ApiResponse, ApiSecurity, ApiSummary, ApiTag, ApiMethod, ApiNamespace, ApiIgnore } from "./decorators";
|
|
3
|
+
export declare const OpenApi: {
|
|
4
|
+
Summary: typeof ApiSummary;
|
|
5
|
+
Description: typeof ApiDescription;
|
|
6
|
+
OperationId: typeof ApiOperationId;
|
|
7
|
+
Tag: typeof ApiTag;
|
|
8
|
+
Response: typeof ApiResponse;
|
|
9
|
+
Parameter: typeof ApiParameter;
|
|
10
|
+
RequestBody: typeof ApiRequestBody;
|
|
11
|
+
Security: typeof ApiSecurity;
|
|
12
|
+
BearerAuth: typeof ApiBearerAuth;
|
|
13
|
+
Method: typeof ApiMethod;
|
|
14
|
+
Namespace: typeof ApiNamespace;
|
|
15
|
+
Ignore: typeof ApiIgnore;
|
|
16
|
+
};
|
|
17
|
+
export { ApiBearerAuth, ApiDescription, ApiOperationId, ApiParameter, ApiRequestBody, ApiResponse, ApiSecurity, ApiSummary, ApiTag, ApiMethod, ApiNamespace, ApiIgnore, };
|
|
18
|
+
import { Constructor } from "../server/decorators/types";
|
|
19
|
+
import { OpenAPIDocument } from "./types";
|
|
20
|
+
/**
|
|
21
|
+
* Generates an OpenAPI specification object from a HyperApp class.
|
|
22
|
+
*
|
|
23
|
+
* @param App The Root Application Class
|
|
24
|
+
* @param options Generator options
|
|
25
|
+
* @returns OpenAPI Spec Object
|
|
26
|
+
*/
|
|
27
|
+
export declare function getOpenAPI(App: Constructor, options?: {
|
|
28
|
+
includeNamespaces?: string[];
|
|
29
|
+
excludeNamespaces?: string[];
|
|
30
|
+
}): OpenAPIDocument;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ApiIgnore = exports.ApiNamespace = exports.ApiMethod = exports.ApiTag = exports.ApiSummary = exports.ApiSecurity = exports.ApiResponse = exports.ApiRequestBody = exports.ApiParameter = exports.ApiOperationId = exports.ApiDescription = exports.ApiBearerAuth = exports.OpenApi = void 0;
|
|
18
|
+
exports.getOpenAPI = getOpenAPI;
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
const decorators_1 = require("./decorators");
|
|
21
|
+
Object.defineProperty(exports, "ApiBearerAuth", { enumerable: true, get: function () { return decorators_1.ApiBearerAuth; } });
|
|
22
|
+
Object.defineProperty(exports, "ApiDescription", { enumerable: true, get: function () { return decorators_1.ApiDescription; } });
|
|
23
|
+
Object.defineProperty(exports, "ApiOperationId", { enumerable: true, get: function () { return decorators_1.ApiOperationId; } });
|
|
24
|
+
Object.defineProperty(exports, "ApiParameter", { enumerable: true, get: function () { return decorators_1.ApiParameter; } });
|
|
25
|
+
Object.defineProperty(exports, "ApiRequestBody", { enumerable: true, get: function () { return decorators_1.ApiRequestBody; } });
|
|
26
|
+
Object.defineProperty(exports, "ApiResponse", { enumerable: true, get: function () { return decorators_1.ApiResponse; } });
|
|
27
|
+
Object.defineProperty(exports, "ApiSecurity", { enumerable: true, get: function () { return decorators_1.ApiSecurity; } });
|
|
28
|
+
Object.defineProperty(exports, "ApiSummary", { enumerable: true, get: function () { return decorators_1.ApiSummary; } });
|
|
29
|
+
Object.defineProperty(exports, "ApiTag", { enumerable: true, get: function () { return decorators_1.ApiTag; } });
|
|
30
|
+
Object.defineProperty(exports, "ApiMethod", { enumerable: true, get: function () { return decorators_1.ApiMethod; } });
|
|
31
|
+
Object.defineProperty(exports, "ApiNamespace", { enumerable: true, get: function () { return decorators_1.ApiNamespace; } });
|
|
32
|
+
Object.defineProperty(exports, "ApiIgnore", { enumerable: true, get: function () { return decorators_1.ApiIgnore; } });
|
|
33
|
+
exports.OpenApi = {
|
|
34
|
+
Summary: decorators_1.ApiSummary,
|
|
35
|
+
Description: decorators_1.ApiDescription,
|
|
36
|
+
OperationId: decorators_1.ApiOperationId,
|
|
37
|
+
Tag: decorators_1.ApiTag,
|
|
38
|
+
Response: decorators_1.ApiResponse,
|
|
39
|
+
Parameter: decorators_1.ApiParameter,
|
|
40
|
+
RequestBody: decorators_1.ApiRequestBody,
|
|
41
|
+
Security: decorators_1.ApiSecurity,
|
|
42
|
+
BearerAuth: decorators_1.ApiBearerAuth,
|
|
43
|
+
Method: decorators_1.ApiMethod,
|
|
44
|
+
Namespace: decorators_1.ApiNamespace,
|
|
45
|
+
Ignore: decorators_1.ApiIgnore,
|
|
46
|
+
};
|
|
47
|
+
const tree_1 = require("../tree/tree");
|
|
48
|
+
const metadata_registry_1 = require("./metadata.registry");
|
|
49
|
+
// --- Registration ---
|
|
50
|
+
const collectors_1 = require("./collectors");
|
|
51
|
+
metadata_registry_1.openApiRegistry.registerCollector("class", collectors_1.collectClassMetadata);
|
|
52
|
+
metadata_registry_1.openApiRegistry.registerCollector("method", collectors_1.collectMethodMetadata);
|
|
53
|
+
/**
|
|
54
|
+
* Generates an OpenAPI specification object from a HyperApp class.
|
|
55
|
+
*
|
|
56
|
+
* @param App The Root Application Class
|
|
57
|
+
* @param options Generator options
|
|
58
|
+
* @returns OpenAPI Spec Object
|
|
59
|
+
*/
|
|
60
|
+
function getOpenAPI(App, options = {}) {
|
|
61
|
+
const tree = (0, tree_1.getAppTree)(App);
|
|
62
|
+
const spec = {
|
|
63
|
+
openapi: "3.0.0",
|
|
64
|
+
info: {
|
|
65
|
+
title: tree.app.name || "HyperApp API",
|
|
66
|
+
version: tree.app.version || "1.0.0",
|
|
67
|
+
},
|
|
68
|
+
paths: {},
|
|
69
|
+
};
|
|
70
|
+
const processController = (ctrl, parentNamespace) => {
|
|
71
|
+
const ctrlOpenApi = ctrl.openapi;
|
|
72
|
+
if (ctrlOpenApi === null || ctrlOpenApi === void 0 ? void 0 : ctrlOpenApi.ignore)
|
|
73
|
+
return;
|
|
74
|
+
const ctrlNamespace = (ctrlOpenApi === null || ctrlOpenApi === void 0 ? void 0 : ctrlOpenApi.namespace) || parentNamespace;
|
|
75
|
+
ctrl.routes.forEach((route) => {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
const routeOpenApi = route.openapi;
|
|
78
|
+
if (!routeOpenApi || routeOpenApi.ignore)
|
|
79
|
+
return;
|
|
80
|
+
const path = normalizePath(route.fullPath);
|
|
81
|
+
if (!spec.paths[path])
|
|
82
|
+
spec.paths[path] = {};
|
|
83
|
+
const methodNamespace = routeOpenApi.namespace || ctrlNamespace;
|
|
84
|
+
// Filtering logic
|
|
85
|
+
if (options.includeNamespaces && options.includeNamespaces.length > 0) {
|
|
86
|
+
if (!methodNamespace || !options.includeNamespaces.includes(methodNamespace))
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (options.excludeNamespaces && options.excludeNamespaces.length > 0) {
|
|
90
|
+
if (methodNamespace && options.excludeNamespaces.includes(methodNamespace))
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// --- Merge Metadata Inheritance ---
|
|
94
|
+
const ctrlData = (ctrl.openapi || {});
|
|
95
|
+
const finalOperation = Object.assign(Object.assign(Object.assign({ responses: {} }, ctrlData), routeOpenApi), {
|
|
96
|
+
// Merge Tags (unique by name)
|
|
97
|
+
tags: Array.from(new Map([
|
|
98
|
+
...(ctrlData.tags || []).map(t => [t.name, t]),
|
|
99
|
+
...(routeOpenApi.tags || []).map(t => [t.name, t])
|
|
100
|
+
]).values()),
|
|
101
|
+
// Merge Security (additive)
|
|
102
|
+
security: [
|
|
103
|
+
...(ctrlData.security || []),
|
|
104
|
+
...(routeOpenApi.security || [])
|
|
105
|
+
] });
|
|
106
|
+
// Remove empty fields to keep spec clean
|
|
107
|
+
if (((_a = finalOperation.tags) === null || _a === void 0 ? void 0 : _a.length) === 0)
|
|
108
|
+
delete finalOperation.tags;
|
|
109
|
+
if (((_b = finalOperation.security) === null || _b === void 0 ? void 0 : _b.length) === 0)
|
|
110
|
+
delete finalOperation.security;
|
|
111
|
+
spec.paths[path] = Object.assign(Object.assign({}, spec.paths[path]), { [route.method.toLowerCase()]: finalOperation });
|
|
112
|
+
});
|
|
113
|
+
// Clean up empty paths if all methods were filtered out
|
|
114
|
+
Object.keys(spec.paths).forEach(path => {
|
|
115
|
+
if (Object.keys(spec.paths[path]).length === 0) {
|
|
116
|
+
delete spec.paths[path];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
function normalizePath(path) {
|
|
121
|
+
let normalized = path.replace(/:([a-zA-Z0-9_]+)/g, '{$1}');
|
|
122
|
+
// Remove trailing slash if it's not the root path
|
|
123
|
+
if (normalized.length > 1 && normalized.endsWith('/')) {
|
|
124
|
+
normalized = normalized.slice(0, -1);
|
|
125
|
+
}
|
|
126
|
+
return normalized;
|
|
127
|
+
}
|
|
128
|
+
const processModule = (mod) => {
|
|
129
|
+
var _a;
|
|
130
|
+
const modNamespace = (_a = mod.openapi) === null || _a === void 0 ? void 0 : _a.namespace;
|
|
131
|
+
Object.values(mod.controllers).forEach(ctrl => processController(ctrl, modNamespace));
|
|
132
|
+
Object.values(mod.modules).forEach(processModule);
|
|
133
|
+
};
|
|
134
|
+
Object.values(tree.modules).forEach(processModule);
|
|
135
|
+
return spec;
|
|
136
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwaggerMeta = void 0;
|
|
4
|
+
const meta_store_1 = require("../../__internals/stores/meta.store");
|
|
5
|
+
/**
|
|
6
|
+
* 🚀 Metadata accessor for OpenAPI/Swagger documentation
|
|
7
|
+
*/
|
|
8
|
+
exports.SwaggerMeta = meta_store_1.Metadata.prefix('hyper:openapi');
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AppTree } from "../tree/tree";
|
|
2
|
+
export type CollectorType = "class" | "method" | "param";
|
|
3
|
+
export type CollectorFn = (target: any, propertyKey?: string) => any;
|
|
4
|
+
export type TreeProcessorFn = (tree: AppTree) => void;
|
|
5
|
+
declare class OpenAPIMetadataRegistry {
|
|
6
|
+
private collectors;
|
|
7
|
+
private processors;
|
|
8
|
+
/**
|
|
9
|
+
* Register a custom metadata collector.
|
|
10
|
+
* @param type The level where the collector operates.
|
|
11
|
+
* @param collector The function that extracts metadata.
|
|
12
|
+
*/
|
|
13
|
+
registerCollector(type: CollectorType, collector: CollectorFn): void;
|
|
14
|
+
/**
|
|
15
|
+
* Register a processor to transform the final AppTree.
|
|
16
|
+
* @param processor The function that enriches the tree.
|
|
17
|
+
*/
|
|
18
|
+
registerProcessor(processor: TreeProcessorFn): void;
|
|
19
|
+
/**
|
|
20
|
+
* Returns all registered collectors for a specific type.
|
|
21
|
+
*/
|
|
22
|
+
getCollectors(type: CollectorType): CollectorFn[];
|
|
23
|
+
/**
|
|
24
|
+
* Returns all registered tree processors.
|
|
25
|
+
*/
|
|
26
|
+
getProcessors(): TreeProcessorFn[];
|
|
27
|
+
}
|
|
28
|
+
export declare const openApiRegistry: OpenAPIMetadataRegistry;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openApiRegistry = void 0;
|
|
4
|
+
class OpenAPIMetadataRegistry {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.collectors = {
|
|
7
|
+
class: new Set(),
|
|
8
|
+
method: new Set(),
|
|
9
|
+
param: new Set(),
|
|
10
|
+
};
|
|
11
|
+
this.processors = new Set();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Register a custom metadata collector.
|
|
15
|
+
* @param type The level where the collector operates.
|
|
16
|
+
* @param collector The function that extracts metadata.
|
|
17
|
+
*/
|
|
18
|
+
registerCollector(type, collector) {
|
|
19
|
+
this.collectors[type].add(collector);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Register a processor to transform the final AppTree.
|
|
23
|
+
* @param processor The function that enriches the tree.
|
|
24
|
+
*/
|
|
25
|
+
registerProcessor(processor) {
|
|
26
|
+
this.processors.add(processor);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns all registered collectors for a specific type.
|
|
30
|
+
*/
|
|
31
|
+
getCollectors(type) {
|
|
32
|
+
return Array.from(this.collectors[type]);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns all registered tree processors.
|
|
36
|
+
*/
|
|
37
|
+
getProcessors() {
|
|
38
|
+
return Array.from(this.processors);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.openApiRegistry = new OpenAPIMetadataRegistry();
|