Swagger-ui: In SwaggerUIBundle,validatorUrl set it to null will disable validation is wrong

Created on 21 Apr 2017  路  11Comments  路  Source: swagger-api/swagger-ui

In SwaggerUIBundle,validatorUrl set it to false will disable validation is right.

version:3.0.6

lock-bot bug 3.x

Most helpful comment

I confirm that with latest swaggerUI from master it is still the case:
"False" will disable validation, and remove the badge:

<script>
window.onload = function() {

  // Build a system
  const ui = SwaggerUIBundle({
    url: "http://petstore.swagger.io/v2/swagger.json",
    validatorUrl : false,
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })

  window.ui = ui
}
</script>

"null" will do nothing, and badge still will be there:

<script>
window.onload = function() {

  // Build a system
  const ui = SwaggerUIBundle({
    url: "http://petstore.swagger.io/v2/swagger.json",
    validatorUrl : null,
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })

  window.ui = ui
}
</script>

All 11 comments

What do you mean?

In the swagger-UI README.md

validatorUrl:By default, Swagger-UI attempts to validate specs against swagger.io's online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators (Validator Badge). Setting it to null will disable validation.

[Setting it to null will disable validation.] <- this is wrong
[Setting it to false will disable validation.] <- this is correct

@bodnia can you look into that? it should be null.

Hello, I just downloaded today latest version. Setting validatorUrl to either null or false does not skip validation. It was however working on Friday on previous version. Can you please check?

@psimek12 this is due to #3045.

@psimek12 @icelemon1314 in latest master setting validatorUrl to false/null removes validation badge. Please re-open in case of any issues.

@bodnia It does remove the validation badge. but it does not disable validation. Errors still show up on the top.

I've checked with 3.0.20 and the master

@gayanW - just tested with master and it seems to work as expected. If you're seeing errors at the top, it sounds like a different issue. File a separate ticket and provide a full API definition we can use to investigate.

I confirm that with latest swaggerUI from master it is still the case:
"False" will disable validation, and remove the badge:

<script>
window.onload = function() {

  // Build a system
  const ui = SwaggerUIBundle({
    url: "http://petstore.swagger.io/v2/swagger.json",
    validatorUrl : false,
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })

  window.ui = ui
}
</script>

"null" will do nothing, and badge still will be there:

<script>
window.onload = function() {

  // Build a system
  const ui = SwaggerUIBundle({
    url: "http://petstore.swagger.io/v2/swagger.json",
    validatorUrl : null,
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })

  window.ui = ui
}
</script>

Also, passing an empty value via url parameter like this:
/static/swagger/index.html?url=/api/swagger.json&validatorUrl=
will disable basge.
Passing null or false via url will still show "error" link at the bottom of the page.

Empty value via url parameter doesn't work for me.
http://localhost:9999/swagger.json?validatorUrl=

Passing null or false via validatorUrl removes "error" link at the bottom of the page.
`
$(function () {
var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = window.location.toString();
url = url.substring(0, url.lastIndexOf("/docs")) + "/swagger.json" + "?validatorUrl=";
}
window.swaggerUi = new SwaggerUi({
url: url,
validatorUrl: null,
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
if(typeof initOAuth == "function") {
initOAuth({
clientId: "your-client-id",
realm: "your-realms",
appName: "your-app-name"
});
}

      $('pre code').each(function(i, e) {
        hljs.highlightBlock(e)
      });

      addApiKeyAuthorization();
    },
    onFailure: function(data) {
      log("Unable to Load SwaggerUI");
    },
    docExpansion: "none",
    apisSorter: "alpha",
    showRequestHeaders: false
  });`
Was this page helpful?
0 / 5 - 0 ratings