#ExpressSwaggerCustomOptions / SwaggerCustomOptions : urls Property?

1 messages · Page 1 of 1 (latest)

tall current
#

Hello there 👋

I was wondering, how I could use this property (see title). I couldn't find any documentation about this.

I followed these instructions on the website: https://docs.nestjs.com/openapi/other-features#multiple-specifications

and I wanted to achieve following result: (look at the marked answer)

I tried the approach of the marked answer where I iterate an array with my modules I wanted to import.

Here is my code:

const modules: any[] = [CatsModule, DogsModule]

let i = 0;
  const swaggerCustomOptions: ExpressSwaggerCustomOptions = {
    urls: [],
  };
// Import each module
for (const module of modules) {
    const c = new DocumentBuilder()
      .setTitle(`${module.name} API`)
      .setDescription(`${module.name} API`)
      .setVersion('1.0')
      .setExternalDoc('YAML definition file', `/${globalPrefix + i}-yaml`)
      .addTag(module.name)
      .build();

    const d = SwaggerModule.createDocument(app, c, {
      include: [module]
    });

    SwaggerModule.setup(globalPrefix + i, app, d, {
      url: `/${globalPrefix + i}-yaml`
    });
    i++;
    swaggerCustomOptions.urls.push({
      name: module.name,
      url: `http://localhost:4400/${globalPrefix + i}-yaml`
    })
  }

// root-path
  const config = new DocumentBuilder()
      .setTitle(`${AppModule.name} API`)
      .setDescription(`${AppModule.name} API`)
    .setVersion('1.0')
    .setExternalDoc('YAML definition file', `/${globalPrefix}-yaml`)
    .build();
  const document = SwaggerModule.createDocument(app, config, {
    include: [AppModule]
  });
  swaggerCustomOptions.urls.push({
    name: AppModule.name,
    url: `http://localhost:4400/${globalPrefix}-yaml`
  })
  swaggerCustomOptions.url = globalPrefix;
  SwaggerModule.setup(globalPrefix, app, document, swaggerCustomOptions);

Unfortunately it doesn't work. (no selection available)

Any help is appreciated. Thanks in advance

covert grove
#

@tall current hello! Did you manage to achieve what you described?