41

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

lostintranslation
  • 23,756
  • 50
  • 159
  • 262

3 Answers3

41

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",
pmaruszczyk
  • 2,157
  • 2
  • 24
  • 49
Sasha Bond
  • 984
  • 10
  • 13
18

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

atlithorn
  • 401
  • 4
  • 8
  • 4
    I get the same error as OP but the validation on the herokuapp tells me success, no error... – JP Moresmau Feb 29 '16 at 13:42
  • An easier way to check a Swagger spec for syntax errors is go to http://editor.swagger.io and import your spec. (This approach does not require the Swagger JSON Schema file.) – Helen Jul 02 '18 at 11:52
4

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.

Ron
  • 14,160
  • 3
  • 52
  • 39
  • Thanks @webron. I get an internal server error when I click that icon. I generated the swagger 2.0 doc with the swagger editor and I did not see any errors. That being said I know the UI and Editor are in different states of complying to the 2.0 spec. Not sure if they user different validators. I will see about trimming down the spec a few paths at a time to see if I can identify the location of the error. – lostintranslation Jan 07 '15 at 18:56
  • 1
    I just noticed you edited the question. Did you edit the validatorUrl parameter of SwaggerUi? Is the server deployed on localhost? – Ron Jan 07 '15 at 19:08
  • Not on localhost. As a test I grabbed the petstore_simple.yaml from the editor, downloaded it as JSON and served that out as my swagger doc. I am serving over https:/api/api-docs I verified that I can grab the swagger doc itself via that url and it works just fine. Not overriding the validatorUrl. validation is going to: http://online.swagger.io/validator/debug?url=https:///api/api-docs Seems like its https that is screwing it up. – lostintranslation Jan 08 '15 at 00:37
  • 1
    It works fine with https, as long as the certificate is fine - http://online.swagger.io/validator/debug?url=https://raw.githubusercontent.com/webron/test/master/swagger.json – Ron Jan 08 '15 at 07:00
  • K, not https but must be something with the validator. Try this: http://online.swagger.io/validator/debug?url=https://github.com/swagger-api/swagger-spec/blob/master/examples/v2.0/json/petstore-expanded.json – lostintranslation Jan 10 '15 at 16:12
  • 1
    That's not a link to the json file. It's a link to the github page holding the json file. Try http://online.swagger.io/validator/debug?url=https://raw.githubusercontent.com/swagger-api/swagger-spec/master/examples/v2.0/json/petstore-expanded.json instead which likes to the actual json file. – Ron Jan 10 '15 at 16:19
  • Ah yes, crap. I still have no idea. Its definitely something on my server. Certificate looks ok, triple checked it. Can get the json from my request just fine. Turning off validation works and all the Try it methods work as well. I will keep digging, thanks. – lostintranslation Jan 10 '15 at 19:33
  • If it's publicly accessible and you can share, I can check it as well. – Ron Jan 10 '15 at 19:57