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


TypeScript swagger-express-middleware類代碼示例

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


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

示例1:

SwaggerExpressMiddleware("PetStore.yaml", app, (err: any, middleware: SwaggerExpressMiddleware.SwaggerMiddleware) => {
    let filesOptions: SwaggerExpressMiddleware.FilesOptions = {
        useBasePath: false,
        apiPath: "/api-docs/",
        rawFilesPath: "/api-docs/"
    };

    let parseRequestOptions: SwaggerExpressMiddleware.ParseRequestOptions = {
        cookie: { secret: undefined },
        json: {
            limit: '1mb'
        },
        text: {
            limit: '1mb',
            type: 'text/*'
        },
        urlencoded:{
            extended:true
        },
        raw:{
           inflate:false,
           limit:100
        }

    }

    app.use(
        middleware.metadata(router),
        middleware.CORS(),
        middleware.files(router, filesOptions),
        middleware.parseRequest(parseRequestOptions),
        middleware.validateRequest(),
        middleware.mock(router)
    );
});
開發者ID:ArtemZag,項目名稱:DefinitelyTyped,代碼行數:35,代碼來源:swagger-express-middleware-tests.ts

示例2: Resource

import * as express from 'express';
import * as path from 'path';
import * as util from 'util';


// from sample1.js

let app = express();

middleware(path.join(__dirname, 'PetStore.yaml'), app, (err, middleware) => {
  app.use(
    ...middleware.metadata(),
    ...middleware.CORS(),
    ...middleware.files(),
    ...middleware.parseRequest(),
    ...middleware.validateRequest(),
    ...middleware.mock()
  );

  app.listen(8000, function() {
    console.log('The Swagger Pet Store is now running at http://localhost:8000');
  });
});

// from sample2.js

var middlewareInstance = new Middleware(app);
middlewareInstance.init(path.join(__dirname, 'PetStore.yaml'), err => {
  // Create a custom data store with some initial mock data
  var myDB = new MemoryDataStore();
  myDB.save(
    new Resource('/pets/Lassie', {name: 'Lassie', type: 'dog', tags: ['brown', 'white']}),
開發者ID:swissspidy,項目名稱:typed-swagger-express-middleware,代碼行數:32,代碼來源:swagger-express-middleware-test.ts


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