nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swagger UI options not working after upgrading to v7

bc-m opened this issue · comments

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

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? 👀

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'
});

Okay I figured out the issue I will make a PR

Fixed in 7.0.2

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.