Skip to content

Instantly share code, notes, and snippets.

@KerryRitter
Last active May 23, 2020 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KerryRitter/5749e49afd2b10d4c81a47397012e0c4 to your computer and use it in GitHub Desktop.
Save KerryRitter/5749e49afd2b10d4c81a47397012e0c4 to your computer and use it in GitHub Desktop.
Auto-generate Angular Clients from a Nest-Swagger API
{
"name": "my-api",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"swaggergen": "ts-node ./src/swaggergen.ts --output cfn/symposia-api-swagger.json && ng-openapi-gen --input cfn/symposia-api-swagger.json --output cfn/client"
},
"dependencies": {
"@nestjs/common": "^7.0.0",
"@nestjs/core": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
"@nestjs/swagger": "^4.5.7",
"class-transformer": "^0.2.3",
"class-validator": "^0.12.2",
"ng-openapi-gen": "^0.11.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"swagger-ui-express": "^4.1.4"
},
"devDependencies": {
"@nestjs/cli": "^7.0.0",
"@nestjs/schematics": "^7.0.0",
"@nestjs/testing": "^7.0.0",
"@types/express": "^4.17.3",
"@types/jest": "25.1.4",
"@types/node": "^13.9.1",
"@types/supertest": "^2.0.8",
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"jest": "^25.1.0",
"prettier": "^2.0.5",
"supertest": "^4.0.2",
"ts-jest": "25.2.1",
"ts-loader": "^6.2.1",
"ts-node": "^8.6.2",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.9.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';
import { writeFileSync } from 'fs';
async function generateSwaggerFile() {
const outputFlagIndex = process.argv.findIndex(f => f === 'output');
const outputFile = process.argv[outputFlagIndex + 1];
const app = await NestFactory.create(AppModule);
const options = new DocumentBuilder()
.setTitle('Symposia API')
.setDescription('The Symposia API description')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, options);
writeFileSync(outputFile, JSON.stringify(document, null, 2));
}
generateSwaggerFile();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment