How can I disable parameter and request body validation in swagger-ui?
Q&A
- OS: Windows 11
- Browser: Chrome
- Version: 126.0.6478.183
- Method of installation: Plain old HTML/CSS/JS (Standalone)
- Swagger-UI version: 5.17.14
- Swagger/OpenAPI version: OpenAPI v2.0
Content & configuration
Swagger-UI configuration options:
SwaggerUIBundle({
url: window.location.href.substring(0, window.location.href.lastIndexOf('swagger/') + 'swagger/'.length - 1) + "/v2/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
tryItOutEnabled: true
});
Screenshots
How can we help?
I would really like a way to disable parameter and request body validation in swagger-ui. We are using swagger purely as documentation, and as a way to demo our rest api. We have our own validation engine implemented in our backend, which we are unable to test because swagger-ui parameter validation will not send a request where a parameter is f.ex. less than what is specificed via a "minimum" constraint, see part of the schema definition below:
"VedvarendeEnergiOplysningerDTO": {
"properties": {
"maksAntalVindmoeller": {
"type": "integer",
"format": "int32",
"description": "Gemmes kun hvis specifik anvendelse Vindmølleanlæg (8111) er angivet.",
"minimum": 0,
"maximum": 9999999
}
},
"type": "object"
}
We can not test that this minimum constraint works in our backend, because swagger-ui refuses to send the request in the first place. But it refuses to send the request without any feedback to the user. So now I'm wondering, is there a way to disable this validation?
I checked the source code, and in execute.jsx the onClick callback for the Execute button calls handleValidateParameters() and handleValidateRequestBody(), that I would like it to skip.
Looks like you can disable validation or set a different validator by changing the validatorUrl parameter
Setting it to either none, 127.0.0.1 or localhost will disable validation.
https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
The validatorUrl does not work, either null or above values. The validatorUrl is for another purpose: validate the swagger.json itself, instead of the input data check before clicking the execute button.
I also really want to disable client side input check, seems I have to modify the source code, or degrade to a lower version.
See my example, there is an optional integer property "cidr", if I just input a string, then a error popup occurs, cause the request can not be sent. But actually I want to test the case input a string to the property.