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AO,CAAC,uBAAuB;IAmG/B,OAAO,CAAC,2BAA2B;IAgEnC,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,eAAe;IA8BvB,OAAO,CAAC,qBAAqB;IAgC7B,OAAO,CAAC,QAAQ;CAGnB","file":"swagger.service.d.ts","sourcesContent":["import * as assert from 'assert';\nimport * as _ from 'lodash';\nimport { IApiModelArgs } from '.';\nimport { IApiModelPropertyArgs } from './api-model-property.decorator';\nimport { IApiOperationGetArgs } from './api-operation-get.decorator';\nimport { IApiOperationPostArgs } from './api-operation-post.decorator';\nimport { IApiPathArgs } from './api-path.decorator';\nimport {\n    IApiBodyOperationArgsBaseParameter,\n    IApiOperationArgsBase,\n    IApiOperationArgsBaseParameter,\n    IApiOperationArgsBaseResponse,\n} from './i-api-operation-args.base';\nimport {\n    ISwagger,\n    ISwaggerDefinition,\n    ISwaggerDefinitionProperty,\n    ISwaggerDefinitionPropertyItems,\n    ISwaggerExternalDocs,\n    ISwaggerInfo,\n    ISwaggerOperation,\n    ISwaggerOperationParameter,\n    ISwaggerOperationResponse,\n    ISwaggerOperationSchema,\n    ISwaggerOperationSchemaItems,\n    ISwaggerPath,\n    ISwaggerPropertySchemaOperation,\n    ISwaggerTag,\n} from './i-swagger';\nimport { SwaggerDefinitionConstant } from './swagger-definition.constant';\nimport {\n    ISwaggerBuildDefinitionModel,\n    ISwaggerBuildDefinitionModelProperty,\n    ISwaggerSecurityDefinition,\n} from './swagger.builder';\n\ninterface IPath {\n    path: string;\n    get?: ISwaggerOperation;\n    post?: ISwaggerOperation;\n    put?: ISwaggerOperation;\n    patch?: ISwaggerOperation;\n    delete?: ISwaggerOperation;\n}\n\ninterface IController {\n    path?: string;\n    paths?: { [key: string]: IPath };\n    name?: string;\n    description?: string;\n    security?: { [key: string]: any[] };\n    deprecated?: boolean;\n}\n\nexport class SwaggerService {\n    public static getInstance(): SwaggerService {\n        if (!SwaggerService.instance) {\n            const newSwaggerService: SwaggerService = new SwaggerService();\n            newSwaggerService.initData();\n            SwaggerService.instance = newSwaggerService;\n        }\n        return SwaggerService.instance;\n    }\n    private static instance: SwaggerService;\n    private controllerMap: IController[] = [];\n    private data: ISwagger;\n    private modelsMap: { [key: string]: ISwaggerBuildDefinitionModel } = {};\n    private globalResponses: { [key: string]: IApiOperationArgsBaseResponse };\n\n    public resetData(): void {\n        this.controllerMap = [];\n        this.initData();\n    }\n\n    public getData(): ISwagger {\n        return _.cloneDeep(this.data);\n    }\n\n    public setBasePath(basePath: string): void {\n        this.data.basePath = basePath;\n    }\n\n    public setOpenapi(openapi: string): void {\n        this.data.openapi = openapi;\n    }\n\n    public setInfo(info: ISwaggerInfo): void {\n        this.data.info = info;\n    }\n\n    public setSchemes(schemes: string[]): void {\n        this.data.schemes = schemes;\n    }\n\n    public setProduces(produces: string[]): void {\n        this.data.produces = produces;\n    }\n\n    public setConsumes(consumes: string[]): void {\n        this.data.consumes = consumes;\n    }\n\n    public setHost(host: string): void {\n        this.data.host = host;\n    }\n\n    public setDefinitions(models: {\n        [key: string]: ISwaggerBuildDefinitionModel;\n    }): void {\n        const definitions: { [key: string]: ISwaggerDefinition } = {};\n        for (const modelIndex in models) {\n            const model: ISwaggerBuildDefinitionModel = models[modelIndex];\n            const newDefinition: ISwaggerDefinition = {\n                type: SwaggerDefinitionConstant.Model.Type.OBJECT,\n                properties: {},\n                required: [],\n            };\n            if (model.description) {\n                newDefinition.description = model.description;\n            }\n            for (const propertyIndex in model.properties) {\n                const property: ISwaggerBuildDefinitionModelProperty =\n                    model.properties[propertyIndex];\n                const newProperty: ISwaggerDefinitionProperty = {\n                    type: property.type,\n                };\n                newProperty.format = property.format;\n                newProperty.description = property.description;\n                newProperty.enum = property.enum;\n                newProperty.example = property.example;\n                if (property.itemType) {\n                    newProperty.items = {\n                        type: property.itemType,\n                    } as ISwaggerDefinitionPropertyItems;\n                }\n                if (property.model) {\n                    if (\n                        _.isEqual(\n                            SwaggerDefinitionConstant.Model.Property.Type.ARRAY,\n                            property.type\n                        )\n                    ) {\n                        newProperty.items = {\n                            $ref: this.buildRef(property.model),\n                        } as ISwaggerDefinitionPropertyItems;\n                    } else {\n                        newProperty.$ref = this.buildRef(property.model);\n                    }\n                }\n                if (property.required) {\n                    newDefinition.required.push(propertyIndex);\n                }\n                newDefinition.properties[propertyIndex] = newProperty;\n            }\n            definitions[modelIndex] = newDefinition;\n        }\n        this.data.definitions = _.mergeWith(this.data.definitions, definitions);\n    }\n\n    public setExternalDocs(externalDocs: ISwaggerExternalDocs): void {\n        this.data.externalDocs = externalDocs;\n    }\n\n    public setGlobalResponses(globalResponses: {\n        [key: string]: IApiOperationArgsBaseResponse;\n    }): void {\n        this.globalResponses = this.buildOperationResponses(globalResponses);\n    }\n\n    public addPath(args: IApiPathArgs, target: any): void {\n        let currentController: IController = {\n            path: args.path,\n            name: args.name,\n            paths: {},\n        };\n        for (const controllerIndex in this.controllerMap) {\n            const controller: IController = this.controllerMap[controllerIndex];\n            if (controllerIndex === target.name) {\n                currentController = controller;\n                currentController.path = args.path;\n                currentController.name = args.name;\n                currentController.description = args.description;\n                currentController.security = args.security;\n                currentController.deprecated = args.deprecated;\n            }\n        }\n        this.controllerMap[target.name] = _.mergeWith(\n            this.controllerMap[target.name],\n            currentController\n        );\n    }\n\n    public addOperationGet(\n        args: IApiOperationGetArgs,\n        target: any,\n        propertyKey: string | symbol\n    ): void {\n        assert.ok(args, 'Args are required.');\n        assert.ok(args.responses, 'Responses are required.');\n        if (args.parameters) {\n            assert.ok(!args.parameters.body, 'Parameter body is not required.');\n        }\n        this.addOperation('get', args, target, propertyKey);\n    }\n\n    public addOperationPost(\n        args: IApiOperationPostArgs,\n        target: any,\n        propertyKey: string | symbol\n    ): void {\n        assert.ok(args, 'Args are required.');\n        assert.ok(args.parameters, 'Parameters are required.');\n        assert.ok(args.responses, 'Responses are required.');\n        this.addOperation('post', args, target, propertyKey);\n    }\n\n    public addOperationPut(\n        args: IApiOperationPostArgs,\n        target: any,\n        propertyKey: string | symbol\n    ): void {\n        assert.ok(args, 'Args are required.');\n        assert.ok(args.parameters, 'Parameters are required.');\n        assert.ok(args.responses, 'Responses are required.');\n        this.addOperation('put', args, target, propertyKey);\n    }\n\n    public addOperationPatch(\n        args: IApiOperationPostArgs,\n        target: any,\n        propertyKey: string | symbol\n    ): void {\n        assert.ok(args, 'Args are required.');\n        assert.ok(args.parameters, 'Parameters are required.');\n        assert.ok(args.responses, 'Responses are required.');\n        this.addOperation('patch', args, target, propertyKey);\n    }\n\n    public addOperationDelete(\n        args: IApiOperationPostArgs,\n        target: any,\n        propertyKey: string | symbol\n    ): void {\n        assert.ok(args, 'Args are required.');\n        assert.ok(args.parameters, 'Parameters are required.');\n        assert.ok(!args.parameters.body, 'Parameter body is not required.');\n        assert.ok(args.responses, 'Responses are required.');\n        this.addOperation('delete', args, target, propertyKey);\n    }\n\n    public addSecurityDefinitions(securityDefinitions: {\n        [key: string]: ISwaggerSecurityDefinition;\n    }): void {\n        this.data.securityDefinitions = securityDefinitions;\n    }\n\n    public buildSwagger(): void {\n        const data: ISwagger = _.cloneDeep(this.data);\n        for (const controllerIndex in this.controllerMap) {\n            const controller: IController = this.controllerMap[controllerIndex];\n            if (_.toArray(controller.paths).length > 0) {\n                for (const pathIndex in controller.paths) {\n                    const path: IPath = controller.paths[pathIndex];\n                    const swaggerPath: ISwaggerPath = {};\n                    if (path.get) {\n                        swaggerPath.get = this.buildSwaggerOperation(\n                            path.get,\n                            controller\n                        );\n                    }\n                    if (path.post) {\n                        swaggerPath.post = this.buildSwaggerOperation(\n                            path.post,\n                            controller\n                        );\n                    }\n                    if (path.put) {\n                        swaggerPath.put = this.buildSwaggerOperation(\n                            path.put,\n                            controller\n                        );\n                    }\n                    if (path.patch) {\n                        swaggerPath.patch = this.buildSwaggerOperation(\n                            path.patch,\n                            controller\n                        );\n                    }\n                    if (path.delete) {\n                        swaggerPath.delete = this.buildSwaggerOperation(\n                            path.delete,\n                            controller\n                        );\n                    }\n                    if (path.path && path.path.length > 0) {\n                        data.paths[\n                            controller.path.concat(path.path)\n                        ] = swaggerPath;\n                    } else {\n                        data.paths[controller.path] = swaggerPath;\n                    }\n                }\n            } else {\n                const swaggerPath: ISwaggerPath = {};\n                data.paths[controller.path] = swaggerPath;\n            }\n\n            if (!_.find(data.tags, (tag: ISwaggerTag) => tag.name === _.upperFirst(controller.name))) {\n              data.tags.push({\n                  name: _.upperFirst(controller.name),\n                  description: controller.description,\n              } as ISwaggerTag);\n            }\n        }\n        this.data = data;\n    }\n\n    public addApiModelProperty(\n        args: IApiModelPropertyArgs,\n        target: any,\n        propertyKey: string | symbol,\n        propertyType: string\n    ) {\n        const definitionKey = target.constructor.name;\n        let swaggerBuildDefinitionModel: ISwaggerBuildDefinitionModel = this\n            .modelsMap[definitionKey];\n        if (!swaggerBuildDefinitionModel) {\n            swaggerBuildDefinitionModel = {\n                properties: {},\n            };\n            this.modelsMap[definitionKey] = swaggerBuildDefinitionModel;\n        }\n\n        const swaggerBuildDefinitionModelProperty: ISwaggerBuildDefinitionModelProperty = {\n            type: _.lowerCase(propertyType),\n        };\n        if (args) {\n            swaggerBuildDefinitionModelProperty.required = args.required;\n            swaggerBuildDefinitionModelProperty.description = args.description;\n            swaggerBuildDefinitionModelProperty.enum = args.enum;\n            swaggerBuildDefinitionModelProperty.itemType = args.itemType;\n            swaggerBuildDefinitionModelProperty.example = args.example;\n            swaggerBuildDefinitionModelProperty.format = args.format;\n            if (args.model) {\n                swaggerBuildDefinitionModelProperty.model = args.model;\n                if (!_.isEqual('Array', propertyType)) {\n                    swaggerBuildDefinitionModelProperty.type = undefined;\n                }\n            }\n            if (args.type) {\n                swaggerBuildDefinitionModelProperty.type = args.type;\n            }\n        }\n        swaggerBuildDefinitionModel.properties[\n            propertyKey.toString()\n        ] = swaggerBuildDefinitionModelProperty;\n        this.setDefinitions(this.modelsMap);\n    }\n\n    public addApiModel(args: IApiModelArgs, target: any): any {\n        const definitionKey = target.name;\n        let swaggerBuildDefinitionModel: ISwaggerBuildDefinitionModel = this\n            .modelsMap[definitionKey];\n        if (!swaggerBuildDefinitionModel) {\n            swaggerBuildDefinitionModel = {\n                properties: {},\n            };\n            this.modelsMap[definitionKey] = swaggerBuildDefinitionModel;\n        }\n        if (args) {\n            swaggerBuildDefinitionModel.description = args.description;\n            if (args.name) {\n                const name: string = _.upperFirst(args.name);\n                this.modelsMap[name] = _.cloneDeep(\n                    this.modelsMap[definitionKey]\n                );\n                if (!_.isEqual(name, definitionKey)) {\n                    delete this.modelsMap[definitionKey];\n                    delete this.data.definitions[definitionKey];\n                }\n            }\n        }\n        this.setDefinitions(this.modelsMap);\n    }\n\n    private initData(): void {\n        this.data = {\n            basePath: '/',\n            info: {\n                title: '',\n                version: '',\n            } as ISwaggerInfo,\n            paths: {},\n            tags: [],\n            schemes: [SwaggerDefinitionConstant.Scheme.HTTP],\n            produces: [SwaggerDefinitionConstant.Produce.JSON],\n            consumes: [SwaggerDefinitionConstant.Consume.JSON],\n            definitions: {},\n            swagger: '2.0',\n        };\n    }\n\n    private addOperation(\n        operation: string,\n        args: IApiOperationArgsBase,\n        target: any,\n        propertyKey: string | symbol\n    ): void {\n        let currentController: IController = {\n            paths: {},\n        };\n        for (const index in this.controllerMap) {\n            const controller = this.controllerMap[index];\n            if (index === target.constructor.name) {\n                currentController = controller;\n            }\n        }\n\n        let currentPath: IPath;\n        if (args.path && args.path.length > 0) {\n            if (!currentController.paths[args.path]) {\n                currentController.paths[args.path] = {} as IPath;\n            }\n            currentPath = currentController.paths[args.path];\n            currentPath.path = args.path;\n        } else {\n            if (!currentController.paths['/']) {\n                currentController.paths['/'] = {} as IPath;\n            }\n            currentPath = currentController.paths['/'];\n        }\n\n        if ('get' === operation) {\n            currentPath.get = this.buildOperation(args, target, propertyKey);\n        }\n\n        if ('post' === operation) {\n            currentPath.post = this.buildOperation(args, target, propertyKey);\n        }\n\n        if ('put' === operation) {\n            currentPath.put = this.buildOperation(args, target, propertyKey);\n        }\n\n        if ('patch' === operation) {\n            currentPath.patch = this.buildOperation(args, target, propertyKey);\n        }\n\n        if ('delete' === operation) {\n            currentPath.delete = this.buildOperation(args, target, propertyKey);\n        }\n\n        this.controllerMap[target.constructor.name] = currentController;\n    }\n\n    private buildOperation(\n        args: IApiOperationArgsBase,\n        target: any,\n        propertyKey: string | symbol\n    ): ISwaggerOperation {\n        const operation: ISwaggerOperation = {\n            operationId: propertyKey,\n            tags: [],\n        };\n        if (args.description) {\n            operation.description = args.description;\n        }\n        if (args.summary) {\n            operation.summary = args.summary;\n        }\n        if (args.produces && args.produces.length > 0) {\n            operation.produces = args.produces;\n        }\n\n        if (args.consumes && args.consumes.length > 0) {\n            operation.consumes = args.consumes;\n        }\n\n        if (args.tags && args.tags.length > 0) {\n            operation.tags = args.tags;\n        }\n\n        if (args.deprecated) {\n            operation.deprecated = args.deprecated;\n        }\n\n        if (args.parameters) {\n            operation.parameters = [];\n            if (args.parameters.header) {\n                operation.parameters = _.concat(\n                    operation.parameters,\n                    this.buildParameters(\n                        SwaggerDefinitionConstant.Parameter.In.HEADER,\n                        args.parameters.header\n                    )\n                );\n            }\n            if (args.parameters.path) {\n                operation.parameters = _.concat(\n                    operation.parameters,\n                    this.buildParameters(\n                        SwaggerDefinitionConstant.Parameter.In.PATH,\n                        args.parameters.path\n                    )\n                );\n            }\n            if (args.parameters.query) {\n                operation.parameters = _.concat(\n                    operation.parameters,\n                    this.buildParameters(\n                        SwaggerDefinitionConstant.Parameter.In.QUERY,\n                        args.parameters.query\n                    )\n                );\n            }\n            if (args.parameters.body) {\n                operation.parameters = _.concat(\n                    operation.parameters,\n                    this.buildBodyOperationParameter(args.parameters.body)\n                );\n            }\n            if (args.parameters.formData) {\n                operation.parameters = _.concat(\n                    operation.parameters,\n                    this.buildParameters(\n                        SwaggerDefinitionConstant.Parameter.In.FORM_DATA,\n                        args.parameters.formData\n                    )\n                );\n            }\n        }\n\n        if (args.responses) {\n            operation.responses = this.buildOperationResponses(args.responses);\n        }\n\n        if (args.security) {\n            operation.security = this.buildOperationSecurity(args.security);\n        }\n\n        return operation;\n    }\n\n    private buildOperationResponses(responses: {\n        [key: string]: IApiOperationArgsBaseResponse;\n    }): {\n        [key: string]: ISwaggerOperationResponse;\n    } {\n        const swaggerOperationResponses: {\n            [key: string]: ISwaggerOperationResponse;\n        } = {};\n        for (const responseIndex in responses) {\n            const response: IApiOperationArgsBaseResponse =\n                responses[responseIndex];\n            const newSwaggerOperationResponse: ISwaggerOperationResponse = {};\n            if (response.description) {\n                newSwaggerOperationResponse.description = response.description;\n            } else {\n                switch (responseIndex) {\n                    case '200':\n                        newSwaggerOperationResponse.description = 'Success';\n                        break;\n                    case '201':\n                        newSwaggerOperationResponse.description = 'Created';\n                        break;\n                    case '202':\n                        newSwaggerOperationResponse.description = 'Accepted';\n                        break;\n                    case '203':\n                        newSwaggerOperationResponse.description =\n                            'Non-Authoritative Information';\n                        break;\n                    case '204':\n                        newSwaggerOperationResponse.description = 'No Content';\n                        break;\n                    case '205':\n                        newSwaggerOperationResponse.description =\n                            'Reset Content';\n                        break;\n                    case '206':\n                        newSwaggerOperationResponse.description =\n                            'Partial Content';\n                        break;\n                    case '400':\n                        newSwaggerOperationResponse.description =\n                            'Client error and Bad Request';\n                        break;\n                    case '401':\n                        newSwaggerOperationResponse.description =\n                            'Client error and Unauthorized';\n                        break;\n                    case '404':\n                        newSwaggerOperationResponse.description =\n                            'Client error and Not Found';\n                        break;\n                    case '406':\n                        newSwaggerOperationResponse.description =\n                            'Client error and Not Acceptable';\n                        break;\n                    case '500':\n                        newSwaggerOperationResponse.description =\n                            'Internal Server Error';\n                        break;\n                    case '501':\n                        newSwaggerOperationResponse.description =\n                            'Not Implemented';\n                        break;\n                    case '503':\n                        newSwaggerOperationResponse.description =\n                            'Service Unavailable';\n                        break;\n                    default:\n                        newSwaggerOperationResponse.description = null;\n                }\n            }\n            if (response.model) {\n                const ref = this.buildRef(response.model);\n                let newSwaggerOperationResponseSchema: ISwaggerOperationSchema = {\n                    $ref: ref,\n                };\n                if (\n                    _.isEqual(\n                        response.type,\n                        SwaggerDefinitionConstant.Response.Type.ARRAY\n                    )\n                ) {\n                    newSwaggerOperationResponseSchema = {\n                        items: {\n                            $ref: ref,\n                        } as ISwaggerOperationSchemaItems,\n                        type: SwaggerDefinitionConstant.Response.Type.ARRAY,\n                    };\n                }\n                newSwaggerOperationResponse.schema = newSwaggerOperationResponseSchema;\n            }\n            swaggerOperationResponses[\n                responseIndex\n            ] = newSwaggerOperationResponse;\n        }\n        return swaggerOperationResponses;\n    }\n\n    private buildBodyOperationParameter(\n        bodyOperationArgsBaseParameter: IApiBodyOperationArgsBaseParameter\n    ): ISwaggerOperationParameter[] {\n        const swaggerOperationParameterList: ISwaggerOperationParameter[] = [];\n        const swaggerOperationParameter = {} as ISwaggerOperationParameter;\n        swaggerOperationParameter.name = bodyOperationArgsBaseParameter.name\n            ? bodyOperationArgsBaseParameter.name\n            : 'body';\n        swaggerOperationParameter.in = 'body';\n        swaggerOperationParameter.type = bodyOperationArgsBaseParameter.type;\n        swaggerOperationParameter.description =\n            bodyOperationArgsBaseParameter.description;\n        swaggerOperationParameter.required =\n            bodyOperationArgsBaseParameter.required;\n        swaggerOperationParameter.format =\n            bodyOperationArgsBaseParameter.format;\n        swaggerOperationParameter.deprecated =\n            bodyOperationArgsBaseParameter.deprecated;\n        swaggerOperationParameter.allowEmptyValue =\n            bodyOperationArgsBaseParameter.allowEmptyValue;\n        swaggerOperationParameter.minimum =\n            bodyOperationArgsBaseParameter.minimum;\n        swaggerOperationParameter.maximum =\n            bodyOperationArgsBaseParameter.maximum;\n        swaggerOperationParameter.default =\n            bodyOperationArgsBaseParameter.default;\n        let schema = {} as ISwaggerOperationSchema;\n        if (bodyOperationArgsBaseParameter.properties) {\n            schema.type = 'object';\n            schema.required = [];\n            schema.properties = {} as {\n                [key: string]: ISwaggerPropertySchemaOperation;\n            };\n            for (const propetyIndex in bodyOperationArgsBaseParameter.properties) {\n                const propertyBodyOperationArgsBaseParameter =\n                    bodyOperationArgsBaseParameter.properties[propetyIndex];\n                const propertySchemaOperation = {} as ISwaggerPropertySchemaOperation;\n                propertySchemaOperation.type =\n                    propertyBodyOperationArgsBaseParameter.type;\n                schema.properties[propetyIndex] = propertySchemaOperation;\n                if (propertyBodyOperationArgsBaseParameter.required) {\n                    schema.required.push(propetyIndex);\n                }\n            }\n        }\n        if (bodyOperationArgsBaseParameter.model) {\n            const swaggerOperationSchema: ISwaggerOperationSchema = {\n                $ref: this.buildRef(bodyOperationArgsBaseParameter.model),\n            };\n\n            if (bodyOperationArgsBaseParameter.type !== 'array') {\n                schema = swaggerOperationSchema;\n            } else {\n                schema.type = bodyOperationArgsBaseParameter.type;\n                schema.items = {\n                    $ref: this.buildRef(bodyOperationArgsBaseParameter.model),\n                };\n            }\n        }\n        swaggerOperationParameter.schema = schema;\n        swaggerOperationParameterList.push(swaggerOperationParameter);\n        return swaggerOperationParameterList;\n    }\n\n    private buildOperationSecurity(argsSecurity: {\n        [key: string]: any[];\n    }): { [key: string]: any[] }[] {\n        const securityToReturn = [];\n        for (const securityIndex in argsSecurity) {\n            const security: any[] = argsSecurity[securityIndex];\n            const result: { [key: string]: any[] } = {};\n            result[securityIndex] = security;\n            securityToReturn.push(result);\n        }\n        return securityToReturn;\n    }\n\n    private buildParameters(\n        type: string,\n        parameters: { [key: string]: IApiOperationArgsBaseParameter }\n    ): ISwaggerOperationParameter[] {\n        const swaggerOperationParameter: ISwaggerOperationParameter[] = [];\n        for (const parameterIndex in parameters) {\n            const parameter: IApiOperationArgsBaseParameter =\n                parameters[parameterIndex];\n            const newSwaggerOperationParameter: ISwaggerOperationParameter = {\n                name: parameterIndex,\n                in: type,\n                type: parameter.type,\n            };\n            if (parameter.name) {\n                newSwaggerOperationParameter.name = parameter.name;\n            }\n            newSwaggerOperationParameter.description = parameter.description;\n            newSwaggerOperationParameter.required = parameter.required;\n            newSwaggerOperationParameter.format = parameter.format;\n            newSwaggerOperationParameter.deprecated = parameter.deprecated;\n            newSwaggerOperationParameter.allowEmptyValue =\n                parameter.allowEmptyValue;\n            newSwaggerOperationParameter.minimum = parameter.minimum;\n            newSwaggerOperationParameter.maximum = parameter.maximum;\n            newSwaggerOperationParameter.default = parameter.default;\n            swaggerOperationParameter.push(newSwaggerOperationParameter);\n        }\n        return swaggerOperationParameter;\n    }\n\n    private buildSwaggerOperation(\n        operation: ISwaggerOperation,\n        controller: IController\n    ): ISwaggerOperation {\n        if (_.isUndefined(operation.produces)) {\n            operation.produces = this.data.produces;\n        }\n        if (_.isUndefined(operation.consumes)) {\n            operation.consumes = this.data.consumes;\n        }\n        if (_.isUndefined(operation.security) && controller.security) {\n            operation.security = this.buildOperationSecurity(\n                controller.security\n            );\n        }\n        if (_.isUndefined(operation.deprecated) && controller.deprecated) {\n            operation.deprecated = controller.deprecated;\n        }\n        if (this.globalResponses) {\n            operation.responses = _.mergeWith(\n                _.cloneDeep(this.globalResponses),\n                operation.responses\n            );\n        }\n        if (operation.tags && operation.tags.length > 0) {\n            operation.tags.unshift(_.upperFirst(controller.name));\n        } else {\n            operation.tags = [_.upperFirst(controller.name)];\n        }\n        return operation;\n    }\n\n    private buildRef(definition: string): string {\n        return '#/definitions/'.concat(_.upperFirst(definition));\n    }\n}\n"]}