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.

Configure swagger-ui-dist URL server side

See original GitHub issue

Is your feature request related to a problem?

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 without modifying the node_module folders or without having an endpoint that accept requests for the index.html and that serves the modified index. Both this solution are not acceptable, in fact for the first one it’s clearly a bad practice to change the node_modules folder content on runtime and for the second I cannot replace an example URL that I have no certainty it will be constant in each update.

Describe the solution you’d like

I do not know a clear solution for this problem. Maybe the only way is indeed to modify the content of the index.html but at least I was expecting that there will be a function to do that inside the library. Maybe this is the simplest solution.

Describe alternatives you’ve considered

  • [ ] Save index.html content and serve it to the index.html endpoint (not so usable without Express or similar)
  • On application startup replace https://petstore.swagger.io/v2/swagger.json with my JSON swagger configuration endpoint.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:13
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
gonendukcommented, Jan 16, 2022

@deusama That was my workaround but it stopped working with version 4.1.3. Reading the url as a query parameter is blocked now.

0reactions
WeetA34commented, Aug 5, 2022

or

const express = require('express')
const fs = require('fs')
const path = require('path')
const pathToSwaggerUi = require('swagger-ui-dist').getAbsoluteFSPath()

const indexContent = fs.readFileSync(path.join(pathToSwaggerUi, 'swagger-initializer.js'))
    .toString()
    .replace('https://petstore.swagger.io/v2/swagger.json', '/path/to/swagger.json')

const app = express()
app.get('/swagger-initializer.js', (req, res) => res.send(indexContent))
app.use('/path/to/swagger.json', express.static(path.join(__dirname__, 'swagger.json')))
app.use(express.static(pathToSwaggerUi))

app.listen(8080)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Installation - Swagger Documentation
In contrast, swagger-ui-dist is meant for server-side projects that need assets to ... You can also provide a URL to a swagger.json on...
Read more >
Configuring and Using Swagger UI in ASP.NET Core Web API
In this tutorial, we're going to talk about configuring and using Swagger UI. Swagger UI offers a web-based interface that allows anyone to ......
Read more >
Swagger UI tutorial | Documenting APIs - Idratherbewriting.com
By default, SwaggerUI has the Petstore OpenAPI document configured in the url parameter in the index.html file. You need to swap in your...
Read more >
How can I get the html string from swagger-ui-dist?
It turns out that swagger-ui-dist is not really meant for server-side rendering the way it implies. It just includes the files.
Read more >
Top 5 swagger-ui-dist Code Examples - Snyk
Learn more about how to use swagger-ui-dist, based on swagger-ui-dist code ... SwaggerUI files to ${path.basename(outputPath)}/`); // replace api url to ...
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