@nestjs/swagger
Advanced tools
Comparing version 4.0.0 to 4.0.1
import { Type } from '@nestjs/common'; | ||
import { RequestBodyObject, SchemaObject } from '../interfaces/open-api-spec.interface'; | ||
import { SwaggerEnumType } from '../types/swagger-enum.type'; | ||
declare type RequestBodyOptions = Omit<RequestBodyObject, 'content'>; | ||
@@ -7,2 +8,3 @@ interface ApiBodyMetadata extends RequestBodyOptions { | ||
isArray?: boolean; | ||
enum?: SwaggerEnumType; | ||
} | ||
@@ -9,0 +11,0 @@ interface ApiBodySchemaHost extends RequestBodyOptions { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const lodash_1 = require("lodash"); | ||
const enum_utils_1 = require("../utils/enum.utils"); | ||
const helpers_1 = require("./helpers"); | ||
@@ -10,6 +12,12 @@ const defaultBodyMetadata = { | ||
const [type, isArray] = helpers_1.getTypeIsArrayTuple(options.type, options.isArray); | ||
const param = Object.assign(Object.assign({ in: 'body' }, options), { type, | ||
const param = Object.assign(Object.assign({ in: 'body' }, lodash_1.omit(options, 'enum')), { type, | ||
isArray }); | ||
if (enum_utils_1.isEnumArray(options)) { | ||
enum_utils_1.addEnumArraySchema(param, options); | ||
} | ||
else if (enum_utils_1.isEnumDefined(options)) { | ||
enum_utils_1.addEnumSchema(param, options); | ||
} | ||
return helpers_1.createParamDecorator(param, defaultBodyMetadata); | ||
} | ||
exports.ApiBody = ApiBody; |
@@ -10,22 +10,9 @@ "use strict"; | ||
}; | ||
const isEnumArray = (obj) => obj.isArray && obj.enum; | ||
function ApiQuery(options) { | ||
const param = Object.assign({ name: lodash_1.isNil(options.name) ? defaultQueryOptions.name : options.name, in: 'query' }, lodash_1.omit(options, 'enum')); | ||
if (isEnumArray(options)) { | ||
const paramSchema = param.schema || {}; | ||
param.schema = paramSchema; | ||
paramSchema.type = 'array'; | ||
delete param.isArray; | ||
const enumValues = enum_utils_1.getEnumValues(options.enum); | ||
paramSchema.items = { | ||
type: enum_utils_1.getEnumType(enumValues), | ||
enum: enumValues | ||
}; | ||
if (enum_utils_1.isEnumArray(options)) { | ||
enum_utils_1.addEnumArraySchema(param, options); | ||
} | ||
else if (options.enum) { | ||
const paramSchema = param.schema || {}; | ||
const enumValues = enum_utils_1.getEnumValues(options.enum); | ||
param.schema = paramSchema; | ||
paramSchema.enum = enumValues; | ||
paramSchema.type = enum_utils_1.getEnumType(enumValues); | ||
else if (enum_utils_1.isEnumDefined(options)) { | ||
enum_utils_1.addEnumSchema(param, options); | ||
} | ||
@@ -32,0 +19,0 @@ return helpers_1.createParamDecorator(param, defaultQueryOptions); |
@@ -1,1 +0,1 @@ | ||
export declare const BUILT_IN_TYPES: (StringConstructor | ArrayConstructor | ObjectConstructor | NumberConstructor | BooleanConstructor)[]; | ||
export declare const BUILT_IN_TYPES: (ArrayConstructor | StringConstructor | ObjectConstructor | NumberConstructor | BooleanConstructor)[]; |
@@ -15,3 +15,3 @@ import { BaseParameterObject } from '../interfaces/open-api-spec.interface'; | ||
hasSchemaDefinition(param: BaseParameterObject): param is BaseParameterObject; | ||
omitParamType(param: ParamWithTypeMetadata | BaseParameterObject): Partial<BaseParameterObject> | Partial<ParamWithTypeMetadata>; | ||
omitParamType(param: ParamWithTypeMetadata | BaseParameterObject): Pick<BaseParameterObject | ParamWithTypeMetadata, "required">; | ||
} |
import { SwaggerEnumType } from '../types/swagger-enum.type'; | ||
export declare function getEnumValues(enumType: SwaggerEnumType): string[] | number[]; | ||
export declare function getEnumType(values: (string | number)[]): 'string' | 'number'; | ||
export declare function addEnumArraySchema(paramDefinition: Record<'schema' | 'isArray', any>, decoratorOptions: Partial<Record<'enum', any>>): void; | ||
export declare function addEnumSchema(paramDefinition: Record<'schema', any>, decoratorOptions: Partial<Record<'enum', any>>): void; | ||
export declare const isEnumArray: <T extends Partial<Record<"isArray" | "enum", any>>>(obj: Record<string, any>) => obj is T; | ||
export declare const isEnumDefined: <T extends Partial<Record<"enum", any>>>(obj: Record<string, any>) => obj is T; |
@@ -29,1 +29,23 @@ "use strict"; | ||
exports.getEnumType = getEnumType; | ||
function addEnumArraySchema(paramDefinition, decoratorOptions) { | ||
const paramSchema = paramDefinition.schema || {}; | ||
paramDefinition.schema = paramSchema; | ||
paramSchema.type = 'array'; | ||
delete paramDefinition.isArray; | ||
const enumValues = getEnumValues(decoratorOptions.enum); | ||
paramSchema.items = { | ||
type: getEnumType(enumValues), | ||
enum: enumValues | ||
}; | ||
} | ||
exports.addEnumArraySchema = addEnumArraySchema; | ||
function addEnumSchema(paramDefinition, decoratorOptions) { | ||
const paramSchema = paramDefinition.schema || {}; | ||
const enumValues = getEnumValues(decoratorOptions.enum); | ||
paramDefinition.schema = paramSchema; | ||
paramSchema.enum = enumValues; | ||
paramSchema.type = getEnumType(enumValues); | ||
} | ||
exports.addEnumSchema = addEnumSchema; | ||
exports.isEnumArray = (obj) => obj.isArray && obj.enum; | ||
exports.isEnumDefined = (obj) => obj.enum; |
{ | ||
"name": "@nestjs/swagger", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@swagger)", | ||
@@ -21,3 +21,3 @@ "author": "Kamil Mysliwiec", | ||
"lodash": "4.17.15", | ||
"path-to-regexp": "3.1.0" | ||
"path-to-regexp": "6.1.0" | ||
}, | ||
@@ -29,5 +29,5 @@ "devDependencies": { | ||
"@types/jest": "24.0.23", | ||
"@types/lodash": "4.14.141", | ||
"@types/lodash": "4.14.149", | ||
"@types/node": "11.15.0", | ||
"express": "^4.17.1", | ||
"express": "4.17.1", | ||
"husky": "3.1.0", | ||
@@ -38,4 +38,4 @@ "jest": "24.9.0", | ||
"reflect-metadata": "0.1.13", | ||
"swagger-parser": "8.0.1", | ||
"swagger-ui-express": "4.1.1", | ||
"swagger-parser": "8.0.3", | ||
"swagger-ui-express": "4.1.2", | ||
"ts-jest": "24.2.0", | ||
@@ -42,0 +42,0 @@ "typescript": "3.7.2" |
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
151869
2928
+ Addedpath-to-regexp@6.1.0(transitive)
- Removedpath-to-regexp@3.1.0(transitive)
Updatedpath-to-regexp@6.1.0