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 UI Dist Config

See original GitHub issue

Temporary solution: …open-api.controller.ts

 @Get('/')
  async index(ctx: Context) {
    ...
    const template = await promisify(readFile)(join('your_custom_index_template_path/index.tpl.html'), 'utf8');
    ...
}

…your_custom_index_template/index.tpl.html

...
const ui = SwaggerUIBundle({
        {{ urls }},{{ primaryName }}
        dom_id: '#swagger-ui',
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "StandaloneLayout",
        ...more config here
      })
...

I think this is quite inconvenience now. Maybe we should add swaggerui option in the option of opneapi if we are still using swagger-ui-dist? Or maybe adding this tutorial to cookbook if nothing is gonna change in short time?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
LoicPoullaincommented, Jul 22, 2019

Ok, I see. I took a look at the Swagger documentation as well, most of the options can be “stringified”.

Here how I see how to update to the SwaggerController:

export abstract class SwaggerController {
  // ...

  abstract options: ... // Current options that are used both to render the templates and determine the route behaviors.

  uiOptions: object = {} // Additional swagger UI options that can be override.

  // ...
}

// Example
class DocumentationController extends SwaggerController {
  options = { controller: ApiController };

  uiOptions = { docExpansion: 'none' };
}

To implement this, we need to:

  • Update index.tpl.html.

    const ui = SwaggerUIBundle(Object.assign({
       // Current content
    }, {{ uiOptions }}));
    
  • Update the files index.*.spec.html (that test template renders for each scenario) to end with:

    }, {}));
    
  • Add two new tests to swagger-controller.spec.ts:

    SwaggerController > has a "index" method that > should properly render the template given options are { url: "xxx" } and uiOptions are { docExpansion:"none" }.. Spec file to add: index.url.ui-options.spec.html.

    SwaggerController > has a "index" method that > should properly render the template given options are [{ url: "v1.json", name: "v1" }] and uiOptions are { docExpansion:"none" }. Spec file to add: index.no-primary.ui-options.spec.html.

  • Finally update swagger-controller.ts to use the uiOptions with JSON.strifigify (lines 94 & 109)

0reactions
LoicPoullaincommented, Jul 24, 2019

Don’t worry, the PR does not require to add too much code. The two new tests are pretty much a copy-past of old ones as well as the new template specs. If you feel like to take it, I’ll assign it to you.

should properly render the template given options are { url: "xxx" } and uiOptions are { docExpansion:"none" } inspired from should properly render the template given options are { url: "xxx" }

should properly render the template given options are [{ url: "v1.json", name: "v1" }] and uiOptions are { docExpansion:"none" } inspired from should properly render the template given options are [{ url: "v1.json", name: "v1" } ...]

index.url.ui-options.spec.html inspired from index.url.spec.html

index.no-primary.ui-options.spec.html inspired from index.no-primary.spec.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration - Swagger Documentation
Swagger UI accepts configuration parameters in four locations. From lowest to highest precedence: The swagger-config.yaml in the project root directory, if it ...
Read more >
Configure swagger-ui-dist URL server side #5710 - GitHub
This issue is related to the #4624 and the swagger-ui-dist library. There is no way to change the url on the server side...
Read more >
swagger-ui-dist - npm
Start using swagger-ui-dist in your project by running `npm i swagger-ui-dist`. There are 368 other projects in the npm registry using ...
Read more >
How to use the swagger-ui-dist.absolutePath function in ...
To help you get started, we've selected a few swagger-ui-dist.absolutePath examples, based on ... config'; export default () => { const swaggerIndex =...
Read more >
Swagger UI tutorial | Documenting APIs - Idratherbewriting.com
In your command prompt, browse to the Swagger UI dist directory. To browse in the Windows command ... Configuring Swagger UI parameters.
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