I've noticed that when you host swagger-ui on a particular domain and you make calls to a CORS enabled api, not all response headers are shown. I think this may be a bug related to the preflight OPTIONS call, but I may just be misunderstanding something.


The response headers should be very similar since the call is made to the same endpoint
I believe that something is going awry when CORS is required. I tested this assumption by hosting the same petstore swagger document locally at http://0.0.0.0:3200/test.json , removing the host property making CORS unnecessary. I received this in response -

Of course the actual call failed (404) since i'm not hosting the api, but I do in fact receive the expected response headers from the dev server.
See if this helps: https://github.com/swagger-api/swagger-ui/issues/3340#issuecomment-313550973
Hey @blortfish!
It's a CORS issue indeed - the browser only exposes a response header to Swagger-UI if that header is listed in Access-Control-Expose-Headers. Note that Allow-Headers (which you did define) is to tell the browser what request headers it can send, and Expose-Headers is to tell the browser what response headers it can read.
There are a few allowed by default, which is why you're seeing some but not all of your headers 馃槃
PS: Looks like @hkosova beat me to it, as usual 馃槈
You might be able to get away with Access-Control-Expose-Headers: * if you only need to support newer browsers - it was added to the Fetch living standard in 2015. Do some checks on your end if you end up using that trick.
Ahh apologies for duplicating. Unfortunately, I don't have access to the API servers that would need to serve up the header. Being that this is part of CORS I don't think there would be any work around. It seems reaching out to API owners is the only option.
That said, if there is some other way around this I'm all ears. If not, feel free to close this issue. Thanks for the quick response!
@blortfish, while you're right in that there's not really a way to throw out CORS.... you do have a couple of options while you wait to hear back:
--disable-web-security command line flag will get you there. Also consider browser extensions, looks like there's a few out there that claim to be able to toggle CORS enforcement on and off.@shockey thank you for all of the suggestions and information. These are all great options to consider. In the end we will be recommending that our users either whitelist headers in Access-Control-Expose-Headers or allow *.
Locking due to inactivity.
This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.
If you think you're experiencing something similar to what you've found here: please open a new issue, follow the template, and reference this issue in your report.
Thanks!
Most helpful comment
@blortfish, while you're right in that there's not really a way to throw out CORS.... you do have a couple of options while you wait to hear back:
--disable-web-securitycommand line flag will get you there. Also consider browser extensions, looks like there's a few out there that claim to be able to toggle CORS enforcement on and off.