swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.39k stars 2.19k forks source link

[swagger-ui][java-play2] Error with using java-play2 with swagger-ui #41

Closed angeloh closed 12 years ago

angeloh commented 12 years ago

When running swagger-ui and read from http://localhost:9000/resources.json, it will give me errors on the console:

[error] application - Cannot determine Path. Nothing defined in play routes file for api method public static play.mvc.Result controllers.UserApiController.updateUser(java.lang.String) [error] application - Cannot determine Path. Nothing defined in play routes file for api method public static play.mvc.Result controllers.PetApiController.addPet() [error] application - Cannot determine Path. Nothing defined in play routes file for api method public static play.mvc.Result controllers.StoreApiController.placeOrder() [debug] application - /store [debug] application - /pet [debug] application - /user [error] application - Could not find route controllers.StoreApiController.placeOrder [error] application - Could not find route controllers.PetApiController.addPet [error] application - Could not find route controllers.UserApiController.updateUser

If I change 'swagger-play2' to 'swagger-play2-utils' in Build.scala, the errors go away but stuck at 'Fetching _store...'.

geeksville commented 12 years ago

swagger-ui is working well for me, but I had to make a few small fixes. I suspect the one you want for this is:

https://github.com/Xeralux/swagger-core/commit/688616e8c87b64b920183c094fa9b31f1a5fb5c4

angeloh commented 12 years ago

I tried you patch.

First, I git pull latest changes from swagger-core repo, and publish local for swagger-play2. Make java-play2 to use local repo jars. Then, I tried you patch. Remove local cache. Republish and recompile.

The result looks the same to me with or without your patch. Only /store.{format} have shown up on swagger-ui, not the other two (/pet and /user). Did you try java-play2 example at your local env?

cainj commented 12 years ago

I'm seeing this issue also, has it been resolved.

fehguy commented 12 years ago

Hi, please pull from this branch:

https://github.com/wordnik/swagger-core/tree/1.1.0-spec

Which will be merged with master shortly. It should work fine and has been tested with the latest swagger-ui

fehguy commented 12 years ago

correction on my last post--the scala play2 app is updated, the java-play2 sample will be shortly. Apologies on that!

fehguy commented 12 years ago

@cainj, @angelokh, this is now fixed--I've committed the java-play2 sample changes here:

https://github.com/wordnik/swagger-core/tree/1.1.0-spec/samples/java-play2

The updated support is in the 1.1.0-SNAPSHOT for swagger-core as well as swagger-play2. You can build each module as needed, or you can grab them from Sonatype:

https://oss.sonatype.org/content/repositories/snapshots/com/wordnik/swagger-core_2.9.1/1.1.0-SNAPSHOT/

And swagger-play2 from our github repo:

http://wordnik.github.com/repository/com.wordnik/swagger-play2_2.9.1/1.1.0-SNAPSHOT/ivys/ivy.xml

Thanks for your patience with this--I'm going to keep this open until I hear that it's resolved the issue, which was based on reading the host class from the route + method name, which was different from java & scala (per our implementation at least):

https://github.com/wordnik/swagger-core/commit/e2bfd57a37f95901f7c95066ea4a164beaea798b

Tested with latest swagger-ui and swagger-codegen

cainj commented 12 years ago

I'm still see these errors. Everything works fine with scala-play, but the java-play not so well. PathParams are not showing up in swagger-ui

fehguy commented 12 years ago

@cainj you mean the stock sample here:

https://github.com/wordnik/swagger-core/tree/1.1.0-spec/samples/java-play2

is not showing up in the ui for you? can you please wipe your ivy cache?

rm -rf ~/.ivy2/local && rm -rf ~/.ivy2/cache

and try again? I'm baffled, just ran the project and it's behaving nicely with the swagger ui.

cainj commented 12 years ago

Did as you suggested and came to the following conclusion. It works like a charm, when I run the sbt console, but if I use the play console, that's when the errors happen. So I think it's a play issue and not swagger. Although, if I run the scala-play2 with the play console it works fine.

fehguy commented 12 years ago

aha! ivy strikes again. Please nuke your play ivy cache as follows:

rm -rf $PLAY_HOME/repository/cache/com.wordnik*  && rm -rf $PLAY_HOME/repository/local/com.wordnik*

That should do it--please post back after you give it a shot.

cainj commented 12 years ago

That did it. You are the man!

The ivy cache can really mess things up. Thanks again.

fehguy commented 12 years ago

Awesome, glad that did it

fehguy commented 12 years ago

closing this out, if issue comes back, please reopen. Now pushed to master, artifacts in maven central