Closed fehguy closed 10 years ago
What official Play2 version and manually compiled swagger-core branch/tag combination can one use in the meantime to correctly build and a working java-play2 or scala-play2 sample? I've tried a variety of different combinations and though some can compile, various issues have cropped up at run-time.
I'm very interested in the answer to this question, too. What's the most up-to-date combination that actually compiles?
Check this merge request:
Steps:
to be clear, this is not an update to swagger-core 1.3, or am I missing something?
The reference above is about swagger-core-1.2.5 integrated with Play 2.2.0 For swagger-core-1.3 integrated with Play 2.2.0, please see my fork here:
Thanks for the work on your fork, I have been using it and it appears to be working, except I can only get implicit parameters working, the regular parameters appear to be ignored. Have you had any trouble with these?
Pls give me a simple example to add to test/testdata/DogController, or one of the other test controllers in there. I'll create a bunch of test cases for existing functionality tomorrow (if time allows), and then perhaps you can help me get the details right for some more test-cases that need to be implemented next. thnx.
On 25 September 2013 15:51, tjslone notifications@github.com wrote:
Thanks for the work on your fork, I have been using it and it appears to be working, except I can only get implicit parameters working, the regular parameters appear to be ignored. Have you had any trouble with these?
— Reply to this email directly or view it on GitHubhttps://github.com/wordnik/swagger-core/issues/307#issuecomment-25092425 .
No problem - here is an example of what I was using:
This example caused there to be no parameters returned ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Delete a user @ApiOperation(value = "Delete", notes = "Deletes a user", httpMethod = "DELETE") def delete( @ApiParam(name = "userId", value = "userId")@PathParam("userId") userId: String) = Action.async { implicit request => val FutureDeleteUserResult = UserModel.delete(userId) FutureDeleteUserResult.map{ case result: Boolean => { if(result) Ok("User Deleted") else BadRequest("Delete failed") } } recover { case iu: InvalidUserException => Unauthorized(iu.getMessage()) case ex: QueryErrorException => ServiceUnavailable(ex.getMessage()) case se: ServerNotAvailable => ServiceUnavailable(se.getMessage()) case _ : Exception => BadRequest("Unknown error") } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Sorry - I forgot to simplify it!! ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Delete a user @ApiOperation(value = "Delete", notes = "Deletes a user", httpMethod = "DELETE") def delete( @ApiParam(name = "userId", value = "userId")@PathParam("userId") userId: String) = Action.async { implicit request => Ok } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I included: "com.wordnik" %% "swagger-play2" % "1.2.5-2"
[trace] Stack trace suppressed: run last :update for the full output. [error](:update) sbt.ResolveException: unresolved dependency: com.wordnik#swagger-play2_2.10;1.2.5-2: not found [error] Total time: 6 s, completed 26.09.2013 13:50:18
It seems like this dependency con't be found.
This is my workaround to get my project compiled. "com.wordnik" %% "swagger-play2" % "1.2.5" exclude("org.scala-stm", "scala-stm_2.10.0"),
@OliverKK
@tjslone I have just pushed a bunch of changes to my fork (https://github.com/andyoll/swagger-core/tree/play_2.2.0-swagger_1.3) - parameter annotations are now supported, and the test coverage is increasing. I'm sure there will be some more to do, so I'd really appreciate any further feedback or failing test-cases you can give.. Stuff that I know of as work-in-progress:
@andyoll Thank your for the bunch of changes. Just updated today. I'm testing the 1.2.6-SNAPSHOT ("com.wordnik" %% "swagger-play2" % "1.2.6-SNAPSHOT",) in my Play2.2 / Scala project.
First thing i saw was following messages.
[error] c.w.s.c.u.TypeUtil$ - Unable to load class double [error] c.w.s.p.HelpApi - Skipping model play.api.libs.json.JsValue. Did not find any public fields or bean-properties in this model. If its a scala class its fields might not have @BeanProperty annotation added to its fields.
@OliverKK that's not really an error, in later builds of swagger-core it is an INFO. Can you update to 1.3.1-SNAPSHOT? See here...
https://groups.google.com/forum/#!topic/swagger-swaggersocket/lN99-GetOLY
@fehguy @andyoll Updated right now to 1.3.1-SNAPSHOT The [error] messages turned obviously to [info] which is very good :)
Swagger returns currently: "Unable to read api 'user' from path http://localhost:9000/api-docs/api-docs/user (server returned Not Found)"
The path "...api-docs/api-docs..." seems to be wrong...
Hi
In branch 'develop' there exist test cases showing it works nice for @ApiOperation( responseClass=
[info] + returns 'void' for 'responseClass' when not defined [info] + adds 'responseClass' when defined [info] + adds 'responseClass' correctly when defined as list
from PlayAPIReaderSpec.
The API reader only gets into action for a class or method if it is referenced in the routes file, so perhaps this is an issue? Perhaps post both routes file and controller code.
Regarding @ApiErrors - this is not supported, but there is support for: @ApiResponses -- I wonder if I was right in assuming this was the right way to do things with Swagger-core 1.3 ? I may have got this wrong..
The example play2 app may be helpful to you in demonstrating what works.
regards
Andy
On 17 October 2013 10:23, OliverKK notifications@github.com wrote:
@fehguy https://github.com/fehguy Updated right now. It seems like some annotations are not recognized anymore. @ApiErrors and @ApiOperation( responseClass=
— Reply to this email directly or view it on GitHubhttps://github.com/wordnik/swagger-core/issues/307#issuecomment-26489901 .
Hi folks, the @ApiErrors was renamed to @ApiResponses because it's not just for documenting error states. There are some slight differences in the signature but switching between the annotations is very simple. See here:
and here:
@andyoll Thank you for the quick answer.
Following the routes and controller code:
routes
GET /api-docs controllers.ApiHelpController.getResources GET /api-docs/user controllers.ApiHelpController.getResource(path = "/api-docs/user")
GET / controllers.Index.view
Controller: User.scala
@Path("/user") @Api(value = "/api-docs/user", description = "Manages requests for the user part of the api.") @Produces(Array("application/json")) class User @Inject() (userService: UserService) extends Controller {
@POST @Path("/user/{register}") @ApiOperation( value = "value", notes = "notes", response = classOf[Reg] ) @ApiResponses(Array( new ApiResponse(code = 110, message = "Bad JSON format."), ))
Does your routes file define routes to the User controller? - without this the annotations are not read, cos the API is not available.
On 17 October 2013 17:28, OliverKK notifications@github.com wrote:
@andyoll https://github.com/andyoll Thank you for the quick answer.
Following the routes and controller code:
routes Swagger - Root Resources Listing
GET /api-docs controllers.ApiHelpController.getResources GET /api-docs/user controllers.ApiHelpController.getResource(path = "/api-docs/user")
index path
GET / controllers.Index.view
Controller: User.scala
@Path https://github.com/Path("/user") @Api(value = "/api-docs/user", description = "Manages requests for the user part of the api.") @Produces(Array("application/json")) class User @Inject https://github.com/Inject() (userService: UserService) extends Controller {
@POST https://github.com/POST @Path https://github.com/Path("/user/{register}") @ApiOperation( value = "value", notes = "notes", response = classOf[Reg] ) @ApiResponses(Array( new ApiResponse(code = 110, message = "Bad JSON format."), ))
— Reply to this email directly or view it on GitHubhttps://github.com/wordnik/swagger-core/issues/307#issuecomment-26524024 .
@andyoll Yes i define a route to my user controller.
POST /user/register @controllers.User.register()
The url's "http://localhost:9000/api-docs" and "http://localhost:9000/api-docs/user" deliver valid json.
So I made a guess that using the @controllers syntax in order to use a class as a controller might be an issue, since I hadn't tried this. But I've added a bunch of test cases for this scenario, and they all pass so far. Next Step - I'll add a class as controller to the play2 test app, and confirm this works (or fix it if not). Hopefully I can get on to this this w/e, and let you know.
If you are in a hurry, I suggest you download the play2 test app, run it up to satisfy yourself it does what you'd expect, add a similar controller and routes to what you are playing with, and see what happens. If this doesn't work you should send me your additions to the test app that recreate this issue.
On 18 October 2013 07:42, OliverKK notifications@github.com wrote:
Yes it does:
User registration
POST /user/register @controllers.User.register()
— Reply to this email directly or view it on GitHubhttps://github.com/wordnik/swagger-core/issues/307#issuecomment-26575077 .
@OliverKK the play2 module in branch 'develop' is 100% compatible with '@controllers syntax in order to use a class as a controller'. this pull request is full of test cases, and also an update to the scala-plauy2 sample app demonstrating this behaviour:
I suggest you get the sample app working (from this pull request branch), and then consider what you are doing differently in your app.
On 19 October 2013 10:45, Andy Olliver andy@slyfrog.com wrote:
So I made a guess that using the @controllers syntax in order to use a class as a controller might be an issue, since I hadn't tried this. But I've added a bunch of test cases for this scenario, and they all pass so far. Next Step - I'll add a class as controller to the play2 test app, and confirm this works (or fix it if not). Hopefully I can get on to this this w/e, and let you know.
If you are in a hurry, I suggest you download the play2 test app, run it up to satisfy yourself it does what you'd expect, add a similar controller and routes to what you are playing with, and see what happens. If this doesn't work you should send me your additions to the test app that recreate this issue.
On 18 October 2013 07:42, OliverKK notifications@github.com wrote:
Yes it does:
User registration
POST /user/register @controllers.User.register()
— Reply to this email directly or view it on GitHubhttps://github.com/wordnik/swagger-core/issues/307#issuecomment-26575077 .
pushed to maven central
http://oss.sonatype.org/content/repositories/releases/com/wordnik/swagger-play2_2.10/1.3.1/
@fehguy @andyoll Thank you for caring about this issue and pushing to maven central. Swagger 1.3.1 works very very fine with play 2.2.
Great @OliverKK !
The play2 module is not supported with 1.3 core yet.