當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript swagger.SwaggerModule類代碼示例

本文整理匯總了TypeScript中@nestjs/swagger.SwaggerModule的典型用法代碼示例。如果您正苦於以下問題:TypeScript SwaggerModule類的具體用法?TypeScript SwaggerModule怎麽用?TypeScript SwaggerModule使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SwaggerModule類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: bootstrap

async function bootstrap() {
  //創建express 實例
  const instance = express();
  //middleware
  instance.use(bodyParser.json());
  instance.use(bodyParser.urlencoded({ extended: false }));
  //NestFactory.create()接受一個模組引數,和一個可選的express實例引數,並返回Promise。
  const app = await NestFactory.create(ApplicationModule, instance);

  //swagger options
  const options = new DocumentBuilder()
    .setTitle('Users Restful API')
    .setDescription('The users Restful API description')
    .setVersion('1.0')
    .addTag('users')
    .build();

  //restful API 文檔
  const document = SwaggerModule.createDocument(app, options);
  
  //打開http://localhost/api 就會連結到swagger服務。
  SwaggerModule.setup('/api', app, document);

  await app.listen(3000)
}
開發者ID:fanybook,項目名稱:Nestjs30Days,代碼行數:25,代碼來源:server.ts

示例2: bootstrap

async function bootstrap(): Promise<void> {
    const app = await NestFactory.create(M1cr0blogModule, { cors: true })

    // Set up static content rendering
    app.useStaticAssets(__dirname + '/static')
    app.setBaseViewsDir(__dirname + '/views')
    app.setViewEngine('hbs')
    hbs.registerPartials(__dirname + '/views/partials')
    hbs.registerHelper('unlessEquals', function(arg1, arg2, options) {
        //@ts-ignore
        return (arg1 != arg2) ? options.fn(this) : options.inverse(this);
    })
    hbs.registerHelper('replace', function(needle: string, newstr: string, options) {
        //@ts-ignore
        return options.fn(this).replace(needle, newstr)
    })

    // Set up Swagger
    const options = new DocumentBuilder()
        .setTitle('M1cr0blog API')
        .setDescription('Backend REST API for m1cr0man\'s blog')
        .setVersion('1.0')
        .addTag('Users', 'User management system')
        .addBearerAuth()
        .build()
    const document = SwaggerModule.createDocument(app, options)
    SwaggerModule.setup('api/swagger', app, document)

    await app.listen(3000)
}
開發者ID:m1cr0man,項目名稱:m1cr0blog,代碼行數:30,代碼來源:index.ts

示例3: bootstrap

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const options = new DocumentBuilder()
    .setTitle("Blog API")
    .setDescription("Back office, for a blog API")
    .setVersion("1.0")
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup("docs", app, document);
  await app.listen(configService.getNumber("PORT"));
}
開發者ID:jonathan-patalano,項目名稱:blog-api,代碼行數:11,代碼來源:main.ts

示例4: bootstrap

async function bootstrap() {

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

    app.use(bodyParser.json());

    app.useGlobalPipes(new ValidationPipe());

    /**
     * Headers setup
     */
    app.use((req, res, next) => {
        res.header('Access-Control-Allow-Origin', '*');
        res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
        next();
    });

    /**
     * Swagger implementation
     */
    const options = new DocumentBuilder()
        .setTitle('Chainservice API')
        .setDescription('The Chainservice API')
        .setVersion('1.0')
        .setExternalDoc('Github repo', 'https://github.com/wearetheledger/hyperledger-typescript-boilerplate')
        .addOAuth2('implicit', `https://${EnvConfig.AUTH0_DOMAIN}/authorize`, `https://${EnvConfig.AUTH0_DOMAIN}/oauth/token`)
        .build();

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

    SwaggerModule.setup('/api', app, document, {
        swaggerOptions: {
            oauth2RedirectUrl: `${EnvConfig.DOMAIN_URL}/api/oauth2-redirect.html`,
            oauth: {
                clientId: EnvConfig.AUTH0_CLIENT_ID,
                appName: 'Chainservice API',
                scopeSeparator: ' ',
                additionalQueryStringParams: {audience: EnvConfig.AUTH0_AUDIENCE}
            }
        }
    });

    /**
     * Start Chainservice API
     */
    await app.listen(+EnvConfig.PORT, () => {
        Log.config.info(`Started Chain-service on PORT ${EnvConfig.PORT}`);
    });

}
開發者ID:oliutiano,項目名稱:hyperledger-typescript-boilerplate,代碼行數:50,代碼來源:main.ts

示例5: bootstrap

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()
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);

  await app.listen(3001);
}
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:15,代碼來源:main.ts

示例6: bootstrap

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    // logger: new MyLogger(),
  });
  
  app.enableCors();

  const options = new DocumentBuilder()
    .setTitle('Cats example')
    .setDescription('The cats API description')
    .setVersion('1.0')
    .addTag('cats')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);

  app.useWebSocketAdapter(new WsAdapter(app.getHttpServer()));

  await app.listen(3081);
}
開發者ID:paulloo,項目名稱:nobone-front,代碼行數:21,代碼來源:main.ts

示例7: bootstrap

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalPipes(new ValidationPipe({ transform: true }));

  const options = new DocumentBuilder()
    .setTitle('Saevis')
    .setDescription('')
    .setVersion('1.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);

  app.use('/swagger.json', (req, res, next) => res.send(document));
  app.enableCors();

  await app.listen(3000);

  if (module.hot) {
    module.hot.accept();
    module.hot.dispose(() => app.close());
  }
}
開發者ID:arner,項目名稱:saevis,代碼行數:23,代碼來源:main.ts

示例8: startApp

export async function startApp(): Promise<http.Server> {
    const app = express();

    app.use(express.static(__dirname + '/static'));

    const nestApp = await NestFactory.create(AppModule, app);
    const options = new DocumentBuilder()
        .setTitle('Notes API')
        .setDescription('Use this API to work with notes.')
        .setVersion('1.0')
        .build();
    const document = SwaggerModule.createDocument(nestApp, options);
    SwaggerModule.setup('/docs', nestApp, document);
    nestApp.useGlobalPipes(new MyValidationPipe());
    nestApp.useGlobalFilters(new MyHttpExceptionFilter());

    const port = 3000;
    const server = await nestApp.listen(port, () => {
        console.log(`Listening at port ${port}`);
    });

    return server;
}
開發者ID:loki2302,項目名稱:nodejs-experiment,代碼行數:23,代碼來源:app.ts


注:本文中的@nestjs/swagger.SwaggerModule類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。