Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger UI options not working after upgrading to v7 #2481

Closed
3 of 4 tasks
bc-m opened this issue Jun 16, 2023 · 5 comments
Closed
3 of 4 tasks

Swagger UI options not working after upgrading to v7 #2481

bc-m opened this issue Jun 16, 2023 · 5 comments

Comments

@bc-m
Copy link

bc-m commented Jun 16, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

It seems that after the upgrade to v7.0.0 the options no longer work. I have checked the docs for swagger-ui v5 but I cannot see the differences in the options.

Swagger UI renders with default settings:

  • Authorization lost after reload page
  • Tags are unsorted
  • All Models are shown at the bottom of the page

Minimum reproduction code

const config = new DocumentBuilder()
  .setTitle('API')
  .setDescription('Some description')
  .setVersion('1.0')
  .addBearerAuth({
      type: 'apiKey',
      name: 'Authorization',
      in: 'header',
  }).build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('docs', app, document, {
  swaggerOptions: {
    persistAuthorization: true,
    tagsSorter: 'alpha',
    operationsSorter: 'alpha',
    defaultModelsExpandDepth: -1,
    defaultModelExpandDepth: -1,
  },
});

Steps to reproduce

  • Upgrade to NestJS v10 and NestJS-Swagger v7
  • Open Swagger-UI

Expected behavior

It should be the same as in v6.

Package version

7.0.0

NestJS version

10.0.0

Node.js version

18.14.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

I temporarily reverted back to v4 (in @nestjs/swagger@7.0.1).

@flamewow would you take a look at what would it take to upgrade swagger-ui-dist to v5 with our custom templates? 👀

@joshunrau
Copy link
Contributor

joshunrau commented Jun 17, 2023

I am having a similar issue with other settings inSwaggerCustomOptions as well. I am trying to add some custom static assets, but this does not seem to have any effect (I see in the browser they are not being fetched).

This is the code in question. I tried updating to 7.0.1 but this did not fix the issue.

app.useStaticAssets(path.resolve(__dirname, '..', 'public'));

const config = new DocumentBuilder()
  .setTitle('The Douglas Data Bank')
  .setDescription('Documentation for the Douglas Data Bank API')
  .setLicense('AGPL-3.0', 'https://www.gnu.org/licenses/agpl-3.0.txt')
  .setVersion('1.0')
  .addTag('Auth')
  .build();

const document = SwaggerModule.createDocument(app, config);

SwaggerModule.setup('/', app, document, {
  customCssUrl: '/swagger.css',
  customfavIcon: '/favicon.ico',
  customSiteTitle: 'The Douglas Data Bank API'
});

@joshunrau
Copy link
Contributor

Okay I figured out the issue I will make a PR

@kamilmysliwiec
Copy link
Member

Fixed in 7.0.2

@ghost
Copy link

ghost commented Oct 23, 2023

Hello,

I observed that the merge [#2487] aimed at addressing the custom assets injection issue has been reverted in subsequent releases, which seems to have brought back the initial problem.

Could you shed some light on the rationale behind reverting this merge? Additionally, is there an alternative solution or a planned fix for the custom assets injection issue in upcoming releases?

I appreciate your attention to this matter and look forward to any information you can provide.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants