wkennedy / swagger4spring-web

Swagger support for Spring MVC
89 stars 46 forks source link

List<MyClass> is not display correctly #21

Closed seawatts closed 10 years ago

seawatts commented 11 years ago

When I have a controller method that returns List in the documentation it says the "Response Class" is:

Model | Model Schema List { empty(boolean optional) }

the controller method looks like this: @RequestMapping(method = RequestMethod.GET) @ResponseBody public List< GroupMember > getMembers() { ... myCode... }

Do you know why this could be?

Also, sorry this is a separate subject but you seem to be pretty responsive so I thought I would ask you, is there a way to gather the documentation from the JavaDocs in code? or do you have to use the @Api annotations?

wkennedy commented 11 years ago

Unfortunately, this issue has come up a few times. The problem here is do to type erasure in Java generics. From Java generics entry in Wikipedia:

"Generics are checked at compile-time for type-correctness. The generic type information is then removed in a process called type erasure. For example, List will be converted to the non-generic type List, which ordinarily contains arbitrary objects. The compile-time check guarantees that the resulting code is type-correct. As a result of type erasure, type parameters cannot be determined at run-time."

That being said, they introduced in Swagger-Core the ability to handle generics using the @ApiOperation annotation, like so:

@ApiOperation.responseClass="foo.bar.A<foo.bar.B,foo.bar.C>"

I just tested this, but was not able to get it to work. I'm looking into why it's not generating the documentation correctly.

wkennedy commented 11 years ago

Just saw your other question, "is there a way to gather the documentation from the JavaDocs in code? "

I could possibly add functionality to gather information from JavaDocs, but currently it doesn't handle that. If you can add the Swagger annotations, that would be the best solution, but I understand that isn't always possible.

seawatts commented 11 years ago

How fast could you implement that? Or should I try to give it a go. I'm in a rush and if we could work together on getting this done that would be great.

wkennedy commented 11 years ago

Honestly, I don't have much time to work on this at the moment. I'm swamped with other work, currently. Please feel free to give it a go, however, I will say it's probably take a bit of work. I'm also trying to get this project to work with Swagger 1.3, so there is a lot to be done. I'm sorry I can't get this done for you in time.

seawatts commented 11 years ago

Yeah, I was looking through the source and I'm not sure if I would know where to start lol I guess I'll just have to annotate with the default swagger annotations. With that being said, is there a location I can view all the available annotations?

wkennedy commented 11 years ago

Even using the Swagger annotations you might run into issues with generics. I know it might not be ideal for your code, but if you use arrays instead of List, that works well. Here is the list of annotations:

Api ApiClass ApiError ApiErrors ApiOperation ApiParam ApiParamImplicit ApiParamsImplicit ApiProperty ApiResponse ApiResponses

You can find examples of some of these here: https://github.com/wkennedy/swagger4spring-web-example

wkennedy commented 10 years ago

This is resolved with the addition of response and responseContainer in Swagger 1.3 @ApiOperation.