Socket
Socket
Sign inDemoInstall

@nestjs/swagger

Package Overview
Dependencies
Maintainers
2
Versions
206
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs/swagger - npm Package Compare versions

Comparing version 7.0.5 to 7.0.6

2

dist/plugin/utils/ast-utils.d.ts

@@ -23,3 +23,3 @@ import * as ts from 'typescript';

export declare function createBooleanLiteral(factory: ts.NodeFactory, flag: boolean): ts.BooleanLiteral;
export declare function createPrimitiveLiteral(factory: ts.NodeFactory, item: unknown): ts.StringLiteral | ts.NumericLiteral | ts.BooleanLiteral;
export declare function createPrimitiveLiteral(factory: ts.NodeFactory, item: unknown, typeOfItem?: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"): ts.StringLiteral | ts.NumericLiteral | ts.BooleanLiteral | ts.PrefixUnaryExpression;
export declare function createLiteralFromAnyValue(factory: ts.NodeFactory, item: unknown): any;

@@ -207,9 +207,12 @@ "use strict";

exports.createBooleanLiteral = createBooleanLiteral;
function createPrimitiveLiteral(factory, item) {
const typeOfItem = typeof item;
function createPrimitiveLiteral(factory, item, typeOfItem = typeof item) {
switch (typeOfItem) {
case 'boolean':
return createBooleanLiteral(factory, item);
case 'number':
case 'number': {
if (item < 0) {
return factory.createPrefixUnaryExpression(typescript_1.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(item)));
}
return factory.createNumericLiteral(item);
}
case 'string':

@@ -216,0 +219,0 @@ return factory.createStringLiteral(item);

@@ -29,1 +29,2 @@ import * as ts from 'typescript';

export declare function convertPath(windowsPath: string): string;
export declare function canReferenceNode(node: ts.Node, options: PluginOptions): boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertPath = exports.extractTypeArgumentIfArray = exports.isAutoGeneratedTypeUnion = exports.isAutoGeneratedEnumUnion = exports.isDynamicallyAdded = exports.insertAt = exports.replaceImportPath = exports.hasPropertyKey = exports.isPromiseOrObservable = exports.getTypeReferenceAsString = exports.getDecoratorOrUndefinedByNames = void 0;
exports.canReferenceNode = exports.convertPath = exports.extractTypeArgumentIfArray = exports.isAutoGeneratedTypeUnion = exports.isAutoGeneratedEnumUnion = exports.isDynamicallyAdded = exports.insertAt = exports.replaceImportPath = exports.hasPropertyKey = exports.isPromiseOrObservable = exports.getTypeReferenceAsString = exports.getDecoratorOrUndefinedByNames = void 0;
const lodash_1 = require("lodash");

@@ -250,1 +250,11 @@ const path_1 = require("path");

exports.convertPath = convertPath;
function canReferenceNode(node, options) {
if (!options.readonly) {
return true;
}
if (ts.isIdentifier(node) || ts.isCallExpression(node)) {
return false;
}
return true;
}
exports.canReferenceNode = canReferenceNode;

@@ -21,5 +21,5 @@ import * as ts from 'typescript';

createEnumPropertyAssignment(factory: ts.NodeFactory, node: ts.PropertyDeclaration | ts.PropertySignature, typeChecker: ts.TypeChecker, existingProperties: ts.NodeArray<ts.PropertyAssignment>, hostFilename: string, options: PluginOptions): ts.PropertyAssignment | ts.PropertyAssignment[];
createDefaultPropertyAssignment(factory: ts.NodeFactory, node: ts.PropertyDeclaration | ts.PropertySignature, existingProperties: ts.NodeArray<ts.PropertyAssignment>): ts.PropertyAssignment;
createValidationPropertyAssignments(factory: ts.NodeFactory, node: ts.PropertyDeclaration | ts.PropertySignature): ts.PropertyAssignment[];
addPropertyByValidationDecorator(factory: ts.NodeFactory, decoratorName: string, propertyKey: string, decorators: readonly ts.Decorator[], assignments: ts.PropertyAssignment[]): void;
createDefaultPropertyAssignment(factory: ts.NodeFactory, node: ts.PropertyDeclaration | ts.PropertySignature, existingProperties: ts.NodeArray<ts.PropertyAssignment>, options: PluginOptions): ts.PropertyAssignment;
createValidationPropertyAssignments(factory: ts.NodeFactory, node: ts.PropertyDeclaration | ts.PropertySignature, options: PluginOptions): ts.PropertyAssignment[];
addPropertyByValidationDecorator(factory: ts.NodeFactory, decoratorName: string, propertyKey: string, decorators: readonly ts.Decorator[], assignments: ts.PropertyAssignment[], options: PluginOptions): void;
addPropertiesByValidationDecorator(factory: ts.NodeFactory, decoratorName: string, decorators: readonly ts.Decorator[], assignments: ts.PropertyAssignment[], addPropertyAssignments: (decoratorRef: ts.Decorator) => PropertyAssignment[]): void;

@@ -31,3 +31,5 @@ addClassMetadata(node: ts.PropertyDeclaration, objectLiteral: ts.ObjectLiteralExpression, sourceFile: ts.SourceFile, metadata: ClassMetadata): void;

private wrapTypeInArray;
private clonePrimitiveLiteral;
private getInitializerPrimitiveTypeName;
}
export {};

@@ -107,3 +107,3 @@ "use strict";

const isRequired = !node.questionToken;
let properties = [
const properties = [
...existingProperties,

@@ -114,7 +114,7 @@ !(0, plugin_utils_1.hasPropertyKey)('required', existingProperties) &&

...this.createDescriptionAndTsDocTagPropertyAssigments(factory, node, typeChecker, existingProperties, options, sourceFile),
this.createDefaultPropertyAssignment(factory, node, existingProperties),
this.createDefaultPropertyAssignment(factory, node, existingProperties, options),
this.createEnumPropertyAssignment(factory, node, typeChecker, existingProperties, hostFilename, options)
];
if (options.classValidatorShim) {
properties = properties.concat(this.createValidationPropertyAssignments(factory, node));
properties.push(this.createValidationPropertyAssignments(factory, node, options));
}

@@ -210,3 +210,3 @@ return factory.createObjectLiteralExpression((0, lodash_1.compact)((0, lodash_1.flatten)(properties)));

}
createDefaultPropertyAssignment(factory, node, existingProperties) {
createDefaultPropertyAssignment(factory, node, existingProperties, options) {
const key = 'default';

@@ -223,12 +223,19 @@ if ((0, plugin_utils_1.hasPropertyKey)(key, existingProperties)) {

}
initializer =
this.clonePrimitiveLiteral(factory, initializer) ?? initializer;
if (!(0, plugin_utils_1.canReferenceNode)(initializer, options)) {
return undefined;
}
return factory.createPropertyAssignment(key, initializer);
}
createValidationPropertyAssignments(factory, node) {
createValidationPropertyAssignments(factory, node, options) {
const assignments = [];
const decorators = ts.canHaveDecorators(node) && ts.getDecorators(node);
this.addPropertyByValidationDecorator(factory, 'IsIn', 'enum', decorators, assignments);
this.addPropertyByValidationDecorator(factory, 'Min', 'minimum', decorators, assignments);
this.addPropertyByValidationDecorator(factory, 'Max', 'maximum', decorators, assignments);
this.addPropertyByValidationDecorator(factory, 'MinLength', 'minLength', decorators, assignments);
this.addPropertyByValidationDecorator(factory, 'MaxLength', 'maxLength', decorators, assignments);
if (!options.readonly) {
this.addPropertyByValidationDecorator(factory, 'IsIn', 'enum', decorators, assignments, options);
}
this.addPropertyByValidationDecorator(factory, 'Min', 'minimum', decorators, assignments, options);
this.addPropertyByValidationDecorator(factory, 'Max', 'maximum', decorators, assignments, options);
this.addPropertyByValidationDecorator(factory, 'MinLength', 'minLength', decorators, assignments, options);
this.addPropertyByValidationDecorator(factory, 'MaxLength', 'maxLength', decorators, assignments, options);
this.addPropertiesByValidationDecorator(factory, 'IsPositive', decorators, assignments, () => {

@@ -247,5 +254,19 @@ return [

const result = [];
result.push(factory.createPropertyAssignment('minLength', (0, lodash_1.head)(decoratorArguments)));
const minLength = (0, lodash_1.head)(decoratorArguments);
if (!(0, plugin_utils_1.canReferenceNode)(minLength, options)) {
return result;
}
const clonedMinLength = this.clonePrimitiveLiteral(factory, minLength);
if (clonedMinLength) {
result.push(factory.createPropertyAssignment('minLength', clonedMinLength));
}
if (decoratorArguments.length > 1) {
result.push(factory.createPropertyAssignment('maxLength', decoratorArguments[1]));
const maxLength = decoratorArguments[1];
if (!(0, plugin_utils_1.canReferenceNode)(maxLength, options)) {
return result;
}
const clonedMaxLength = this.clonePrimitiveLiteral(factory, maxLength);
if (clonedMaxLength) {
result.push(factory.createPropertyAssignment('maxLength', clonedMaxLength));
}
}

@@ -262,14 +283,10 @@ return result;

}
addPropertyByValidationDecorator(factory, decoratorName, propertyKey, decorators, assignments) {
addPropertyByValidationDecorator(factory, decoratorName, propertyKey, decorators, assignments, options) {
this.addPropertiesByValidationDecorator(factory, decoratorName, decorators, assignments, (decoratorRef) => {
const argument = (0, lodash_1.head)((0, ast_utils_1.getDecoratorArguments)(decoratorRef));
const assignment = ts.isNumericLiteral(argument)
? ts.factory.createNumericLiteral(argument.text)
: ts.isStringLiteral(argument)
? ts.factory.createStringLiteral(argument.text)
: argument;
if (assignment) {
return [factory.createPropertyAssignment(propertyKey, assignment)];
const assignment = this.clonePrimitiveLiteral(factory, argument) ?? argument;
if (!(0, plugin_utils_1.canReferenceNode)(assignment, options)) {
return [];
}
return [];
return [factory.createPropertyAssignment(propertyKey, assignment)];
});

@@ -361,3 +378,23 @@ }

}
clonePrimitiveLiteral(factory, node) {
const primitiveTypeName = this.getInitializerPrimitiveTypeName(node);
if (!primitiveTypeName) {
return undefined;
}
return (0, ast_utils_1.createPrimitiveLiteral)(factory, node.getText(), primitiveTypeName);
}
getInitializerPrimitiveTypeName(node) {
if (ts.isIdentifier(node) &&
(node.text === 'true' || node.text === 'false')) {
return 'boolean';
}
if (ts.isNumericLiteral(node) || ts.isPrefixUnaryExpression(node)) {
return 'number';
}
if (ts.isStringLiteral(node)) {
return 'string';
}
return undefined;
}
}
exports.ModelClassVisitor = ModelClassVisitor;
{
"name": "@nestjs/swagger",
"version": "7.0.5",
"version": "7.0.6",
"description": "Nest - modern, fast, powerful node.js web framework (@swagger)",

@@ -5,0 +5,0 @@ "author": "Kamil Mysliwiec",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc