nestjs-openapi-next 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +211 -0
- package/bun.lock +2154 -0
- package/dist/constants.d.ts +23 -0
- package/dist/constants.js +26 -0
- package/dist/decorators/api-basic.decorator.d.ts +1 -0
- package/dist/decorators/api-basic.decorator.js +7 -0
- package/dist/decorators/api-bearer.decorator.d.ts +1 -0
- package/dist/decorators/api-bearer.decorator.js +7 -0
- package/dist/decorators/api-body.decorator.d.ts +16 -0
- package/dist/decorators/api-body.decorator.js +22 -0
- package/dist/decorators/api-callbacks.decorator.d.ts +2 -0
- package/dist/decorators/api-callbacks.decorator.js +8 -0
- package/dist/decorators/api-consumes.decorator.d.ts +1 -0
- package/dist/decorators/api-consumes.decorator.js +8 -0
- package/dist/decorators/api-cookie.decorator.d.ts +1 -0
- package/dist/decorators/api-cookie.decorator.js +7 -0
- package/dist/decorators/api-default-getter.decorator.d.ts +2 -0
- package/dist/decorators/api-default-getter.decorator.js +12 -0
- package/dist/decorators/api-exclude-controller.decorator.d.ts +1 -0
- package/dist/decorators/api-exclude-controller.decorator.js +8 -0
- package/dist/decorators/api-exclude-endpoint.decorator.d.ts +1 -0
- package/dist/decorators/api-exclude-endpoint.decorator.js +10 -0
- package/dist/decorators/api-extension.decorator.d.ts +1 -0
- package/dist/decorators/api-extension.decorator.js +38 -0
- package/dist/decorators/api-extra-models.decorator.d.ts +1 -0
- package/dist/decorators/api-extra-models.decorator.js +17 -0
- package/dist/decorators/api-header.decorator.d.ts +7 -0
- package/dist/decorators/api-header.decorator.js +37 -0
- package/dist/decorators/api-hide-property.decorator.d.ts +1 -0
- package/dist/decorators/api-hide-property.decorator.js +6 -0
- package/dist/decorators/api-link.decorator.d.ts +7 -0
- package/dist/decorators/api-link.decorator.js +21 -0
- package/dist/decorators/api-oauth2.decorator.d.ts +1 -0
- package/dist/decorators/api-oauth2.decorator.js +7 -0
- package/dist/decorators/api-operation.decorator.d.ts +5 -0
- package/dist/decorators/api-operation.decorator.js +12 -0
- package/dist/decorators/api-param.decorator.d.ts +22 -0
- package/dist/decorators/api-param.decorator.js +17 -0
- package/dist/decorators/api-produces.decorator.d.ts +1 -0
- package/dist/decorators/api-produces.decorator.js +8 -0
- package/dist/decorators/api-property.decorator.d.ts +15 -0
- package/dist/decorators/api-property.decorator.js +48 -0
- package/dist/decorators/api-query-method.decorator.d.ts +1 -0
- package/dist/decorators/api-query-method.decorator.js +8 -0
- package/dist/decorators/api-query.decorator.d.ts +24 -0
- package/dist/decorators/api-query.decorator.js +25 -0
- package/dist/decorators/api-response.decorator.d.ts +39 -0
- package/dist/decorators/api-response.decorator.js +55 -0
- package/dist/decorators/api-schema.decorator.d.ts +6 -0
- package/dist/decorators/api-schema.decorator.js +8 -0
- package/dist/decorators/api-security-device-flow.decorator.d.ts +1 -0
- package/dist/decorators/api-security-device-flow.decorator.js +7 -0
- package/dist/decorators/api-security.decorator.d.ts +2 -0
- package/dist/decorators/api-security.decorator.js +25 -0
- package/dist/decorators/api-streaming-response.decorator.d.ts +7 -0
- package/dist/decorators/api-streaming-response.decorator.js +9 -0
- package/dist/decorators/api-tag-group.decorator.d.ts +11 -0
- package/dist/decorators/api-tag-group.decorator.js +13 -0
- package/dist/decorators/api-use-tags.decorator.d.ts +1 -0
- package/dist/decorators/api-use-tags.decorator.js +8 -0
- package/dist/decorators/helpers.d.ts +8 -0
- package/dist/decorators/helpers.js +123 -0
- package/dist/decorators/index.d.ts +28 -0
- package/dist/decorators/index.js +48 -0
- package/dist/document-builder.d.ts +29 -0
- package/dist/document-builder.js +142 -0
- package/dist/explorers/api-callbacks.explorer.d.ts +2 -0
- package/dist/explorers/api-callbacks.explorer.js +36 -0
- package/dist/explorers/api-consumes.explorer.d.ts +5 -0
- package/dist/explorers/api-consumes.explorer.js +11 -0
- package/dist/explorers/api-exclude-controller.explorer.d.ts +2 -0
- package/dist/explorers/api-exclude-controller.explorer.js +10 -0
- package/dist/explorers/api-exclude-endpoint.explorer.d.ts +2 -0
- package/dist/explorers/api-exclude-endpoint.explorer.js +6 -0
- package/dist/explorers/api-extra-models.explorer.d.ts +3 -0
- package/dist/explorers/api-extra-models.explorer.js +11 -0
- package/dist/explorers/api-headers.explorer.d.ts +7 -0
- package/dist/explorers/api-headers.explorer.js +9 -0
- package/dist/explorers/api-operation.explorer.d.ts +2 -0
- package/dist/explorers/api-operation.explorer.js +43 -0
- package/dist/explorers/api-parameters.explorer.d.ts +71 -0
- package/dist/explorers/api-parameters.explorer.js +47 -0
- package/dist/explorers/api-produces.explorer.d.ts +5 -0
- package/dist/explorers/api-produces.explorer.js +11 -0
- package/dist/explorers/api-response.explorer.d.ts +13 -0
- package/dist/explorers/api-response.explorer.js +103 -0
- package/dist/explorers/api-security.explorer.d.ts +5 -0
- package/dist/explorers/api-security.explorer.js +13 -0
- package/dist/explorers/api-use-tags.explorer.d.ts +5 -0
- package/dist/explorers/api-use-tags.explorer.js +18 -0
- package/dist/extra/swagger-shim.d.ts +100 -0
- package/dist/extra/swagger-shim.js +367 -0
- package/dist/fixtures/document.base.d.ts +2 -0
- package/dist/fixtures/document.base.js +16 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +23 -0
- package/dist/interfaces/callback-object.interface.d.ts +12 -0
- package/dist/interfaces/callback-object.interface.js +2 -0
- package/dist/interfaces/denormalized-doc-resolvers.interface.d.ts +7 -0
- package/dist/interfaces/denormalized-doc-resolvers.interface.js +2 -0
- package/dist/interfaces/denormalized-doc.interface.d.ts +8 -0
- package/dist/interfaces/denormalized-doc.interface.js +2 -0
- package/dist/interfaces/enum-schema-attributes.interface.d.ts +2 -0
- package/dist/interfaces/enum-schema-attributes.interface.js +2 -0
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/index.js +18 -0
- package/dist/interfaces/module-route.interface.d.ts +2 -0
- package/dist/interfaces/module-route.interface.js +2 -0
- package/dist/interfaces/open-api-spec.interface.d.ts +252 -0
- package/dist/interfaces/open-api-spec.interface.js +2 -0
- package/dist/interfaces/schema-object-metadata.interface.d.ts +30 -0
- package/dist/interfaces/schema-object-metadata.interface.js +2 -0
- package/dist/interfaces/swagger-custom-options.interface.d.ts +24 -0
- package/dist/interfaces/swagger-custom-options.interface.js +2 -0
- package/dist/interfaces/swagger-document-options.interface.d.ts +10 -0
- package/dist/interfaces/swagger-document-options.interface.js +2 -0
- package/dist/interfaces/swagger-ui-init-options.interface.d.ts +7 -0
- package/dist/interfaces/swagger-ui-init-options.interface.js +2 -0
- package/dist/interfaces/swagger-ui-options.interface.d.ts +15 -0
- package/dist/interfaces/swagger-ui-options.interface.js +2 -0
- package/dist/plugin/compiler-plugin.d.ts +2 -0
- package/dist/plugin/compiler-plugin.js +30 -0
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/index.js +18 -0
- package/dist/plugin/merge-options.d.ts +17 -0
- package/dist/plugin/merge-options.js +37 -0
- package/dist/plugin/metadata-loader.d.ts +7 -0
- package/dist/plugin/metadata-loader.js +51 -0
- package/dist/plugin/plugin-constants.d.ts +3 -0
- package/dist/plugin/plugin-constants.js +6 -0
- package/dist/plugin/plugin-debug-logger.d.ts +5 -0
- package/dist/plugin/plugin-debug-logger.js +7 -0
- package/dist/plugin/utils/ast-utils.d.ts +30 -0
- package/dist/plugin/utils/ast-utils.js +273 -0
- package/dist/plugin/utils/is-filename-matched.util.d.ts +1 -0
- package/dist/plugin/utils/is-filename-matched.util.js +5 -0
- package/dist/plugin/utils/plugin-utils.d.ts +30 -0
- package/dist/plugin/utils/plugin-utils.js +307 -0
- package/dist/plugin/utils/type-reference-to-identifier.util.d.ts +7 -0
- package/dist/plugin/utils/type-reference-to-identifier.util.js +52 -0
- package/dist/plugin/visitors/abstract.visitor.d.ts +4 -0
- package/dist/plugin/visitors/abstract.visitor.js +30 -0
- package/dist/plugin/visitors/controller-class.visitor.d.ts +20 -0
- package/dist/plugin/visitors/controller-class.visitor.js +265 -0
- package/dist/plugin/visitors/model-class.visitor.d.ts +35 -0
- package/dist/plugin/visitors/model-class.visitor.js +514 -0
- package/dist/plugin/visitors/readonly.visitor.d.ts +21 -0
- package/dist/plugin/visitors/readonly.visitor.js +40 -0
- package/dist/services/constants.d.ts +1 -0
- package/dist/services/constants.js +4 -0
- package/dist/services/decorators-properties.d.ts +21 -0
- package/dist/services/decorators-properties.js +149 -0
- package/dist/services/mimetype-content-wrapper.d.ts +4 -0
- package/dist/services/mimetype-content-wrapper.js +11 -0
- package/dist/services/model-properties-accessor.d.ts +6 -0
- package/dist/services/model-properties-accessor.js +37 -0
- package/dist/services/parameter-metadata-accessor.d.ts +22 -0
- package/dist/services/parameter-metadata-accessor.js +41 -0
- package/dist/services/parameters-metadata-mapper.d.ts +9 -0
- package/dist/services/parameters-metadata-mapper.js +38 -0
- package/dist/services/response-object-factory.d.ts +28 -0
- package/dist/services/response-object-factory.js +120 -0
- package/dist/services/response-object-mapper.d.ts +39 -0
- package/dist/services/response-object-mapper.js +38 -0
- package/dist/services/schema-object-factory.d.ts +156 -0
- package/dist/services/schema-object-factory.js +471 -0
- package/dist/services/swagger-types-mapper.d.ts +260 -0
- package/dist/services/swagger-types-mapper.js +107 -0
- package/dist/storages/global-parameters.storage.d.ts +8 -0
- package/dist/storages/global-parameters.storage.js +22 -0
- package/dist/storages/global-responses.storage.d.ts +10 -0
- package/dist/storages/global-responses.storage.js +21 -0
- package/dist/swagger-explorer.d.ts +41 -0
- package/dist/swagger-explorer.js +326 -0
- package/dist/swagger-module.d.ts +27 -0
- package/dist/swagger-module.js +223 -0
- package/dist/swagger-scanner.d.ts +25 -0
- package/dist/swagger-scanner.js +116 -0
- package/dist/swagger-transformer.d.ts +4 -0
- package/dist/swagger-transformer.js +22 -0
- package/dist/swagger-ui/constants.d.ts +3 -0
- package/dist/swagger-ui/constants.js +132 -0
- package/dist/swagger-ui/helpers.d.ts +2 -0
- package/dist/swagger-ui/helpers.js +16 -0
- package/dist/swagger-ui/index.d.ts +1 -0
- package/dist/swagger-ui/index.js +17 -0
- package/dist/swagger-ui/swagger-ui.d.ts +4 -0
- package/dist/swagger-ui/swagger-ui.js +62 -0
- package/dist/type-helpers/index.d.ts +4 -0
- package/dist/type-helpers/index.js +20 -0
- package/dist/type-helpers/intersection-type.helper.d.ts +8 -0
- package/dist/type-helpers/intersection-type.helper.js +42 -0
- package/dist/type-helpers/mapped-types.utils.d.ts +2 -0
- package/dist/type-helpers/mapped-types.utils.js +31 -0
- package/dist/type-helpers/omit-type.helper.d.ts +2 -0
- package/dist/type-helpers/omit-type.helper.js +40 -0
- package/dist/type-helpers/partial-type.helper.d.ts +4 -0
- package/dist/type-helpers/partial-type.helper.js +49 -0
- package/dist/type-helpers/pick-type.helper.d.ts +2 -0
- package/dist/type-helpers/pick-type.helper.js +40 -0
- package/dist/types/swagger-enum.type.d.ts +1 -0
- package/dist/types/swagger-enum.type.js +2 -0
- package/dist/utils/assign-two-levels-deep.d.ts +1 -0
- package/dist/utils/assign-two-levels-deep.js +12 -0
- package/dist/utils/enum.utils.d.ts +9 -0
- package/dist/utils/enum.utils.js +65 -0
- package/dist/utils/extend-metadata.util.d.ts +2 -0
- package/dist/utils/extend-metadata.util.js +11 -0
- package/dist/utils/get-global-prefix.d.ts +2 -0
- package/dist/utils/get-global-prefix.js +7 -0
- package/dist/utils/get-schema-path.util.d.ts +4 -0
- package/dist/utils/get-schema-path.util.js +26 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/is-body-parameter.util.d.ts +2 -0
- package/dist/utils/is-body-parameter.util.js +6 -0
- package/dist/utils/is-built-in-type.util.d.ts +2 -0
- package/dist/utils/is-built-in-type.util.js +8 -0
- package/dist/utils/is-date-ctor.util.d.ts +2 -0
- package/dist/utils/is-date-ctor.util.js +6 -0
- package/dist/utils/merge-and-uniq.util.d.ts +1 -0
- package/dist/utils/merge-and-uniq.util.js +7 -0
- package/dist/utils/normalize-rel-path.d.ts +1 -0
- package/dist/utils/normalize-rel-path.js +7 -0
- package/dist/utils/remove-undefined-keys.d.ts +5 -0
- package/dist/utils/remove-undefined-keys.js +11 -0
- package/dist/utils/resolve-path.util.d.ts +1 -0
- package/dist/utils/resolve-path.util.js +7 -0
- package/dist/utils/reverse-object-keys.util.d.ts +1 -0
- package/dist/utils/reverse-object-keys.util.js +11 -0
- package/dist/utils/sort-object-lexicographically.d.ts +5 -0
- package/dist/utils/sort-object-lexicographically.js +11 -0
- package/dist/utils/strip-last-slash.util.d.ts +1 -0
- package/dist/utils/strip-last-slash.util.js +8 -0
- package/dist/utils/validate-global-prefix.util.d.ts +1 -0
- package/dist/utils/validate-global-prefix.util.js +5 -0
- package/dist/utils/validate-path.util.d.ts +1 -0
- package/dist/utils/validate-path.util.js +5 -0
- package/eslint.config.mjs +47 -0
- package/nest-cli.json +6 -0
- package/package.json +116 -0
- package/plugin.js +10 -0
- package/tsconfig.build.json +21 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwaggerScanner = void 0;
|
|
4
|
+
const constants_1 = require("@nestjs/common/constants");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const constants_2 = require("./constants");
|
|
7
|
+
const model_properties_accessor_1 = require("./services/model-properties-accessor");
|
|
8
|
+
const schema_object_factory_1 = require("./services/schema-object-factory");
|
|
9
|
+
const swagger_types_mapper_1 = require("./services/swagger-types-mapper");
|
|
10
|
+
const swagger_explorer_1 = require("./swagger-explorer");
|
|
11
|
+
const swagger_transformer_1 = require("./swagger-transformer");
|
|
12
|
+
const get_global_prefix_1 = require("./utils/get-global-prefix");
|
|
13
|
+
const strip_last_slash_util_1 = require("./utils/strip-last-slash.util");
|
|
14
|
+
class SwaggerScanner {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.transformer = new swagger_transformer_1.SwaggerTransformer();
|
|
17
|
+
this.schemaObjectFactory = new schema_object_factory_1.SchemaObjectFactory(new model_properties_accessor_1.ModelPropertiesAccessor(), new swagger_types_mapper_1.SwaggerTypesMapper());
|
|
18
|
+
}
|
|
19
|
+
scanApplication(app, options) {
|
|
20
|
+
const { deepScanRoutes, include: includedModules = [], extraModels = [], ignoreGlobalPrefix = false, operationIdFactory, linkNameFactory, autoTagControllers = true } = options;
|
|
21
|
+
const untypedApp = app;
|
|
22
|
+
const container = untypedApp.container;
|
|
23
|
+
const internalConfigRef = untypedApp.config;
|
|
24
|
+
const httpAdapterType = app.getHttpAdapter().getType();
|
|
25
|
+
this.initializeSwaggerExplorer(httpAdapterType);
|
|
26
|
+
const modules = this.getModules(container.getModules(), includedModules);
|
|
27
|
+
const globalPrefix = !ignoreGlobalPrefix
|
|
28
|
+
? (0, strip_last_slash_util_1.stripLastSlash)((0, get_global_prefix_1.getGlobalPrefix)(app))
|
|
29
|
+
: '';
|
|
30
|
+
const tagGroups = this.exploreTagGroups(modules);
|
|
31
|
+
const denormalizedPaths = modules.map(({ controllers, metatype, imports }) => {
|
|
32
|
+
let result = [];
|
|
33
|
+
if (deepScanRoutes) {
|
|
34
|
+
const isGlobal = (module) => !container.isGlobalModule(module);
|
|
35
|
+
Array.from(imports.values())
|
|
36
|
+
.filter(isGlobal)
|
|
37
|
+
.forEach(({ metatype, controllers }) => {
|
|
38
|
+
const modulePath = this.getModulePathMetadata(container, metatype);
|
|
39
|
+
result = result.concat(this.scanModuleControllers(controllers, internalConfigRef, {
|
|
40
|
+
modulePath,
|
|
41
|
+
globalPrefix,
|
|
42
|
+
operationIdFactory,
|
|
43
|
+
linkNameFactory,
|
|
44
|
+
autoTagControllers
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const modulePath = this.getModulePathMetadata(container, metatype);
|
|
49
|
+
return result.concat(this.scanModuleControllers(controllers, internalConfigRef, {
|
|
50
|
+
modulePath,
|
|
51
|
+
globalPrefix,
|
|
52
|
+
operationIdFactory,
|
|
53
|
+
linkNameFactory,
|
|
54
|
+
autoTagControllers
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
57
|
+
const schemas = this.explorer.getSchemas();
|
|
58
|
+
this.addExtraModels(schemas, extraModels);
|
|
59
|
+
return Object.assign(Object.assign(Object.assign({}, this.transformer.normalizePaths((0, lodash_1.flatten)(denormalizedPaths))), (tagGroups.length > 0 ? { tags: tagGroups } : {})), { components: {
|
|
60
|
+
schemas: schemas
|
|
61
|
+
} });
|
|
62
|
+
}
|
|
63
|
+
scanModuleControllers(controller, applicationConfig, options) {
|
|
64
|
+
const denormalizedArray = [...controller.values()].map((ctrl) => this.explorer.exploreController(ctrl, applicationConfig, options));
|
|
65
|
+
return (0, lodash_1.flatten)(denormalizedArray);
|
|
66
|
+
}
|
|
67
|
+
getModules(modulesContainer, include) {
|
|
68
|
+
if (!include || (0, lodash_1.isEmpty)(include)) {
|
|
69
|
+
return [...modulesContainer.values()];
|
|
70
|
+
}
|
|
71
|
+
return [...modulesContainer.values()].filter(({ metatype }) => include.some((item) => item === metatype));
|
|
72
|
+
}
|
|
73
|
+
addExtraModels(schemas, extraModels) {
|
|
74
|
+
extraModels.forEach((item) => {
|
|
75
|
+
this.schemaObjectFactory.exploreModelSchema(item, schemas);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
getModulePathMetadata(container, metatype) {
|
|
79
|
+
const modulesContainer = container.getModules();
|
|
80
|
+
const modulePath = Reflect.getMetadata(constants_1.MODULE_PATH + modulesContainer.applicationId, metatype);
|
|
81
|
+
return modulePath !== null && modulePath !== void 0 ? modulePath : Reflect.getMetadata(constants_1.MODULE_PATH, metatype);
|
|
82
|
+
}
|
|
83
|
+
initializeSwaggerExplorer(httpAdapterType) {
|
|
84
|
+
if (this.explorer) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.explorer = new swagger_explorer_1.SwaggerExplorer(this.schemaObjectFactory, {
|
|
88
|
+
httpAdapterType
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
exploreTagGroups(modules) {
|
|
92
|
+
const byName = new Map();
|
|
93
|
+
for (const moduleRef of modules) {
|
|
94
|
+
for (const wrapper of moduleRef.controllers.values()) {
|
|
95
|
+
const metatype = wrapper.metatype;
|
|
96
|
+
if (!metatype) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const groups = Reflect.getMetadata(constants_2.DECORATORS.API_TAG_GROUP, metatype) || [];
|
|
100
|
+
for (const group of groups) {
|
|
101
|
+
if (!(group === null || group === void 0 ? void 0 : group.name)) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const previous = byName.get(group.name) || { name: group.name };
|
|
105
|
+
byName.set(group.name, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, previous), (group.summary !== undefined ? { summary: group.summary } : {})), (group.description !== undefined
|
|
106
|
+
? { description: group.description }
|
|
107
|
+
: {})), (group.externalDocs !== undefined
|
|
108
|
+
? { externalDocs: group.externalDocs }
|
|
109
|
+
: {})), (group.parent !== undefined ? { parent: group.parent } : {})), (group.kind !== undefined ? { kind: group.kind } : {})));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return [...byName.values()];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.SwaggerScanner = SwaggerScanner;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwaggerTransformer = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const sort_object_lexicographically_1 = require("./utils/sort-object-lexicographically");
|
|
6
|
+
class SwaggerTransformer {
|
|
7
|
+
normalizePaths(denormalizedDoc) {
|
|
8
|
+
const roots = (0, lodash_1.filter)(denormalizedDoc, (r) => r.root);
|
|
9
|
+
const groupedByPath = (0, lodash_1.groupBy)(roots, ({ root }) => root.path);
|
|
10
|
+
const paths = (0, lodash_1.mapValues)(groupedByPath, (routes) => {
|
|
11
|
+
const keyByMethod = (0, lodash_1.keyBy)(routes, ({ root }) => root.method);
|
|
12
|
+
return (0, lodash_1.mapValues)(keyByMethod, (route) => {
|
|
13
|
+
const mergedDefinition = Object.assign(Object.assign({}, (0, lodash_1.omit)(route, 'root')), (0, lodash_1.omit)(route.root, ['method', 'path']));
|
|
14
|
+
return (0, sort_object_lexicographically_1.sortObjectLexicographically)(mergedDefinition);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
paths
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.SwaggerTransformer = SwaggerTransformer;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const favIconHtml: string;
|
|
2
|
+
export declare const htmlTemplateString = "\n<!-- HTML for static distribution bundle build -->\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <title><% title %></title>\n <link rel=\"stylesheet\" type=\"text/css\" href=\"<% baseUrl %>swagger-ui.css\" >\n <% favIconString %>\n <style>\n html\n {\n box-sizing: border-box;\n overflow: -moz-scrollbars-vertical;\n overflow-y: scroll;\n }\n *,\n *:before,\n *:after\n {\n box-sizing: inherit;\n }\n\n body {\n margin:0;\n background: #fafafa;\n }\n </style>\n</head>\n\n<body>\n\n<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" style=\"position:absolute;width:0;height:0\">\n <defs>\n <symbol viewBox=\"0 0 20 20\" id=\"unlocked\">\n <path d=\"M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z\"></path>\n </symbol>\n\n <symbol viewBox=\"0 0 20 20\" id=\"locked\">\n <path d=\"M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z\"/>\n </symbol>\n\n <symbol viewBox=\"0 0 20 20\" id=\"close\">\n <path d=\"M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z\"/>\n </symbol>\n\n <symbol viewBox=\"0 0 20 20\" id=\"large-arrow\">\n <path d=\"M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z\"/>\n </symbol>\n\n <symbol viewBox=\"0 0 20 20\" id=\"large-arrow-down\">\n <path d=\"M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z\"/>\n </symbol>\n\n\n <symbol viewBox=\"0 0 24 24\" id=\"jump-to\">\n <path d=\"M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z\"/>\n </symbol>\n\n <symbol viewBox=\"0 0 24 24\" id=\"expand\">\n <path d=\"M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z\"/>\n </symbol>\n\n </defs>\n</svg>\n\n<div id=\"swagger-ui\"></div>\n\n<script src=\"<% baseUrl %>swagger-ui-bundle.js\"> </script>\n<script src=\"<% baseUrl %>swagger-ui-standalone-preset.js\"> </script>\n<script src=\"<% baseUrl %>swagger-ui-init.js\"> </script>\n<% customJs %>\n<% customJsStr %>\n<% customCssUrl %>\n<style>\n <% customCss %>\n <% explorerCss %>\n</style>\n</body>\n\n</html>\n";
|
|
3
|
+
export declare const jsTemplateString = "\nwindow.onload = function() {\n // Build a system\n let url = window.location.search.match(/url=([^&]+)/);\n if (url && url.length > 1) {\n url = decodeURIComponent(url[1]);\n } else {\n url = window.location.origin;\n }\n <% swaggerOptions %>\n url = options.swaggerUrl || url\n let urls = options.swaggerUrls\n let customOptions = options.customOptions\n let spec1 = options.swaggerDoc\n let swaggerOptions = {\n spec: spec1,\n url: url,\n urls: urls,\n dom_id: '#swagger-ui',\n deepLinking: true,\n presets: [\n SwaggerUIBundle.presets.apis,\n SwaggerUIStandalonePreset\n ],\n plugins: [\n SwaggerUIBundle.plugins.DownloadUrl\n ],\n layout: \"StandaloneLayout\"\n }\n for (let attrname in customOptions) {\n swaggerOptions[attrname] = customOptions[attrname];\n }\n let ui = SwaggerUIBundle(swaggerOptions)\n\n if (customOptions.initOAuth) {\n ui.initOAuth(customOptions.initOAuth)\n }\n\n if (customOptions.authAction) {\n ui.authActions.authorize(customOptions.authAction)\n }\n \n window.ui = ui\n}\n";
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsTemplateString = exports.htmlTemplateString = exports.favIconHtml = void 0;
|
|
4
|
+
exports.favIconHtml = '<link rel="icon" type="image/png" href="<% baseUrl %>favicon-32x32.png" sizes="32x32" />' +
|
|
5
|
+
'<link rel="icon" type="image/png" href="<% baseUrl %>favicon-16x16.png" sizes="16x16" />';
|
|
6
|
+
exports.htmlTemplateString = `
|
|
7
|
+
<!-- HTML for static distribution bundle build -->
|
|
8
|
+
<!DOCTYPE html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="UTF-8">
|
|
12
|
+
<title><% title %></title>
|
|
13
|
+
<link rel="stylesheet" type="text/css" href="<% baseUrl %>swagger-ui.css" >
|
|
14
|
+
<% favIconString %>
|
|
15
|
+
<style>
|
|
16
|
+
html
|
|
17
|
+
{
|
|
18
|
+
box-sizing: border-box;
|
|
19
|
+
overflow: -moz-scrollbars-vertical;
|
|
20
|
+
overflow-y: scroll;
|
|
21
|
+
}
|
|
22
|
+
*,
|
|
23
|
+
*:before,
|
|
24
|
+
*:after
|
|
25
|
+
{
|
|
26
|
+
box-sizing: inherit;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
body {
|
|
30
|
+
margin:0;
|
|
31
|
+
background: #fafafa;
|
|
32
|
+
}
|
|
33
|
+
</style>
|
|
34
|
+
</head>
|
|
35
|
+
|
|
36
|
+
<body>
|
|
37
|
+
|
|
38
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
|
39
|
+
<defs>
|
|
40
|
+
<symbol viewBox="0 0 20 20" id="unlocked">
|
|
41
|
+
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
|
42
|
+
</symbol>
|
|
43
|
+
|
|
44
|
+
<symbol viewBox="0 0 20 20" id="locked">
|
|
45
|
+
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
|
|
46
|
+
</symbol>
|
|
47
|
+
|
|
48
|
+
<symbol viewBox="0 0 20 20" id="close">
|
|
49
|
+
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
|
|
50
|
+
</symbol>
|
|
51
|
+
|
|
52
|
+
<symbol viewBox="0 0 20 20" id="large-arrow">
|
|
53
|
+
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
|
|
54
|
+
</symbol>
|
|
55
|
+
|
|
56
|
+
<symbol viewBox="0 0 20 20" id="large-arrow-down">
|
|
57
|
+
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
|
|
58
|
+
</symbol>
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
<symbol viewBox="0 0 24 24" id="jump-to">
|
|
62
|
+
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
|
|
63
|
+
</symbol>
|
|
64
|
+
|
|
65
|
+
<symbol viewBox="0 0 24 24" id="expand">
|
|
66
|
+
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
|
|
67
|
+
</symbol>
|
|
68
|
+
|
|
69
|
+
</defs>
|
|
70
|
+
</svg>
|
|
71
|
+
|
|
72
|
+
<div id="swagger-ui"></div>
|
|
73
|
+
|
|
74
|
+
<script src="<% baseUrl %>swagger-ui-bundle.js"> </script>
|
|
75
|
+
<script src="<% baseUrl %>swagger-ui-standalone-preset.js"> </script>
|
|
76
|
+
<script src="<% baseUrl %>swagger-ui-init.js"> </script>
|
|
77
|
+
<% customJs %>
|
|
78
|
+
<% customJsStr %>
|
|
79
|
+
<% customCssUrl %>
|
|
80
|
+
<style>
|
|
81
|
+
<% customCss %>
|
|
82
|
+
<% explorerCss %>
|
|
83
|
+
</style>
|
|
84
|
+
</body>
|
|
85
|
+
|
|
86
|
+
</html>
|
|
87
|
+
`;
|
|
88
|
+
exports.jsTemplateString = `
|
|
89
|
+
window.onload = function() {
|
|
90
|
+
// Build a system
|
|
91
|
+
let url = window.location.search.match(/url=([^&]+)/);
|
|
92
|
+
if (url && url.length > 1) {
|
|
93
|
+
url = decodeURIComponent(url[1]);
|
|
94
|
+
} else {
|
|
95
|
+
url = window.location.origin;
|
|
96
|
+
}
|
|
97
|
+
<% swaggerOptions %>
|
|
98
|
+
url = options.swaggerUrl || url
|
|
99
|
+
let urls = options.swaggerUrls
|
|
100
|
+
let customOptions = options.customOptions
|
|
101
|
+
let spec1 = options.swaggerDoc
|
|
102
|
+
let swaggerOptions = {
|
|
103
|
+
spec: spec1,
|
|
104
|
+
url: url,
|
|
105
|
+
urls: urls,
|
|
106
|
+
dom_id: '#swagger-ui',
|
|
107
|
+
deepLinking: true,
|
|
108
|
+
presets: [
|
|
109
|
+
SwaggerUIBundle.presets.apis,
|
|
110
|
+
SwaggerUIStandalonePreset
|
|
111
|
+
],
|
|
112
|
+
plugins: [
|
|
113
|
+
SwaggerUIBundle.plugins.DownloadUrl
|
|
114
|
+
],
|
|
115
|
+
layout: "StandaloneLayout"
|
|
116
|
+
}
|
|
117
|
+
for (let attrname in customOptions) {
|
|
118
|
+
swaggerOptions[attrname] = customOptions[attrname];
|
|
119
|
+
}
|
|
120
|
+
let ui = SwaggerUIBundle(swaggerOptions)
|
|
121
|
+
|
|
122
|
+
if (customOptions.initOAuth) {
|
|
123
|
+
ui.initOAuth(customOptions.initOAuth)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (customOptions.authAction) {
|
|
127
|
+
ui.authActions.authorize(customOptions.authAction)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
window.ui = ui
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildJSInitOptions = buildJSInitOptions;
|
|
4
|
+
function buildJSInitOptions(initOptions) {
|
|
5
|
+
const functionPlaceholder = '____FUNCTION_PLACEHOLDER____';
|
|
6
|
+
const fns = [];
|
|
7
|
+
let json = JSON.stringify(initOptions, (key, value) => {
|
|
8
|
+
if (typeof value === 'function') {
|
|
9
|
+
fns.push(value);
|
|
10
|
+
return functionPlaceholder;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}, 2);
|
|
14
|
+
json = json.replace(new RegExp('"' + functionPlaceholder + '"', 'g'), () => fns.shift());
|
|
15
|
+
return `let options = ${json};`;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './swagger-ui';
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./swagger-ui"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { OpenAPIObject, SwaggerCustomOptions } from '../interfaces';
|
|
2
|
+
export declare function buildSwaggerInitJS(swaggerDoc: OpenAPIObject, customOptions?: SwaggerCustomOptions): string;
|
|
3
|
+
export declare function getSwaggerAssetsAbsoluteFSPath(): string;
|
|
4
|
+
export declare function buildSwaggerHTML(baseUrl: string, customOptions?: SwaggerCustomOptions): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSwaggerInitJS = buildSwaggerInitJS;
|
|
4
|
+
exports.getSwaggerAssetsAbsoluteFSPath = getSwaggerAssetsAbsoluteFSPath;
|
|
5
|
+
exports.buildSwaggerHTML = buildSwaggerHTML;
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
8
|
+
function buildSwaggerInitJS(swaggerDoc, customOptions = {}) {
|
|
9
|
+
const { swaggerOptions = {}, swaggerUrl } = customOptions;
|
|
10
|
+
const swaggerInitOptions = {
|
|
11
|
+
swaggerDoc,
|
|
12
|
+
swaggerUrl,
|
|
13
|
+
customOptions: swaggerOptions
|
|
14
|
+
};
|
|
15
|
+
const jsInitOptions = (0, helpers_1.buildJSInitOptions)(swaggerInitOptions);
|
|
16
|
+
return constants_1.jsTemplateString.replace('<% swaggerOptions %>', jsInitOptions);
|
|
17
|
+
}
|
|
18
|
+
let swaggerAssetsAbsoluteFSPath;
|
|
19
|
+
function getSwaggerAssetsAbsoluteFSPath() {
|
|
20
|
+
if (!swaggerAssetsAbsoluteFSPath) {
|
|
21
|
+
swaggerAssetsAbsoluteFSPath = require('swagger-ui-dist/absolute-path.js')();
|
|
22
|
+
}
|
|
23
|
+
return swaggerAssetsAbsoluteFSPath;
|
|
24
|
+
}
|
|
25
|
+
function toExternalScriptTag(url) {
|
|
26
|
+
return `<script src='${url}'></script>`;
|
|
27
|
+
}
|
|
28
|
+
function toInlineScriptTag(jsCode) {
|
|
29
|
+
return `<script>${jsCode}</script>`;
|
|
30
|
+
}
|
|
31
|
+
function toExternalStylesheetTag(url) {
|
|
32
|
+
return `<link href='${url}' rel='stylesheet'>`;
|
|
33
|
+
}
|
|
34
|
+
function toTags(customCode, toScript) {
|
|
35
|
+
if (!customCode) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
if (typeof customCode === 'string') {
|
|
39
|
+
return toScript(customCode);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return customCode.map(toScript).join('\n');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function buildSwaggerHTML(baseUrl, customOptions = {}) {
|
|
46
|
+
const { customCss = '', customJs = '', customJsStr = '', customfavIcon = false, customSiteTitle = 'Swagger UI', customCssUrl = '', explorer = false } = customOptions;
|
|
47
|
+
const favIconString = customfavIcon
|
|
48
|
+
? `<link rel='icon' href='${customfavIcon}' />`
|
|
49
|
+
: constants_1.favIconHtml;
|
|
50
|
+
const explorerCss = explorer
|
|
51
|
+
? ''
|
|
52
|
+
: '.swagger-ui .topbar .download-url-wrapper { display: none }';
|
|
53
|
+
return constants_1.htmlTemplateString
|
|
54
|
+
.replace('<% customCss %>', customCss)
|
|
55
|
+
.replace('<% explorerCss %>', explorerCss)
|
|
56
|
+
.replace('<% favIconString %>', favIconString)
|
|
57
|
+
.replace(/<% baseUrl %>/g, baseUrl)
|
|
58
|
+
.replace('<% customJs %>', toTags(customJs, toExternalScriptTag))
|
|
59
|
+
.replace('<% customJsStr %>', toTags(customJsStr, toInlineScriptTag))
|
|
60
|
+
.replace('<% customCssUrl %>', toTags(customCssUrl, toExternalStylesheetTag))
|
|
61
|
+
.replace('<% title %>', customSiteTitle);
|
|
62
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
__exportStar(require("./intersection-type.helper"), exports);
|
|
18
|
+
__exportStar(require("./omit-type.helper"), exports);
|
|
19
|
+
__exportStar(require("./partial-type.helper"), exports);
|
|
20
|
+
__exportStar(require("./pick-type.helper"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
3
|
+
type ClassRefsToConstructors<T extends Type[]> = {
|
|
4
|
+
[U in keyof T]: T[U] extends Type<infer V> ? V : never;
|
|
5
|
+
};
|
|
6
|
+
type Intersection<T extends Type[]> = Type<UnionToIntersection<ClassRefsToConstructors<T>[number]>>;
|
|
7
|
+
export declare function IntersectionType<T extends Type[]>(...classRefs: T): Intersection<T>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntersectionType = IntersectionType;
|
|
4
|
+
const mapped_types_1 = require("@nestjs/mapped-types");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const decorators_1 = require("../decorators");
|
|
7
|
+
const metadata_loader_1 = require("../plugin/metadata-loader");
|
|
8
|
+
const model_properties_accessor_1 = require("../services/model-properties-accessor");
|
|
9
|
+
const mapped_types_utils_1 = require("./mapped-types.utils");
|
|
10
|
+
const modelPropertiesAccessor = new model_properties_accessor_1.ModelPropertiesAccessor();
|
|
11
|
+
function IntersectionType(...classRefs) {
|
|
12
|
+
class IntersectionClassType {
|
|
13
|
+
constructor() {
|
|
14
|
+
classRefs.forEach((classRef) => {
|
|
15
|
+
(0, mapped_types_1.inheritPropertyInitializers)(this, classRef);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
classRefs.forEach((classRef) => {
|
|
20
|
+
const fields = modelPropertiesAccessor.getModelProperties(classRef.prototype);
|
|
21
|
+
(0, mapped_types_1.inheritValidationMetadata)(classRef, IntersectionClassType);
|
|
22
|
+
(0, mapped_types_1.inheritTransformationMetadata)(classRef, IntersectionClassType);
|
|
23
|
+
function applyFields(fields) {
|
|
24
|
+
(0, mapped_types_utils_1.clonePluginMetadataFactory)(IntersectionClassType, classRef.prototype);
|
|
25
|
+
fields.forEach((propertyKey) => {
|
|
26
|
+
const metadata = Reflect.getMetadata(constants_1.DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, propertyKey);
|
|
27
|
+
const decoratorFactory = (0, decorators_1.ApiProperty)(metadata);
|
|
28
|
+
decoratorFactory(IntersectionClassType.prototype, propertyKey);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
applyFields(fields);
|
|
32
|
+
metadata_loader_1.MetadataLoader.addRefreshHook(() => {
|
|
33
|
+
const fields = modelPropertiesAccessor.getModelProperties(classRef.prototype);
|
|
34
|
+
applyFields(fields);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
const intersectedNames = classRefs.reduce((prev, ref) => prev + ref.name, '');
|
|
38
|
+
Object.defineProperty(IntersectionClassType, 'name', {
|
|
39
|
+
value: `Intersection${intersectedNames}`
|
|
40
|
+
});
|
|
41
|
+
return IntersectionClassType;
|
|
42
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clonePluginMetadataFactory = clonePluginMetadataFactory;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const plugin_constants_1 = require("../plugin/plugin-constants");
|
|
6
|
+
function clonePluginMetadataFactory(target, parent, transformFn = lodash_1.identity) {
|
|
7
|
+
let targetMetadata = {};
|
|
8
|
+
do {
|
|
9
|
+
if (!parent.constructor) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (!parent.constructor[plugin_constants_1.METADATA_FACTORY_NAME]) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const parentMetadata = parent.constructor[plugin_constants_1.METADATA_FACTORY_NAME]();
|
|
16
|
+
targetMetadata = Object.assign(Object.assign({}, parentMetadata), targetMetadata);
|
|
17
|
+
} while ((parent = Reflect.getPrototypeOf(parent)) &&
|
|
18
|
+
parent !== Object.prototype &&
|
|
19
|
+
parent);
|
|
20
|
+
targetMetadata = transformFn(targetMetadata);
|
|
21
|
+
if (target[plugin_constants_1.METADATA_FACTORY_NAME]) {
|
|
22
|
+
const originalFactory = target[plugin_constants_1.METADATA_FACTORY_NAME];
|
|
23
|
+
target[plugin_constants_1.METADATA_FACTORY_NAME] = () => {
|
|
24
|
+
const originalMetadata = originalFactory();
|
|
25
|
+
return Object.assign(Object.assign({}, originalMetadata), targetMetadata);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
target[plugin_constants_1.METADATA_FACTORY_NAME] = () => targetMetadata;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OmitType = OmitType;
|
|
4
|
+
const mapped_types_1 = require("@nestjs/mapped-types");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const decorators_1 = require("../decorators");
|
|
8
|
+
const metadata_loader_1 = require("../plugin/metadata-loader");
|
|
9
|
+
const model_properties_accessor_1 = require("../services/model-properties-accessor");
|
|
10
|
+
const mapped_types_utils_1 = require("./mapped-types.utils");
|
|
11
|
+
const modelPropertiesAccessor = new model_properties_accessor_1.ModelPropertiesAccessor();
|
|
12
|
+
function OmitType(classRef, keys) {
|
|
13
|
+
const fields = modelPropertiesAccessor
|
|
14
|
+
.getModelProperties(classRef.prototype)
|
|
15
|
+
.filter((item) => !keys.includes(item));
|
|
16
|
+
const isInheritedPredicate = (propertyKey) => !keys.includes(propertyKey);
|
|
17
|
+
class OmitTypeClass {
|
|
18
|
+
constructor() {
|
|
19
|
+
(0, mapped_types_1.inheritPropertyInitializers)(this, classRef, isInheritedPredicate);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
(0, mapped_types_1.inheritValidationMetadata)(classRef, OmitTypeClass, isInheritedPredicate);
|
|
23
|
+
(0, mapped_types_1.inheritTransformationMetadata)(classRef, OmitTypeClass, isInheritedPredicate);
|
|
24
|
+
function applyFields(fields) {
|
|
25
|
+
(0, mapped_types_utils_1.clonePluginMetadataFactory)(OmitTypeClass, classRef.prototype, (metadata) => (0, lodash_1.omit)(metadata, keys));
|
|
26
|
+
fields.forEach((propertyKey) => {
|
|
27
|
+
const metadata = Reflect.getMetadata(constants_1.DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, propertyKey);
|
|
28
|
+
const decoratorFactory = (0, decorators_1.ApiProperty)(metadata);
|
|
29
|
+
decoratorFactory(OmitTypeClass.prototype, propertyKey);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
applyFields(fields);
|
|
33
|
+
metadata_loader_1.MetadataLoader.addRefreshHook(() => {
|
|
34
|
+
const fields = modelPropertiesAccessor
|
|
35
|
+
.getModelProperties(classRef.prototype)
|
|
36
|
+
.filter((item) => !keys.includes(item));
|
|
37
|
+
applyFields(fields);
|
|
38
|
+
});
|
|
39
|
+
return OmitTypeClass;
|
|
40
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PartialType = PartialType;
|
|
4
|
+
const mapped_types_1 = require("@nestjs/mapped-types");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const decorators_1 = require("../decorators");
|
|
8
|
+
const metadata_loader_1 = require("../plugin/metadata-loader");
|
|
9
|
+
const plugin_constants_1 = require("../plugin/plugin-constants");
|
|
10
|
+
const model_properties_accessor_1 = require("../services/model-properties-accessor");
|
|
11
|
+
const mapped_types_utils_1 = require("./mapped-types.utils");
|
|
12
|
+
const modelPropertiesAccessor = new model_properties_accessor_1.ModelPropertiesAccessor();
|
|
13
|
+
function PartialType(classRef, options = {}) {
|
|
14
|
+
const applyPartialDecoratorFn = options.skipNullProperties === false
|
|
15
|
+
? mapped_types_1.applyValidateIfDefinedDecorator
|
|
16
|
+
: mapped_types_1.applyIsOptionalDecorator;
|
|
17
|
+
const fields = modelPropertiesAccessor.getModelProperties(classRef.prototype);
|
|
18
|
+
class PartialTypeClass {
|
|
19
|
+
constructor() {
|
|
20
|
+
(0, mapped_types_1.inheritPropertyInitializers)(this, classRef);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const keysWithValidationConstraints = (0, mapped_types_1.inheritValidationMetadata)(classRef, PartialTypeClass);
|
|
24
|
+
if (keysWithValidationConstraints) {
|
|
25
|
+
keysWithValidationConstraints
|
|
26
|
+
.filter((key) => !fields.includes(key))
|
|
27
|
+
.forEach((key) => applyPartialDecoratorFn(PartialTypeClass, key));
|
|
28
|
+
}
|
|
29
|
+
(0, mapped_types_1.inheritTransformationMetadata)(classRef, PartialTypeClass);
|
|
30
|
+
function applyFields(fields) {
|
|
31
|
+
(0, mapped_types_utils_1.clonePluginMetadataFactory)(PartialTypeClass, classRef.prototype, (metadata) => (0, lodash_1.mapValues)(metadata, (item) => (Object.assign(Object.assign({}, item), { required: false }))));
|
|
32
|
+
if (PartialTypeClass[plugin_constants_1.METADATA_FACTORY_NAME]) {
|
|
33
|
+
const pluginFields = Object.keys(PartialTypeClass[plugin_constants_1.METADATA_FACTORY_NAME]());
|
|
34
|
+
pluginFields.forEach((key) => applyPartialDecoratorFn(PartialTypeClass, key));
|
|
35
|
+
}
|
|
36
|
+
fields.forEach((key) => {
|
|
37
|
+
const metadata = Reflect.getMetadata(constants_1.DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, key) || {};
|
|
38
|
+
const decoratorFactory = (0, decorators_1.ApiProperty)(Object.assign(Object.assign({}, metadata), { required: false }));
|
|
39
|
+
decoratorFactory(PartialTypeClass.prototype, key);
|
|
40
|
+
applyPartialDecoratorFn(PartialTypeClass, key);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
applyFields(fields);
|
|
44
|
+
metadata_loader_1.MetadataLoader.addRefreshHook(() => {
|
|
45
|
+
const fields = modelPropertiesAccessor.getModelProperties(classRef.prototype);
|
|
46
|
+
applyFields(fields);
|
|
47
|
+
});
|
|
48
|
+
return PartialTypeClass;
|
|
49
|
+
}
|