question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger module ignores setGlobalPrefix()

See original GitHub issue

I’m submitting a…


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When setting setGlobalPrefix('v2') and using the Swagger module as described in the doc with SwaggerModule.setup('api', app, document), the API is actually available under /api and /v2/api throws a 404 Cannot GET /v2/api.

It works when setting SwaggerModule.setup('v2/api', app, document), but this introduces duplication.

Expected behavior

I expected the global prefix to be applied to the Swagger module’s path, too.

Minimal reproduction of the problem with instructions

Repro repo. Created with the CLI, only added swagger module as described in the doc and setGlobalPrefix().

Environment

Nest version: 5.0.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

13reactions
kamilmysliwieccommented, Aug 16, 2018

Just tried to reproduce this issue and for me, everything is working correctly. My code:

app.setGlobalPrefix('v1');
const options = new DocumentBuilder()
  .setBasePath('v1')
  .build();
12reactions
dotpackcommented, Dec 24, 2019

@renatogbp try to change operations order.

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.setGlobalPrefix('api');

  const options = new DocumentBuilder()
    .setTitle('Example')
    .setDescription('The API description')
    .setVersion('1.0.0')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('swagger', app, document);

  await app.listen(3000);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

prefix url in Swagger module - node.js - Stack Overflow
I am using nest js and swagger as documentation but Swagger module ignores setGlobalPrefix(). in my environemnt the api prefix is ...
Read more >
Other features - OpenAPI - A progressive Node.js framework
To ignore a global prefix for routes set through setGlobalPrefix() , use ignoreGlobalPrefix : const document = SwaggerModule.createDocument(app, options ...
Read more >
A Guide to NestJS Swagger Configuration - Bits and Pieces
Let's bootstrap the NestJS swagger module into our app. ... swagger will ignore the global prefix set through `setGlobalPrefix()` method
Read more >
A Guide to NestJS Swagger Configuration
Next step is to bootstrap the NestJS Swagger Module in our application. ... ignore the global prefix set through `setGlobalPrefix()` method ...
Read more >
@nestjs/core NestFactory TypeScript Examples
createDocument(app, options); SwaggerModule.setup('api', app, document); await app.listen(port, async () => { console.log(`The server is running on ${port} ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found