{"_id":"@abrahampeh/swagger-express-ts","_rev":"1-4cbc858f53202e205c1a752ee3581231","name":"@abrahampeh/swagger-express-ts","dist-tags":{"latest":"1.0.5"},"versions":{"1.0.5":{"name":"@abrahampeh/swagger-express-ts","version":"1.0.5","description":"Generate and serve swagger.json","main":"index.js","types":"index.d.ts","typings":"index.d.ts","scripts":{"build:lib":"echo \"Building lib...\" && gulp build:lib","build":"echo \"Building...\" && gulp build","clean":"echo \"Cleaning...\" && gulp clean","test":"echo \"Testing...\" && npm run build && nyc mocha","dev":"echo \"Developing...\" && nodemon","start":"echo \"Starting...\" && npm run build && ts-node --project tsconfig.json src/index.ts","publish":"npm publish dist/swagger-express-ts"},"repository":{"type":"git","url":"git+ssh://git@github.com/abrahampeh/swagger-express-ts.git"},"author":{"name":"Abraham Peña"},"license":"MIT","keywords":["inversify","inversifyjs","swagger","swagger2","swagger-ui","typescript","expressjs","express","api rest","documentation","decorator","generator","swagger.json","json","rest"],"bugs":{"url":"https://github.com/abrahampeh/swagger-specification-ts/issues"},"homepage":"https://github.com/abrahampeh/swagger-specification-ts#readme","dependencies":{"@types/body-parser":"^1.17.0","@types/compression":"0.0.35","@types/express":"^4.16.0","@types/helmet":"0.0.37","@types/inversify":"^2.0.33","@types/lodash":"^4.14.109","body-parser":"^1.18.3","compression":"^1.7.2","express":"^4.16.4","helmet":"^3.12.1","inversify":"^4.13.0","inversify-express-utils":"^4.2.2","lodash":"^4.17.10","reflect-metadata":"^0.1.13"},"devDependencies":{"@types/chai":"^4.1.3","@types/mocha":"^2.2.48","@types/sinon":"^4.3.3","chai":"^4.1.2","gulp":"^4.0.0","gulp-clean":"^0.4.0","gulp-sourcemaps":"^2.6.4","gulp-tslint":"^8.1.3","gulp-typescript":"^3.2.4","mocha":"^4.0.1","nodemon":"^1.18.4","nyc":"^13.1.0","prettier":"1.12.0","pretty-quick":"^1.4.1","rimraf":"^2.6.2","sinon":"^4.5.0","source-map-support":"^0.5.9","swagger-ui-dist":"^3.17.0","ts-node":"^7.0.1","tslint":"^5.10.0","tslint-config-prettier":"^1.10.0","typescript":"^3.1.3"},"nyc":{"include":["src/**/*.ts","lib/swagger-express-ts-lib/src/**/*.ts"],"exclude":["src/index.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["html"],"sourceMap":true,"instrument":true},"nodemonConfig":{"restartable":"rs","watch":["src/**/*.ts","lib/**/*.ts"],"ext":"ts","ignore":["test/*","wiki/*","swagger/*","node_modules/*","dist/*"],"delay":"2500","exec":"gulp build && ts-node --project tsconfig.json src/index.ts"},"husky":{"hooks":{"pre-commit":"pretty-quick --staged"}},"publishConfig":{"registry":"https://registry.npmjs.org"},"directories":{"lib":"lib","test":"test"},"gitHead":"d595db6242692dd1c681dcdf4de232a534f04d15","_id":"@abrahampeh/swagger-express-ts@1.0.5","_nodeVersion":"12.18.3","_npmVersion":"6.14.6","dist":{"integrity":"sha512-9bAHhPgzgtyoNj/cfKLQdlGXRfQttGCeYe9QuPKISehpGE9M1vZcomth3dnBkiHgZEvJGgmcPfFkZAxiDAAlxA==","shasum":"692c7b14a40d48a90d66a338d4f11b536ba74034","tarball":"https://registry.npmjs.org/@abrahampeh/swagger-express-ts/-/swagger-express-ts-1.0.5.tgz","fileCount":70,"unpackedSize":296381,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfWgYaCRA9TVsSAnZWagAAShgP/R0WNi5IqtCErnaeFW/O\nfrEpV2q7L2jIU+5SjJ2hUwMn4AENy0bv9ps+4YfqQ7doayIxhWtm4yXIsx3l\nfUS5CcpZRoYEU7PK6aGspeuAr/y6rTjYfeqd+EM2CKVEbkuPP/ZDTQT/O3Bs\n0GN4RqU5T8l0KQzzH++XXaLYiS1dsMnAyb/TVIqwJEEdc7QXNHkK8QnaXuky\nJWKZDG024XsiV4EdntsImdaXmnfgpch7/dY4btDWtmrXFaWtR7YSQMiEgjm1\nPctQ+uaARcsNKCoFo4GINFqOcsfHLfPx4iDCmqn+IcoQ8de0WuCe3evYSO5T\nBnLlW5ra293SbAKfembTNEfRJ/S49Bg0uNeUGrk2IQc0b5vbQpjRuux+KLeg\nKsfTVikw2tc5c/KnXjtCyhyJOlZYcOp/vI4vdalRIdDns1aEDY473Hui6hE5\nF2OQ3UAsjoxS/gY//ZpVS9YZpxggtxlEgdk4PC5qnMoLWbl3sTULZzZXIzxl\nIMR/e35R2h8PMBH5LTZyxc2XPrNpPT8cqF9YDQb40PpTFC71SPj3+SsF3SxQ\nWOI9SLcEtkU6X3eFjaqHAB1CxQgjj5d7nD61JVMZTV1+vDnc9Wx9hF2MEypo\nzT2vGMS1A1TQasMvCE6H7Q+bP+Cn/Gu1oQ3gFZ0qDXgp5hTKiQIWKS/79wmF\neoe7\r\n=8IwP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCGULlg7YJ0Iqw5IaMTMYUPzfQRT65XkxwO1nxFoPKAMwIgKO0cDqBA5b+N73OIgCS4MDv3XXf8tUN8h6jLBmDN7Z8="}]},"maintainers":[{"name":"abrahampeh","email":"abrahampeh@gmail.com"}],"_npmUser":{"name":"abrahampeh","email":"abrahampeh@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/swagger-express-ts_1.0.5_1599735321858_0.8877138456065872"},"_hasShrinkwrap":false}},"time":{"created":"2020-09-10T10:55:21.826Z","1.0.5":"2020-09-10T10:55:21.979Z","modified":"2022-04-04T11:01:40.353Z"},"maintainers":[{"name":"abrahampeh","email":"abrahampeh@gmail.com"}],"description":"Generate and serve swagger.json","homepage":"https://github.com/abrahampeh/swagger-specification-ts#readme","keywords":["inversify","inversifyjs","swagger","swagger2","swagger-ui","typescript","expressjs","express","api rest","documentation","decorator","generator","swagger.json","json","rest"],"repository":{"type":"git","url":"git+ssh://git@github.com/abrahampeh/swagger-express-ts.git"},"author":{"name":"Abraham Peña"},"bugs":{"url":"https://github.com/abrahampeh/swagger-specification-ts/issues"},"license":"MIT","readme":"![](wiki/img/logo.png)\n\n# swagger-express-ts\nAutomatically generate and serve swagger.json v2.0.\n\n## Getting started\n\nFirst, install [swagger-express-ts](https://www.npmjs.com/package/swagger-express-ts).\n\n```sh\nnpm install @fiwoo/swagger-express-ts --save\n```\n\nand [init tsconfig.json](./wiki/installation.md)\n\n## The Basics\n\nIn the examples below, we use [inversify-express-utils](https://www.npmjs.com/package/inversify-express-utils). inversify-express-utils is not required to work with swagger-express-ts.\n\n### Step 1: configure express\n\n```ts\nimport * as bodyParser from \"body-parser\";\nimport * as express from \"express\";\nimport \"reflect-metadata\";\nimport { Container } from \"inversify\";\nimport { interfaces, InversifyExpressServer, TYPE } from \"inversify-express-utils\";\nimport { VersionController } from \"./version/version.controller\";\nimport * as swagger from \"swagger-express-ts\";\nimport { SwaggerDefinitionConstant } from \"swagger-express-ts\";\nconst config = require ( \"../config.json\" );\n\n// set up container\nconst container = new Container ();\n\n// note that you *must* bind your controllers to Controller\ncontainer.bind<interfaces.Controller> ( TYPE.Controller )\n    .to( VersionController ).inSingletonScope().whenTargetNamed( VersionController.TARGET_NAME );\n\n// create server\nconst server = new InversifyExpressServer ( container );\n\nserver.setConfig( ( app : any ) => {\n    app.use( '/api-docs/swagger' , express.static( 'swagger' ) );\n    app.use( '/api-docs/swagger/assets' , express.static( 'node_modules/swagger-ui-dist' ) );\n    app.use( bodyParser.json() );\n    app.use( swagger.express(\n        {\n            definition : {\n                info : {\n                    title : \"My api\" ,\n                    version : \"1.0\"\n                } ,\n                externalDocs : {\n                    url : \"My url\"\n                }\n                // Models can be defined here\n            }\n        }\n    ) );\n} );\n\nserver.setErrorConfig( ( app : any ) => {\n    app.use( ( err : Error , request : express.Request , response : express.Response , next : express.NextFunction ) => {\n        console.error( err.stack );\n        response.status( 500 ).send( \"Something broke!\" );\n    } );\n} );\n\nconst app = server.build();\n\napp.listen( config.port );\nconsole.info( \"Server is listening on port : \" + config.port );\n\n```\n\n### Step 2: Decorate your models\n\n```ts\n@ApiModel( {\n    description : \"Version description\" ,\n    name : \"Version\"\n} )\nexport class VersionModel {\n\n    @ApiModelProperty( {\n        description : \"Id of version\" ,\n        required : true,\n        example: ['123456789']\n    } )\n    id : number;\n\n    @ApiModelProperty( {\n        description : \"\" ,\n        required : true\n    } )\n    name : string;\n\n    @ApiModelProperty( {\n        description : \"Description of version\" ,\n        required : true\n    } )\n    description : string;\n}\n```\n\n### Step 3: Decorate your controllers\n\n```ts\n@ApiPath({\n    path: \"/versions\",\n    name: \"Version\",\n    security: { basicAuth: [] }\n})\n@controller(\"/versions\")\n@injectable()\nexport class VersionController implements interfaces.Controller {\n    public static TARGET_NAME: string = \"VersionController\";\n    \n    private data = [{\n            id: \"1\",\n            name: \"Version 1\",\n            description: \"Description Version 1\",\n            version: \"1.0.0\"\n        },\n        {\n            id: \"2\",\n            name: \"Version 2\",\n            description: \"Description Version 2\",\n            version: \"2.0.0\"\n        }];\n\n    @ApiOperationGet({\n        description: \"Get versions objects list\",\n        summary: \"Get versions list\",\n        responses: {\n            200: { description: \"Success\", type: SwaggerDefinitionConstant.Response.Type.ARRAY, model: \"Version\" }\n        },\n        security: {\n            apiKeyHeader: []\n        }\n    })\n    @httpGet(\"/\")\n    public getVersions(request: express.Request, response: express.Response, next: express.NextFunction): void {\n        response.json(this.data);\n    }\n\n    @ApiOperationPost({\n        description: \"Post version object\",\n        summary: \"Post new version\",\n        parameters: {\n            body: { description: \"New version\", required: true, model: \"Version\" }\n        },\n        responses: {\n            200: { description: \"Success\" },\n            400: { description: \"Parameters fail\" }\n        }\n    })\n    @httpPost(\"/\")\n    public postVersion(request: express.Request, response: express.Response, next: express.NextFunction): void {\n        if (!request.body) {\n            return response.status(400).end();\n        }\n        this.data.push(request.body);\n        response.json(request.body);\n    }\n\n}\n```\n\n### Step 4: Test\n\nStart your server and test on url : /api-docs/swagger.json\n\n## Extra\n\n### Serve swagger-ui in your API\n\nYou can serve swagger.json and swagger-ui in your API.\n\n```sh\nnpm install swagger-ui-dist --save\n```\n\nCreate index.html in new directory \"swagger\".\n\n```html\n<!-- HTML for static distribution bundle build -->\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <title>Swagger UI</title>\n    <link href=\"https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700\"\n          rel=\"stylesheet\">\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"/api-docs/swagger/assets/swagger-ui.css\">\n    <link rel=\"icon\" type=\"image/png\" href=\"/api-docs/swagger/assets/favicon-32x32.png\" sizes=\"32x32\"/>\n    <link rel=\"icon\" type=\"image/png\" href=\"/api-docs/swagger/assets/favicon-16x16.png\" sizes=\"16x16\"/>\n    <style>\n        html {\n            box-sizing: border-box;\n            overflow: -moz-scrollbars-vertical;\n            overflow-y: scroll;\n        }\n\n        *,\n        *:before,\n        *:after {\n            box-sizing: inherit;\n        }\n\n        body {\n            margin: 0;\n            background: #fafafa;\n        }\n    </style>\n</head>\n\n<body>\n\n<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n     style=\"position:absolute;width:0;height:0\">\n    <defs>\n        <symbol viewBox=\"0 0 20 20\" id=\"unlocked\">\n            <path d=\"M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z\"></path>\n        </symbol>\n\n        <symbol viewBox=\"0 0 20 20\" id=\"locked\">\n            <path d=\"M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z\"/>\n        </symbol>\n\n        <symbol viewBox=\"0 0 20 20\" id=\"close\">\n            <path d=\"M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z\"/>\n        </symbol>\n\n        <symbol viewBox=\"0 0 20 20\" id=\"large-arrow\">\n            <path d=\"M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z\"/>\n        </symbol>\n\n        <symbol viewBox=\"0 0 20 20\" id=\"large-arrow-down\">\n            <path d=\"M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z\"/>\n        </symbol>\n\n\n        <symbol viewBox=\"0 0 24 24\" id=\"jump-to\">\n            <path d=\"M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z\"/>\n        </symbol>\n\n        <symbol viewBox=\"0 0 24 24\" id=\"expand\">\n            <path d=\"M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z\"/>\n        </symbol>\n\n    </defs>\n</svg>\n\n<div id=\"swagger-ui\"></div>\n\n<script src=\"/api-docs/swagger/assets/swagger-ui-bundle.js\"></script>\n<script src=\"/api-docs/swagger/assets/swagger-ui-standalone-preset.js\"></script>\n<script>\n    window.onload = function () {\n\n        // Build a system\n        const ui = SwaggerUIBundle ({\n            url: \"/api-docs/swagger.json\",\n            dom_id: '#swagger-ui',\n            deepLinking: true,\n            presets: [\n                SwaggerUIBundle.presets.apis,\n                SwaggerUIStandalonePreset\n            ],\n            plugins: [\n                SwaggerUIBundle.plugins.DownloadUrl\n            ],\n            layout: \"StandaloneLayout\",\n            validatorUrl: null\n        });\n\n        window.ui = ui\n    }\n</script>\n</body>\n\n</html>\n\n```\n\nConfigure your server like that.\n\n```ts\napp.use( '/api-docs/swagger', express.static( 'swagger' ) );\napp.use( '/api-docs/swagger/assets', express.static( 'node_modules/swagger-ui-dist' ) );\n```\n\nTest it on url \"/api-docs/swagger\".\n\n![](./wiki/img/swagger-ui.png)\n\n## Project example\n\nYou can quickly test swagger-express-ts with the project example [example-swagger-express-ts](https://github.com/olivierlsc/example-swagger-express-ts).\n\n## Features and API\n\n- [Installation](./wiki/installation.md)\n- [Configuration](./wiki/configuration.md)\n- [@ApiModel](./wiki/api-model.decorator.md)\n- [@ApiModelProperty](./wiki/api-model-property.decorator.md)\n- [@ApiPath](./wiki/api-path.decorator.md)\n- [@ApiOperationGet](./wiki/api-operation-get.decorator.md)\n- [@ApiOperationPost](./wiki/api-operation-post.decorator.md)\n- [@ApiOperationPut](./wiki/api-operation-put.decorator.md)\n- [@ApiOperationPatch](./wiki/api-operation-patch.decorator.md)\n- [@ApiOperationDelete](./wiki/api-operation-delete.decorator.md)\n\n## For any questions, suggestions, or feature requests\n\n[Please file an issue](https://github.com/olivierlsc/swagger-express-ts/issues)!\n\n## Help wanted\n\nswagger-express-ts wants additional maintainers! To maintain and continue to develop this young library, [Please post in this issue](https://github.com/olivierlsc/swagger-express-ts/issues/34).\n","readmeFilename":"README.md"}