Swagger-ui: Altering default URL of API spec Swagger UI points to

Created on 4 Sep 2017  路  4Comments  路  Source: swagger-api/swagger-ui

The documentation mentions that you should 'change the default URL in the constructor' of Swagger UI to ensure other API specifications are filled in there.
As I'd like to present my APIspecification using Swagger UI on my website as the main source of the API's documentation, I wanted to alter this.

However, I am unable to find the snippet of constructor code anywhere inside the downloaded swagger-ui repository. Attempts to alter swagger-config.yaml or /src/core/index.js did not work, even when running npm build after this.

Is the documentation outdated, or am I missing something?

In any case, I think a reference to the proper file to edit the default URL would improve the documentation.

| Q | A
| ------------------------------- | -------
| Bug or feature request? | Bug
| Which Swagger/OpenAPI version? | 3
| Which Swagger-UI version? | 3.1.7
| How did you install Swagger-UI? | Cloning the Git repository. (master branch)
| Which browser & version? | Any (Tested Chromium and Firefox)
| Which operating system? | Linux Mint

Demonstration API definition


your: "API definition goes here"

Configuration (browser query string, constructor, config.yaml)

{
  "your": { "constructorConfig": "here" }
}

?yourQueryStringConfig=here

Expected Behavior


Current Behavior


Possible Solution


Context


lock-bot support

Most helpful comment

The constructor is in dist/index.html, it looks like this:

<script>
window.onload = function() {

  // Build a system
  const ui = SwaggerUIBundle({
    url: "http://petstore.swagger.io/v2/swagger.json",
    ...

You can change the url here.

The doc you linked to is a bit outdated, use the repository README instead.

All 4 comments

The constructor is in dist/index.html, it looks like this:

<script>
window.onload = function() {

  // Build a system
  const ui = SwaggerUIBundle({
    url: "http://petstore.swagger.io/v2/swagger.json",
    ...

You can change the url here.

The doc you linked to is a bit outdated, use the repository README instead.

Wonderful! I don't know why, but I had the feeling that the dist folder was the location that the whole project compiled to (which is true), which would mean that these kinds of settings would be made outside of it and then compiled to those files (which is not, the index.html seems to be one of the files that is untouched).

Thank you for your very clear answer!

I changed that to my url but it is giving me a failed to load API definition.

@PaulB88 It's hard to help without knowing more details. Please open a new issue and fill in the template. Thanks!

Was this page helpful?
0 / 5 - 0 ratings