#Swagger doesn't work when I build in Javascript instead of Typescript

1 messages · Page 1 of 1 (latest)

wary mortar
#

I use a library that doesn't have types then I'm building backend with nestjs app using JS instead of TS and for swagger I do the same that I do in apps wrote in TS however it doesn't show the routes, only the title

  const options = new DocumentBuilder()
    .setTitle('Example api')
    .setVersion('0.1.0')
    .build();

  const document = swaggerModule.createDocument(app, options);

  SwaggerModule.setup('api/docs', app, document);

do I need to do something else with JS?

I have here the minimal repo https://github.com/dancespiele/nest-swagger-javascript-starter however in this case I get this error:

/home/spielrs/Proyectos/javascript-starter/node_modules/@nestjs/swagger/dist/swagger-scanner.js:49
        const denormalizedArray = [...routes.values()].map((ctrl) => this.explorer.exploreController(ctrl, applicationConfig, modulePath, globalPrefix, operationIdFactory));
                                             ^

TypeError: Cannot read properties of undefined (reading 'values')

it looks like swagger cannot detect routes

GitHub

Contribute to dancespiele/nest-swagger-javascript-starter development by creating an account on GitHub.

elder ravine
#

NestJS's swagger integration heavily relies upon Typescript type metadata emission that comes from using decorators. As there's nothing like that in regular JS, you'd end up needing to use a lot of @ApiBody() type decorators and passing the raw schema per endpoint for the body, param, query,etc