Closed AndreiSoroka closed 1 year ago
Find reason, problem with swagger-typescript-api
// ...
import swaggerUi from 'swagger-ui-express';
import sta from 'swagger-typescript-api';
const swaggerSpec = swaggerJsdoc({
definition: {
openapi: '3.0.1',
info: {
title: 'Rewards',
version: '1.0.0',
},
servers: [{url: "/"}],
},
apis: ['./routes/*.mjs'],
});
let swaggerComponents = yaml2json.load(readFileSync('./components.yaml', 'utf8'));
export const swaggerDoc = { ...swaggerSpec, ...swaggerComponents };
// ...
// generate TS
const __dirname = new URL('.', import.meta.url).pathname;
sta.generateApi({
name: "Api.ts",
output: __dirname+'./build/',
spec: JSON.parse(JSON.stringify(swaggerDoc)), // <-- it is fix, ERROR was: generateApi modified object
})
// ...
export function addSwagger(path, app){
app.use(path, swaggerUi.serve, swaggerUi.setup(swaggerDoc));
// ...
}
FYI: @acacode
Hi! how to fix: