How to use the @nestjs/swagger.DocumentBuilder 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 kuangshp / nestjs-mysql-api / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    cors: true, // 设置跨站访问
    logger: false,
  });
  // 配置api文档信息
  const options = new DocumentBuilder()
    .setTitle('nestjs api文档')
    .setDescription('nestjs api接口文档')
    .setBasePath(PREFIX)
    .setVersion('1.0')
    .addBearerAuth('token')
    .setVersion('0.0.1')
    .build();

  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup(`${PREFIX}/docs`, app, document);

  // 访问频率限制
  app.use(
    rateLimit({
      windowMs: 15 * 60 * 1000, // 15分钟
      max: 100, // 限制15分钟内最多只能访问100次
github nayutaco / ptarmigan / ptarmapi / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useWebSocketAdapter(new WsAdapter(app));

  // swagger setting
  const options = new DocumentBuilder()
    .setTitle('ptarmigan REST-API')
    .setDescription('Lightning Network implementation ptarmigan REST-API')
    .addBearerAuth('Authorization', 'header')
    .setVersion('0.2')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);

  const config = ConfigService;
  Logger.log('ptarmdRpcPort: ' + config.get('ptarmigan.ptarmdRpcPort'));
  Logger.log('ptarmdHost: + ' + config.get('ptarmigan.ptarmdHost'));
  Logger.log('bitcoindRpcPort: ' + config.get('ptarmigan.bitcoindRpcPort'));
  Logger.log('bitcoindHost: ' + config.get('ptarmigan.bitcoindHost'));
  Logger.log('bitcoindHost: ' + config.get('ptarmigan.apiToken'));

  await app.listen(3000);
github ubiq / shokku / src / main.ts View on Github external
async function bootstrap() {
  const server = express()
  const app = await NestFactory.create(ApplicationModule, server, {})

  // Swagger
  const options = new DocumentBuilder()
    .setTitle('Shokku API')
    .setDescription('An open source scalable blockchain infrastructure for Ubiq, Ethereum, POA and IPFS that runs on Kubernetes')
    .setVersion('1.0')
    .build()

  const document = SwaggerModule.createDocument(app, options)
  server.use('/swagger', SwaggerUI.serve, SwaggerUI.setup(document))

  // Global Filters
  app.useGlobalFilters(new AppExceptionFilter())

  // Global Pipes
  const networksRepository = app.get(NetworksRepository)
  app.useGlobalPipes(new NetworkChainValidatorPipe(networksRepository))

  await app.listen(3000)
github new-eden-social / new-eden-social / src / gateway / server.ts View on Github external
async function bootstrap() {
  const HTTP_PORT = parseInt(process.env.HTTP_PORT, 10) || 3000; // Default to 3000

  const app = await NestFactory.create(GatewayModule);
  app.enableCors();
  app.useGlobalPipes(new ValidationPipe());

  // Swagger
  const options = new DocumentBuilder()
  .setTitle('New Eden Social API')
  .setDescription('Automatically generated API Description')
  .setExternalDoc(
    'Additional Resources can be found on Github Wiki',
    'https://github.com/new-eden-social/new-eden-social/wiki')
  .setVersion(process.env.npm_package_version)
  .setSchemes(process.env.NODE_ENV === 'production' ? 'https' : 'http')
  .addTag('characters', 'EVE Online Characters')
  .addTag('corporations', 'EVE Online Corporations')
  .addTag('alliances', 'EVE Online Alliances')
  .addTag('comments')
  .addTag('posts')
  .addTag('follow')
  .addTag('notifications')
  .addTag('search', 'Search for everything in EVE Online')
  .addTag('status', 'EVE Book API and ESI status')
github danielwii / asuna-node-server / src / bootstrap.ts View on Github external
// app.use(csurf());
  // app.enableCors(); fixme temp disable for allow OPTIONS
  app.enableShutdownHooks();

  if (AsunaContext.isDebugMode) {
    logger.log('[X] debug mode is enabled');
  }

  // --------------------------------------------------------------
  // Setup Swagger
  // --------------------------------------------------------------

  if (configLoader.loadBoolConfig(ConfigKeys.SWAGGER)) {
    logger.log('[X] init swagger at /swagger');
    const swaggerOptions = new DocumentBuilder()
      .setTitle('API Server')
      .setVersion(`${options.version}, Core: ${pkg.version}`)
      .build();
    const document = SwaggerModule.createDocument(app, swaggerOptions);
    SwaggerModule.setup('/swagger', app, document);
  }

  const port = configLoader.loadNumericConfig(ConfigKeys.PORT, 5000);

  logger.log('bootstrap app ...');
  return app.listenAsync(port).then(opts => {
    logger.log(`started in ${Date.now() - startAt}ms, listening on ${port}`);

    return app;
  });
}
github nartc / nest-mean / server / src / main.ts View on Github external
async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    const hostDomain = AppModule.isDev ? `${AppModule.host}:${AppModule.port}` : AppModule.host;

    const swaggerOptions = new DocumentBuilder()
        .setTitle('Nest MEAN')
        .setDescription('API Documentation')
        .setVersion('1.0.0')
        .setHost(hostDomain.split('//')[1])
        .setSchemes(AppModule.isDev ? 'http' : 'https')
        .setBasePath('/api')
        .addBearerAuth('Authorization', 'header')
        .build();

    const swaggerDoc = SwaggerModule.createDocument(app, swaggerOptions);

    SwaggerModule.setup('/api/docs', app, swaggerDoc, {
        swaggerUrl: `${hostDomain}/api/docs-json`,
        explorer: true,
        swaggerOptions: {
            docExpansion: 'list',
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 notadd / next / packages / server / server.js View on Github external
logger: services_1.LogService,
            });
            application.use("/", serveStatic(`${process.cwd()}/public`));
        }
        else {
            application = await core_2.NotaddFactory.startWithExpress(modules_1.ApplicationModule, {
                bodyParser: true,
                cors: true,
                logger: services_1.LogService,
            });
            application.use(express.static(process.cwd() + "/public/"));
        }
        application.useGlobalPipes(new common_1.ValidationPipe());
        const swaggerConfiguration = loaders_1.Configuration.loadSwaggerConfiguration();
        if (serverConfiguration.adapter !== "fastify" && swaggerConfiguration.enable) {
            const options = new swagger_1.DocumentBuilder()
                .setTitle("Notadd")
                .setDescription("API document for Notadd.")
                .setVersion("2.0")
                .addBearerAuth()
                .build();
            const document = swagger_1.SwaggerModule.createDocument(application, options);
            swagger_1.SwaggerModule.setup(`/${swaggerConfiguration.endpoint}`, application, document);
        }
        const callback = () => {
            if (graphqlConfiguration.ide.enable) {
                this.logger.log(`Graphql IDE Server on: ${address}/graphiql`);
            }
            if (serverConfiguration.adapter !== "fastify" && swaggerConfiguration.enable) {
                this.logger.log(`Swagger Server on: ${address}/${swaggerConfiguration.endpoint}`);
            }
            this.logger.log(`Server on: ${address}`);
github vip-git / react-ssr-advanced-seed / src / server / main.ts View on Github external
async function bootstrap() {
	const app = await NestFactory.create(ApplicationModule);
	const options = new DocumentBuilder()
		.setTitle('Cats example')
		.setDescription('The cats API description')
		.setVersion('1.0')
		.addTag('cats')
		.addBearerAuth('Authorization', 'header')
		.build();

	const document = SwaggerModule.createDocument(app, options);
	SwaggerModule.setup('swagger', app, document);

	await app.listen(process.env.PORT || '3000');

	if (module.hot) {
		module.hot.accept();
		module.hot.dispose(async () => {
			app.close();
github vellengs / typerx / src / server / main.ts View on Github external
async function bootstrap() {
  if (process.env.NODE_ENV === 'production') {
    serverRender(app);
  }

  const server = await NestFactory.create(ApplicationModule, app);

  const options = new DocumentBuilder()
    .setTitle('Typerx api documents')
    .setDescription('The API description')
    .setVersion('1.0')
    .addTag('typerx')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(server, options);
  SwaggerModule.setup('/api2', server, document);

  await server.listen(process.env.PORT || 3666);
}