Swagger-ui: No operations defined in spec when Content-Type is missing/wrong

Created on 20 Mar 2017  路  18Comments  路  Source: swagger-api/swagger-ui

I was trying the v3 on a test server and I noticed that if the response to the xhr request to obtain the specification file does not have the proper Content-Type (missing or set to a wrong type) it will fail with No operations defined in spec!. Setting the proper type ( application/json for json or text/plain; charset=utf-8 for yaml) fixes the problem.
Sorry if this the expected behaviour.

Most helpful comment

No the problem is in the response the server returns with the spec file. It must have the appropriate Content-Type.
You can use the browser debugger to see the network request and their details

All 18 comments

@CaselIT is that test server public?

Tried both private and public, the behaviour is the same

Do you have a public one to share with us so we can see the behavior?

Not at the moment (I was using my work machine since it has a public ip).
I can share a repo with a test server similar to the one I was using it this can help

If it's not too much trouble, yeah.

Added a repo
https://github.com/CaselIT/swagger-ui-2743

The files in the folder swagger-ui are from this repo, the index.html is the same with just the paths updated, while the spec files are from the swagger examples in https://github.com/OAI/OpenAPI-Specification/tree/master/examples/v2.0

even i am facing the same issue . My spec file is in dist folder itself . I have given the relative path to it .
i see that file is being loaded with 200 status but i get this error

No operations defined in spec!
when i click on the error i get this
{"schemaValidationMessages":[{"level":"error","message":"Can't read from file http://localhost:2000/Master.yaml"}]}

@rockeshub The validation error is normal, since an external website can't access your local network.

For me specifying the Content-Type header fixes the No operations defined in spec! problem?

@CaselIT where did you add the Content-Type header inside the spec file or some other file

No the problem is in the response the server returns with the spec file. It must have the appropriate Content-Type.
You can use the browser debugger to see the network request and their details

ya Content-type is application/octet-stream how can i change this .

It really depends on the server you are using.
Check the repo I provided if you are using the builtin python one

ok thank you

We have a pending fix for the issue, hoping to have that in master later today.

Great, thanks @webron

Same problem here, could work around it defining the content-type for the swagger.json (json/application), didn't work with the swagger.yaml (text/plain) though

2755 should fix this. Hoping to merge later today.

Should be fixed. Please reopen if needed.

Was this page helpful?
0 / 5 - 0 ratings