How to use the @nestjs/swagger.SwaggerModule.createDocument function in @nestjs/swagger

To help you get started, we’ve selected a few @nestjs/swagger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Coding-Coach / find-a-mentor-api / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.enableCors({ origin: process.env.CORS_ORIGIN || /codingcoach\.io$/ });
  const options = new DocumentBuilder()
    .setTitle('Coding Coach')
    .setDescription('A REST API for the coding coach platform')
    .setVersion('1.0')
    .addBearerAuth()
    .build();

  if (process.env.NODE_ENV !== 'production') {
    // We want to get the swagger docs only on development
    const document = SwaggerModule.createDocument(app, options);

    document.schemes = ['https', 'http'];
    fs.writeFileSync('./docs/cc-api-spec.json', JSON.stringify(document));

    SwaggerModule.setup('/docs', app, document);
  }

  await app.listen(process.env.PORT || 3000);
}
bootstrap();
github ksivamuthu / demo-graphql-nestjs / conference-rest-api / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalFilters(new AnyExceptionFilter());

  const options = new DocumentBuilder()
    .setTitle('Conference API example')
    .setDescription('The Conference API description')
    .setVersion('1.0')
    .addTag('conferences', 'CRUD operation of conferences')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('docs', app, document);

  await app.listen(3000);
}
bootstrap();
github Saluki / nestjs-template / src / server.ts View on Github external
function createSwagger(app: INestApplication) {

    const version = require('../package.json').version || '';

    const options = new DocumentBuilder()
        .setTitle(SWAGGER_TITLE)
        .setDescription(SWAGGER_DESCRIPTION)
        .setVersion(version)
        .setBasePath(process.env.API_PREFIX || API_DEFAULT_PREFIX)
        .setSchemes('https', 'http')
        .addBearerAuth('Bearer', 'header')
        .build();

    const document = SwaggerModule.createDocument(app, options);
    SwaggerModule.setup(SWAGGER_PREFIX, app, document);
}
github juicycleff / ultimate-backend / apps / service-tenant / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.enableCors({
    credentials: true,
    preflightContinue: true,
  });
  app.enableShutdownHooks();
  app.use(bloodTearsMiddleware);
  AppUtils.killAppWithGrace(app);
  authSetup(app);

  const document = SwaggerModule.createDocument(app, setupSwagger());
  SwaggerModule.setup('api', app, document);

  await app.listenAsync(
    parseInt(process.env.PORT, 10) ||
    parseInt(config.services?.tenant?.port, 10) ||
    9200,
  );

  await setupGrpc(app, 'tenant', 'tenant.proto', config.services?.tenant?.grpcPort || 7200);
}
bootstrap();
github nestjsx / crud / integration / crud-typeorm / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.useGlobalPipes(new ValidationPipe());
  app.useGlobalFilters(new HttpExceptionFilter());

  const options = new DocumentBuilder()
    .setTitle('@nestjsx/crud-typeorm')
    .setDescription('@nestjsx/crud-typeorm')
    .setVersion('1.0')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('docs', app, document);

  await app.listen(process.env.PORT || 3000);
}
github scalio / bazel-nx-example / apps / api / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.use(cors());
  app.use(helmet());

  const port = process.env.port || 3000;

  const options = new DocumentBuilder()
    .setTitle('nx-bazel-starter')
    .setDescription('The Nx Full-Stack app API description')
    .addBearerAuth()
    .setSchemes('http', 'https')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);

  await app.listen(port, () => {
    Logger.log(`App listening at http://localhost:${port}`, 'HTTP');
    Logger.log('Press Ctrl+C to quit.', 'HTTP');
  });
}
github devonfw / my-thai-star / node / src / main.ts View on Github external
if (configModule.globalPrefix) {
    app.setGlobalPrefix(configModule.globalPrefix);
  }

  if (configModule.isDev) {
    const options = new DocumentBuilder()
      .setTitle(configModule.swaggerConfig.swaggerTitle)
      .setDescription(configModule.swaggerConfig.swaggerDescription)
      .setVersion(configModule.swaggerConfig.swaggerVersion)
      .setHost(configModule.host + ':' + configModule.port)
      .setBasePath(configModule.swaggerConfig.swaggerBasepath)
      .addBearerAuth('Authorization', 'header')
      .build();

    const swaggerDoc = SwaggerModule.createDocument(app, options);
    SwaggerModule.setup('api', app, swaggerDoc);
  }

  app.use(helmet());
  app.enableCors({
    origin: '*',
    credentials: true,
    exposedHeaders: 'Authorization',
    allowedHeaders: 'authorization, content-type',
  });

  app.useGlobalPipes(
    new ValidationPipe({
      transform: true,
    }),
  );
github JamesCoonce / angular-nest-todo / server / todo-api / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.enableCors();
  const options = new DocumentBuilder()
    .setTitle('Todos example')
    .setDescription('The Todos API description')
    .setVersion('1.0')
    .addTag('todos')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);

  await app.listen(3000);
}
bootstrap();
github rucken / todo-nestjs / src / server.ts View on Github external
path.join(FRONTEND_ROOT, 'index.html')
	));
	app.useGlobalPipes(new ValidationPipe());

	const options = new DocumentBuilder()
		.setTitle(packageBody.name)
		.setDescription(packageBody.description)
		.setContactEmail(packageBody.author.email)
		.setExternalDoc('Project on Github', packageBody.repository)
		.setLicense('MIT', '')
		.setSchemes('https', 'http')
		.setVersion(packageBody.version)
		.addBearerAuth('Authorization', 'header')
		.build();

	const document = SwaggerModule.createDocument(app, options);
	/*
		const stt = require('swagger-test-templates');
		const testsConfig = {
			assertionFormat: 'should',
			testModule: 'request'
		};
		const tests = stt.testGen(document, testsConfig);
		tests.forEach(test => {
			fs.writeFileSync(path.resolve(__dirname, '..', 'tests', test.name), test.test);
		});
	*/
	SwaggerModule.setup('/swagger', app, document);

	await app.listen(process.env.PORT && !isNaN(+process.env.PORT) ? +process.env.PORT : 5000);
}
bootstrap();