Skn0tt / nextjs-nestjs-integration-example

https://nextjs-nestjs-integration-example.now.sh
156 stars 36 forks source link

@nestjs/swagger not working #1

Closed hoangnq3004 closed 4 years ago

hoangnq3004 commented 4 years ago

Hi @Skn0tt !

Thanks for your tutorial!

I want to integrate @nestjs/swagger for auto documentation in my project but it not run

Here is my code

const options = new DocumentBuilder()
    .setTitle('API')
    .setDescription('API')
    .setVersion('1.0') 
    .addTag('api')
    .build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('docs', app, document);

When I navigate to http://localhost:3000/api/docs/static/index.html, it's return 404 page.

How I can fix it? Please help!

Skn0tt commented 4 years ago

Hi @hoangnq3004, I'm happy you liked the tutorial.

Some guesses: Did you properly set up Decorators (e.g. using WarnerHooh/babel-plugin-parameter-decorator) ? I had some problems with that myself. Maybe there's something in your logs about that.

Could you provide a minimal reproduction repository? That'd make it a lot easier for me to help you.

hoangnq3004 commented 4 years ago

Thanks for your reply!

Here is my repository https://github.com/hoangnq3004/tima

Skn0tt commented 4 years ago

In case anybody finds this issue and wonders about the error:

The base route you pass to SwaggerModule.setup (in the code above, that's docs) doesn't take the global prefix into account that's set here (see below). So you'll need to set it to api/docs to make it work.


(I guess it's because the SwaggerModule hooks up to straight to express, without going through NestJS' routing mechanism first. That could be the reason why Swaggers routes don't show up in NestJS' route map, at least.)

hoangnq3004 commented 4 years ago

Thank you very much!

Skn0tt commented 4 years ago

Happy I could help. I've placed a link to this issue at the bottom of the blog post for future reference :)