Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger UI shows error (validation) when deployed

I have the swagger ui embedded in my application. And when I run my node application locally the UI works great.

However when I deploy the UI to my 'real' server I get an error image in the bottom right of my swagger ui:

enter image description here

I am sure this is something I am doing that is screwing it up but I have no idea. Again works locally when I access swagger ui via http.

However when I deploy I run through apache and serve out over https, I see an error. Even worse none of my 'Try it' calls work when deployed. Seems like the request is not being made.

Looks like the UI makes a call to a validator with my swagger.json, however that call works locally.

What am I doing wrong?

When I click the error icon, I get:

enter image description here

like image 206
lostintranslation Avatar asked Jan 06 '15 23:01

lostintranslation


People also ask

Does swagger do validation?

Well, Swagger Editor does add it's own additional layer of error recognition on top of JSON Schema validation.

What is the difference between Swagger and Swagger UI?

Swagger Editor: Swagger Editor lets you edit OpenAPI specifications in YAML inside your browser and to preview documentations in real time. Swagger UI: Swagger UI is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from an OAS-compliant API.


3 Answers

To turn off swagger validator add validatorUrl : null, in dist/index.html in

  window.swaggerUi = new SwaggerUi({
    url: url,
    validatorUrl : null,
    dom_id: "swagger-ui-container",
like image 108
Sasha Bond Avatar answered Nov 03 '22 14:11

Sasha Bond


When this happens (and it sometimes does) I go here:

http://json-schema-validator.herokuapp.com/index.jsp

Paste the swagger schema from here https://github.com/swagger-api/swagger-spec/blob/master/schemas/v2.0/schema.json in the schema field and then your spec in the data field

like image 18
atlithorn Avatar answered Nov 03 '22 14:11

atlithorn


Swagger-UI is able to handle some malformed specs, which is probably why it is works locally.

By default, the validation process does not run when the spec is read from localhost. You should be able to run it still, if you wish, using the validatorUrl (https://github.com/swagger-api/swagger-ui#parameters).

To see the validation errors, just click on the ERROR icon, and it will give you a list of problems with your spec.

like image 4
Ron Avatar answered Nov 03 '22 12:11

Ron