swagger-api / swagger-play

Apache License 2.0
330 stars 181 forks source link

@ApiImplicitParam weird error when dataType is a generated model #131

Open JFCote opened 7 years ago

JFCote commented 7 years ago

When using @ApiImplicitParam like this:

@ApiImplicitParams({
        @ApiImplicitParam(name = "suggestion", value = "New suggestion", required = true, dataType = "NewSuggestion", paramType = "body")
    })

When I run my Play Server and open the swagger-ui, I get this error:

[error] application - Failed to resolve 'NewSuggestion' into class
java.lang.ClassNotFoundException: NewSuggestion
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at play.modules.swagger.PlayReader.typeFromString(PlayReader.java:411)
        at play.modules.swagger.PlayReader.readImplicitParam(PlayReader.java:387)
        at play.modules.swagger.PlayReader.readImplicitParameters(PlayReader.java:360)
        at play.modules.swagger.PlayReader.read(PlayReader.java:198)
        at play.modules.swagger.PlayReader.read(PlayReader.java:63)
        at play.modules.swagger.PlayReader.read(PlayReader.java:57)
        at play.modules.swagger.ApiListingCache$$anonfun$listing$1.apply(ApiListingCache.scala:17)

On my Controller, I have the following import, so the class is known:

import models.NewSuggestion;

To fix it, I need to add the package in front of the dataType, which is not wanted since the import are already there and they are always in the "models" folder. Also, I'm trying to do the play framework codegen and it's very difficult to know if a dataType is a model or a primitive type, so I can't program to add "models." or not before the dataType.

To fix it, here is the notation, it should not be needed:

@ApiImplicitParams({
        @ApiImplicitParam(name = "suggestion", value = "New suggestion", required = true, dataType = "models.NewSuggestion", paramType = "body")
    })

I don't know how to fix it but I think that the @ApiImplicitParams should use the same import as the page it is on.

Thanks

duo-xu-canal commented 7 years ago

You can try to use "models.NewSuggestion" instead of "NewSuggestion"