Open Allyhere opened 1 year ago
Seems like this repo isn't supported anymore...
I am just using swagger-ui-dist and doing some static hosting myself (I'm still on restify v7)
const pathToSwaggerUi = require('swagger-ui-dist').getAbsoluteFSPath();
// serve swagger-ui
server.get('/swagger/*', function (req, res) {
const filePath: string = req.params['*'] || 'index.html';
try {
const file = fs.readFileSync(path.join(pathToSwaggerUi, filePath));
res.write(file);
res.end();
} catch {
res.send(500);
}
res.end();
});
You can also point at your own OpenAPI file and update the other configuration params for swagger-ui :
// serve openapi file
const OPENAPI_PATH = '/openapi.yaml';
server.get(OPENAPI_PATH, function (req, res) {
const swaggerDoc = fs.readFileSync(OPENAPI_FILE_PATH);
res.write(swaggerDoc);
res.end();
});
// overwrite swagger initializer config
const pathToSwaggerUi = require('swagger-ui-dist').getAbsoluteFSPath();
const indexContent = fs
.readFileSync(path.join(pathToSwaggerUi, 'swagger-initializer.js'))
.toString()
// to point at local OpenAPI File
.replace('https://petstore.swagger.io/v2/swagger.json', OPENAPI_PATH)
// and to set other configs from https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
.replace(
'layout: "StandaloneLayout",',
`layout: "StandaloneLayout",
<config_key>: <configvalue>
`
);
server.get('/swagger/swagger-initializer.js', (req, res) => {
res.write(indexContent);
res.end();
});
You'll want to place that second snippet before server.get('/swagger/*', ...)
in the first
Im using swagger-ui-restify in the latest version (3.0.8 at the time of this issue) with node v16.19.0 and npm v8.19.3 and got the following warning
It seems that the main field references to a unresolvable path
The swagger-ui-restify folder tree in my node_modules: