Closed dagnelies closed 5 years ago
However, RapiDoc strangely declares that the API server is
//api-docs//localhost:8080/
is the server declared as //api-docs//localhost:8080/
or /localhost:8080/api-docs
?
What is the location of your swagger spec?
General assumption is, If there is no server provided in the spec, then rapidoc considers the location of the spec as the base-url for making the API calls
the other way to workaround it, if you have not defined a server in your spec then provide it as an attribute in the element
<rapi-doc spec-url="swagger.json" server-url="localhost:8080"> </rapi-doc>
or if you want to dynamically set it
document.addEventListener('DOMContentLoaded', function () {
document.getElementsByTagName("rapi-doc")[0].setAttribute("server-url", location.origin+"/api")
});
Thanks for the prompt response. The use case is pretty common:
http://localhost:8080/v2/api-docs
, containing "host":"localhost:8080"
http://localhost:8080/rapidoc.html
, with the component defined as <rapi-doc spec-url="/v2/api-docs"></rapi-doc>
Somehow the API server in Rapi becomes //api-docs//localhost:8080/
...very confusing.
If I add server-url="localhost:8080"
to the component, both servers are suggested, which is still undiserable.
More examples:
Rapi Def | API server(s) |
---|---|
<rapi-doc spec-url="/v2/api-docs"></rapi-doc> |
//api-docs//localhost:8080/ |
<rapi-doc spec-url="http://localhost:8080/v2/api-docs"></rapi-doc> |
http://localhost:8080//localhost:8080/ |
<rapi-doc spec-url="/v2/api-docs" server-url="localhost:8080"></rapi-doc> |
//api-docs//localhost:8080/ and localhost:8080 |
<rapi-doc spec-url="http://localhost:8080/v2/api-docs" server-url="localhost:8080"></rapi-doc> |
http://localhost:8080//localhost:8080/ and localhost:8080 |
My guess is that my Swagger Definition does not contain "schemes", and because of that, the converter swagger2openApi somehow fails to provide correct "servers" ...or something of that sort.
...I only have host
and basePath
I can confirm that when adding schemes
in the swagger definition. It would be great if RapiDoc could infer the scheme from the current URL if it is missing ...I think it's an optional thingy anyway.
Thanks for the detailed analysis, However, if its behaving the way you mentioned is definitely buggy, can you share your swagger spec, and I will see how best can we answer this issue
The swagger spec is 2000 lines, so it's a bit verbose ;) Here is the "top-level":
{
"swagger":"2.0",
"info":{...},
"host":"localhost:8080",
"basePath":"/",
"tags":[...],
"schemes":["http","https"], <- adding/removing this line make the API server resolution work/break
"paths":{...},
"securityDefinitions":{...},
"definitions":{...}
}
Thanks for sharing, I tried to address this issue release 5.0.4, can you confirm if it takes care of your use case
Works, thanks for the prompt fix! 👍 🎉
Hi,
In my swagger definition, I have
"host":"localhost:8080"
.However, RapiDoc strangely declares that the API server is
//api-docs//localhost:8080/
...which causes all "try" requests to fail of course.
AFAIK
api-docs
is solely the name of the swagger definition file.