本文整理匯總了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)
);
});
示例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