私はswagger project createを使ってノードサービスのAPIを立ち上げました。私はthese instructionsを続けた。私もswagger-uiを提供するためにswagger-toolsを使用しています。swagger-uiのベースパスを変更してください
私は、APIのbasePathとそのドキュメントを '/'と '/ docs'からroutingPathとroutingPath + '/ docs'に動的に変更したいと考えています。
swagger API仕様のbasePathを変更できますが、swagger-uiのbasePathを変更する方法がわかりません。私のコードは次のようになります。
'use strict';
const defaultRoutingPath = '/api/collection';
const defaultPort = 3000;
var path = require('path');
var SwaggerExpress = require('swagger-express-mw');
var SwaggerUi = require('swagger-tools/middleware/swagger-ui');
var app = require('express')();
module.exports = app; // for testing
var routingPath = process.env.ROUTING_PATH || defaultRoutingPath;
var config = {
appRoot: __dirname // required config
};
SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err; }
swaggerExpress.runner.swagger.basePath = routingPath; // this works
app.get('/', (req, res) => {
res.redirect(path.join(routingPath, 'docs'));
})
// enable SwaggerUI
app.use(swaggerExpress.runner.swaggerTools.swaggerUi({
basePath: routingPath // this has no effect
}));
// install middleware
swaggerExpress.register(app);
var port = process.env.PORT || defaultPort;
app.listen(port);
if (swaggerExpress.runner.swagger.paths['/hello']) {
console.log('try this:\ncurl http://127.0.0.1:' + port + path.join(routingPath, '/hello?name=Scott'));
}
});
私はこのサービスを実行する場合、私は http://localhost:3000/api/collection
で私のAPI仕様を見つけ、 http://localhost:3000/docs
で私のドキュメントのページに、私はドキュメントを提供したいと思いますページの http://localhost:3000/api/collection/docs
私は、swaggerUiコンストラクタにbasePathオプションを渡して、これを実行しようとしました。
// enable SwaggerUI
app.use(swaggerExpress.runner.swaggerTools.swaggerUi({
basePath: routingPath // this has no effect
}));
これは機能しませんでした。誰でもswagger-uiのbasePathを設定する方法を知っていますか?