diff --git a/e2e/api-spec.json b/e2e/api-spec.json index 476c0dcbf..734639f18 100644 --- a/e2e/api-spec.json +++ b/e2e/api-spec.json @@ -761,6 +761,56 @@ } ] } + }, + "/api/cats/with-enum/{type}": { + "get": { + "operationId": "CatsController_getWithEnumParam", + "parameters": [ + { + "name": "header", + "in": "header", + "description": "Test", + "required": false, + "schema": { + "default": "test", + "type": "string" + } + }, + { + "name": "type", + "required": true, + "in": "path", + "schema": { + "type": "string", + "enum": [ + "A", + "B", + "C" + ] + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "tags": [ + "cats" + ], + "security": [ + { + "key2": [], + "key1": [] + }, + { + "bearer": [] + }, + { + "basic": [] + } + ] + } } } } \ No newline at end of file diff --git a/e2e/src/cats/cats.controller.ts b/e2e/src/cats/cats.controller.ts index c60ddc601..9f7e8b79e 100644 --- a/e2e/src/cats/cats.controller.ts +++ b/e2e/src/cats/cats.controller.ts @@ -8,12 +8,13 @@ import { ApiQuery, ApiResponse, ApiSecurity, - ApiTags + ApiTags, + ApiParam } from '../../../lib'; import { CatsService } from './cats.service'; import { Cat } from './classes/cat.class'; import { CreateCatDto } from './dto/create-cat.dto'; -import { PaginationQuery } from './dto/pagination-query.dto'; +import { PaginationQuery, LettersEnum } from './dto/pagination-query.dto'; @ApiSecurity('basic') @ApiBearerAuth() @@ -87,4 +88,13 @@ export class CatsController { @Get('site*') getSite() {} + + + @Get("with-enum/:type") + @ApiParam({ + name: "type", + enum: LettersEnum, + enumName: "Letter" + }) + getWithEnumParam(@Param('type') type: LettersEnum) {} } diff --git a/lib/services/swagger-types-mapper.ts b/lib/services/swagger-types-mapper.ts index b8b42b1d3..e49545477 100644 --- a/lib/services/swagger-types-mapper.ts +++ b/lib/services/swagger-types-mapper.ts @@ -8,12 +8,22 @@ import { import { ParamWithTypeMetadata } from './parameter-metadata-accessor'; export class SwaggerTypesMapper { + private readonly keysToRemove: Array = [ + 'type', + 'isArray', + 'enum', + 'enumName', + 'items', + '$ref', + ...this.getSchemaOptionsKeys() + ] + mapParamTypes( parameters: Array ) { return parameters.map((param) => { if (this.hasSchemaDefinition(param as BaseParameterObject)) { - return this.omitParamType(param); + return this.omitParamKeys(param); } const { type } = param as ParamWithTypeMetadata; const typeName = @@ -29,27 +39,19 @@ export class SwaggerTypesMapper { isUndefined ); - const keysToRemove: Array = [ - 'type', - 'isArray', - 'enum', - 'items', - '$ref', - ...this.getSchemaOptionsKeys() - ]; if (this.isEnumArrayType(paramWithTypeMetadata)) { return this.mapEnumArrayType( paramWithTypeMetadata as ParamWithTypeMetadata, - keysToRemove + this.keysToRemove ); } else if (paramWithTypeMetadata.isArray) { return this.mapArrayType( paramWithTypeMetadata as ParamWithTypeMetadata, - keysToRemove + this.keysToRemove ); } return { - ...omit(param, keysToRemove), + ...omit(param, this.keysToRemove), schema: omitBy( { ...this.getSchemaOptions(param), @@ -131,8 +133,8 @@ export class SwaggerTypesMapper { return !!param.schema; } - private omitParamType(param: ParamWithTypeMetadata | BaseParameterObject) { - return omit(param, 'type'); + private omitParamKeys(param: ParamWithTypeMetadata | BaseParameterObject) { + return omit(param, this.keysToRemove); } private getSchemaOptionsKeys(): Array {