@nestjs/swagger
Advanced tools
Comparing version 5.2.0 to 5.2.1
@@ -41,2 +41,3 @@ interface CommonSwaggerCustomOptions { | ||
operationsSorter: string; | ||
queryConfigEnabled: boolean; | ||
}>; | ||
@@ -43,0 +44,0 @@ initOAuth?: Record<string, any>; |
import * as ts from 'typescript'; | ||
import { PluginOptions } from '../merge-options'; | ||
import { AbstractFileVisitor } from './abstract.visitor'; | ||
import { PropertyAssignment } from 'typescript'; | ||
declare type ClassMetadata = Record<string, ts.ObjectLiteralExpression>; | ||
@@ -15,2 +16,3 @@ export declare class ModelClassVisitor extends AbstractFileVisitor { | ||
addPropertyByValidationDecorator(factory: ts.NodeFactory, decoratorName: string, propertyKey: string, decorators: ts.NodeArray<ts.Decorator>, assignments: ts.PropertyAssignment[]): void; | ||
addPropertiesByValidationDecorator(factory: ts.NodeFactory, decoratorName: string, decorators: ts.NodeArray<ts.Decorator>, assignments: ts.PropertyAssignment[], addPropertyAssignments: (decoratorRef: ts.Decorator) => PropertyAssignment[]): void; | ||
addClassMetadata(node: ts.PropertyDeclaration, objectLiteral: ts.ObjectLiteralExpression, sourceFile: ts.SourceFile, metadata: ClassMetadata): void; | ||
@@ -17,0 +19,0 @@ createDescriptionAndExamplePropertyAssigments(factory: ts.NodeFactory, node: ts.PropertyDeclaration | ts.PropertySignature, typeChecker: ts.TypeChecker, existingProperties?: ts.NodeArray<ts.PropertyAssignment>, options?: PluginOptions, sourceFile?: ts.SourceFile): ts.PropertyAssignment[]; |
@@ -174,2 +174,4 @@ "use strict"; | ||
const decorators = node.decorators; | ||
this.addPropertyByValidationDecorator(factory, 'Matches', 'pattern', decorators, assignments); | ||
this.addPropertyByValidationDecorator(factory, 'IsIn', 'enum', decorators, assignments); | ||
this.addPropertyByValidationDecorator(factory, 'Min', 'minimum', decorators, assignments); | ||
@@ -179,5 +181,33 @@ this.addPropertyByValidationDecorator(factory, 'Max', 'maximum', decorators, assignments); | ||
this.addPropertyByValidationDecorator(factory, 'MaxLength', 'maxLength', decorators, assignments); | ||
this.addPropertiesByValidationDecorator(factory, 'IsPositive', decorators, assignments, () => { | ||
return [ | ||
factory.createPropertyAssignment('minimum', ast_utils_1.createPrimitiveLiteral(factory, 1)) | ||
]; | ||
}); | ||
this.addPropertiesByValidationDecorator(factory, 'IsNegative', decorators, assignments, () => { | ||
return [ | ||
factory.createPropertyAssignment('maximum', ast_utils_1.createPrimitiveLiteral(factory, -1)) | ||
]; | ||
}); | ||
this.addPropertiesByValidationDecorator(factory, 'Length', decorators, assignments, (decoratorRef) => { | ||
const decoratorArguments = ast_utils_1.getDecoratorArguments(decoratorRef); | ||
const result = []; | ||
result.push(factory.createPropertyAssignment('minLength', lodash_1.head(decoratorArguments))); | ||
if (decoratorArguments.length > 1) { | ||
result.push(factory.createPropertyAssignment('maxLength', decoratorArguments[1])); | ||
} | ||
return result; | ||
}); | ||
return assignments; | ||
} | ||
addPropertyByValidationDecorator(factory, decoratorName, propertyKey, decorators, assignments) { | ||
this.addPropertiesByValidationDecorator(factory, decoratorName, decorators, assignments, (decoratorRef) => { | ||
const argument = lodash_1.head(ast_utils_1.getDecoratorArguments(decoratorRef)); | ||
if (argument) { | ||
return [factory.createPropertyAssignment(propertyKey, argument)]; | ||
} | ||
return []; | ||
}); | ||
} | ||
addPropertiesByValidationDecorator(factory, decoratorName, decorators, assignments, addPropertyAssignments) { | ||
const decoratorRef = plugin_utils_1.getDecoratorOrUndefinedByNames([decoratorName], decorators); | ||
@@ -187,6 +217,3 @@ if (!decoratorRef) { | ||
} | ||
const argument = lodash_1.head(ast_utils_1.getDecoratorArguments(decoratorRef)); | ||
if (argument) { | ||
assignments.push(factory.createPropertyAssignment(propertyKey, argument)); | ||
} | ||
assignments.push(...addPropertyAssignments(decoratorRef)); | ||
} | ||
@@ -193,0 +220,0 @@ addClassMetadata(node, objectLiteral, sourceFile, metadata) { |
@@ -6,9 +6,10 @@ import { INestApplication } from '@nestjs/common'; | ||
import { OpenAPIObject, SwaggerDocumentOptions } from './interfaces'; | ||
import { ModuleRoute } from './interfaces/module-route.interface'; | ||
import { SchemaObject } from './interfaces/open-api-spec.interface'; | ||
export declare class SwaggerScanner { | ||
private readonly transfomer; | ||
private readonly transformer; | ||
private readonly schemaObjectFactory; | ||
private readonly explorer; | ||
scanApplication(app: INestApplication, options: SwaggerDocumentOptions): Omit<OpenAPIObject, 'openapi' | 'info'>; | ||
scanModuleRoutes(routes: Map<InstanceToken, InstanceWrapper>, modulePath: string | undefined, globalPrefix: string | undefined, applicationConfig: ApplicationConfig, operationIdFactory?: (controllerKey: string, methodKey: string) => string): Array<Omit<OpenAPIObject, 'openapi' | 'info'> & Record<'root', any>>; | ||
scanModuleRoutes(routes: Map<InstanceToken, InstanceWrapper>, modulePath: string | undefined, globalPrefix: string | undefined, applicationConfig: ApplicationConfig, operationIdFactory?: (controllerKey: string, methodKey: string) => string): ModuleRoute[]; | ||
getModules(modulesContainer: Map<string, Module>, include: Function[]): Module[]; | ||
@@ -15,0 +16,0 @@ addExtraModels(schemas: Record<string, SchemaObject>, extraModels: Function[]): void; |
@@ -15,3 +15,3 @@ "use strict"; | ||
constructor() { | ||
this.transfomer = new swagger_transformer_1.SwaggerTransformer(); | ||
this.transformer = new swagger_transformer_1.SwaggerTransformer(); | ||
this.schemaObjectFactory = new schema_object_factory_1.SchemaObjectFactory(new model_properties_accessor_1.ModelPropertiesAccessor(), new swagger_types_mapper_1.SwaggerTypesMapper()); | ||
@@ -40,7 +40,8 @@ this.explorer = new swagger_explorer_1.SwaggerExplorer(this.schemaObjectFactory); | ||
const modulePath = this.getModulePathMetadata(container, metatype); | ||
return result.concat(this.scanModuleRoutes(routes, modulePath, globalPrefix, internalConfigRef, operationIdFactory)); | ||
result = result.concat(this.scanModuleRoutes(routes, modulePath, globalPrefix, internalConfigRef, operationIdFactory)); | ||
return this.transformer.unescapeColonsInPath(app, result); | ||
}); | ||
const schemas = this.explorer.getSchemas(); | ||
this.addExtraModels(schemas, extraModels); | ||
return Object.assign(Object.assign({}, this.transfomer.normalizePaths(lodash_1.flatten(denormalizedPaths))), { components: { | ||
return Object.assign(Object.assign({}, this.transformer.normalizePaths(lodash_1.flatten(denormalizedPaths))), { components: { | ||
schemas: schemas | ||
@@ -47,0 +48,0 @@ } }); |
@@ -0,4 +1,7 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { OpenAPIObject } from './interfaces'; | ||
import { ModuleRoute } from './interfaces/module-route.interface'; | ||
export declare class SwaggerTransformer { | ||
normalizePaths(denormalizedDoc: (Partial<OpenAPIObject> & Record<'root', any>)[]): Record<'paths', OpenAPIObject['paths']>; | ||
unescapeColonsInPath(app: INestApplication, moduleRoutes: ModuleRoute[]): ModuleRoute[]; | ||
} |
@@ -19,3 +19,11 @@ "use strict"; | ||
} | ||
unescapeColonsInPath(app, moduleRoutes) { | ||
const httpAdapter = app.getHttpAdapter(); | ||
const usingFastify = httpAdapter && httpAdapter.getType() === 'fastify'; | ||
const unescapeColon = usingFastify | ||
? (path) => path.replace(/:\{([^}]+)\}/g, ':$1') | ||
: (path) => path.replace(/\[:\]/g, ':'); | ||
return moduleRoutes.map((moduleRoute) => (Object.assign(Object.assign({}, moduleRoute), { root: Object.assign(Object.assign({}, moduleRoute.root), { path: unescapeColon(moduleRoute.root.path) }) }))); | ||
} | ||
} | ||
exports.SwaggerTransformer = SwaggerTransformer; |
{ | ||
"name": "@nestjs/swagger", | ||
"version": "5.2.0", | ||
"version": "5.2.1", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@swagger)", | ||
@@ -28,29 +28,29 @@ "author": "Kamil Mysliwiec", | ||
"devDependencies": { | ||
"@commitlint/cli": "16.1.0", | ||
"@commitlint/config-angular": "16.0.0", | ||
"@nestjs/common": "8.2.3", | ||
"@nestjs/core": "8.2.3", | ||
"@nestjs/platform-express": "8.2.3", | ||
"@nestjs/platform-fastify": "8.2.3", | ||
"@types/jest": "27.4.0", | ||
"@types/lodash": "4.14.178", | ||
"@types/node": "16.11.21", | ||
"@typescript-eslint/eslint-plugin": "5.10.1", | ||
"@typescript-eslint/parser": "5.10.1", | ||
"@commitlint/cli": "16.2.3", | ||
"@commitlint/config-angular": "16.2.3", | ||
"@nestjs/common": "8.4.2", | ||
"@nestjs/core": "8.4.2", | ||
"@nestjs/platform-express": "8.4.2", | ||
"@nestjs/platform-fastify": "8.4.2", | ||
"@types/jest": "27.4.1", | ||
"@types/lodash": "4.14.180", | ||
"@types/node": "16.11.26", | ||
"@typescript-eslint/eslint-plugin": "5.16.0", | ||
"@typescript-eslint/parser": "5.16.0", | ||
"class-transformer": "0.5.1", | ||
"class-validator": "0.13.2", | ||
"eslint": "8.7.0", | ||
"eslint-config-prettier": "8.3.0", | ||
"eslint": "8.11.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-import": "2.25.4", | ||
"express": "4.17.2", | ||
"fastify-swagger": "4.13.1", | ||
"express": "4.17.3", | ||
"fastify-swagger": "5.0.0", | ||
"husky": "7.0.4", | ||
"jest": "27.4.7", | ||
"lint-staged": "12.3.1", | ||
"prettier": "2.5.1", | ||
"jest": "27.5.1", | ||
"lint-staged": "12.3.7", | ||
"prettier": "2.6.1", | ||
"reflect-metadata": "0.1.13", | ||
"release-it": "14.12.4", | ||
"release-it": "14.13.1", | ||
"swagger-parser": "10.0.3", | ||
"swagger-ui-express": "4.3.0", | ||
"ts-jest": "27.1.3", | ||
"ts-jest": "27.1.4", | ||
"typescript": "4.3.5" | ||
@@ -57,0 +57,0 @@ }, |
@@ -6,2 +6,6 @@ 'use strict'; | ||
exports.__esModule = true; | ||
__export(require('./dist/plugin')); | ||
const plugin = require('./dist/plugin'); | ||
__export(plugin); | ||
/** Compatibility with ts-patch/ttypescript */ | ||
exports.default = (program, options) => plugin.before(options, program); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
250350
202
5098