Closed rmpestano closed 9 years ago
Hi Rafael,
Have you tried using the -apiBasePath doclet option to set the api base path to point to the server you want?
Conor
Hi Conor, the idea is to let it dynamic, how can I do that?
my idea is to query any rest api via swagger ui (this is already working but the requests are sent only to the server where swagger ui is) so base path must be dynamic, something like a service catalog
swagger ui is a separate project to this https://github.com/swagger-api/swagger-ui , this project generates the json files, if you cant get it working you should raise an issue with the swagger-ui project
However I have spent time checking if the issue you describe happens using the dropwizard sample bundled with the doclet which has swagger-ui-2.0.24 embedded in it but with some patches to the swagger.js and swagger-ui.js i made for a different reason described here https://github.com/teamcarma/swagger-jaxrs-doclet section -docBasePath. I was able to make calls to apis on a different port to the one running the api doc
To see this:
1) Start the dropwizard sample: cd swagger-doclet-sample-dropwizard mvn package java -jar target/swagger-doclet-sample-dropwizard*.jar server sample.yml
2) go to http://127.0.0.1:7070/apidocs/ in a browser
you should see this:
3) enter a url to a service.json on another server and if cors is setup it should work, in my case i just tested against apis hosted on a different localhost port, here is an example:
Hi conor, thanks for you time and help.
I have patched swagger-ui 2.0.24 and got the same behaviour, i can fetch other apis but the request is always to localhost.
I will take a look at dropwizard example. thanks again.
ive just tried using swagger-ui-2.1.8-M1 and it seems to work well for me in terms of making api calls to a remote api you should see if that works for you
ive now upgraded the doclet to use swagger-ui-2.1.8-M1 by default and in the dropwizard sample, note the shred.js patch which was needed for swagger-ui 2.0.X does not work with 2.1.x so should not be applied.
Hi again, here is what happens when i try to consume an external api with the dropwizard sample:
See that swagger-ui is trying to fetch remote services on local app and obviously its not found. I did not faced this because I was featching the same app on different server. The idea is to have a dedicated app which will serve as a service catalog. Maybe swagger-ui is not prepared for that.
Thanks for your help so far.
hmmm my version of swagger-ui is different on that server..will try to update there and see if it works
same problem...it is trying to GET resource definition (.json) on the app which is firing the request (dropwizzard sample in this case) and so receiving a http://localhost:7070/soews/apidocs/documentos.json 404 (Not Found)
for me if i point the dropwizard sample at carma's service.json https://api-dev.car.ma/apidoc/ref/service.json it loads the resource json files fine, that service.json file has relative api paths e.g.:
{ "swaggerVersion" : "1.2", "apiVersion" : "1", "basePath" : "https://api-dev.car.ma/apidoc/ref", "apis" : [ { "path" : "/login.{format}" }, { "path" : "/discovery.{format}" }
Can you check if you can point at https://api-dev.car.ma/apidoc/ref/service.json from the dropwizard sample of the latest snapshot? make sure after updating with git that you run mvn package before restarting the dropwizard server and clear browser cache/use incognito window, if you can access it ok then it could be something different in the service.json file of your service such as an absolute api path that is incorrect.
ok, the problem with my api is with base path:
{ "swaggerVersion" : "1.2", "apiVersion" : "1", "basePath" : "/soews/apidocs", "apis" : [ { "path" : "/documentos.{format}" }, { "path" : "/usuarios.{format}" }, { "path" : "/dadosAdicionais.{format}" }, { "path" : "/ldap.{format}" }, { "path" : "/logon.{format}" } ] }
many thanks for your help Conor, keep the great work!
closing this issue/question
Hi there, this is a question on how can i change the api base path, let me clarify.
I am consuming services.json present on my network and this works great, see image below:
although i can read service.json from any application on my network (using cors) when i fire a request it goes to localhost (the base url).
How can i fire requests to other applications rest apis?
thanks in advance.