UNPKG

swagger-express-ts

Version:
1 lines 1.73 kB
{"version":3,"sources":["../../lib/swagger-express-ts-lib/src/express.configurator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmC,MAAM,SAAS,CAAC;AAGlE,OAAO,EAAS,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAGnE,MAAM,WAAW,sBAAsB;IACnC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,CAAC,EAAE,uBAAuB,CAAC;CACxC;AAED,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAahE","file":"express.configurator.d.ts","sourcesContent":["import { Router, Request, Response, NextFunction } from 'express';\nimport { SwaggerService } from './swagger.service';\nimport * as assert from 'assert';\nimport { build, ISwaggerBuildDefinition } from './swagger.builder';\nimport { ISwagger } from './i-swagger';\n\nexport interface ISwaggerExpressOptions {\n /**\n * Path of resource.\n * Default is \"/api-docs/swagger.json\".\n */\n path?: string;\n\n /**\n * Swagger Definition.\n */\n definition?: ISwaggerBuildDefinition;\n}\n\nexport function express(options?: ISwaggerExpressOptions): Router {\n let path: string = '/api-docs/swagger.json';\n if (options) {\n assert.ok(options.definition, 'Definition is required.');\n if (options.path) {\n path = options.path;\n }\n if (options.definition) {\n build(options.definition);\n }\n }\n const router = buildRouter(path);\n return router;\n}\n\nfunction buildRouter(path: string): Router {\n const router: Router = Router();\n router.get(\n path,\n (request: Request, response: Response, next: NextFunction) => {\n const data: ISwagger = SwaggerService.getInstance().getData();\n response.json(data);\n }\n );\n return router;\n}\n"]}