Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0-SNAPSHOT: Strange behaviour after added @ApiModelProperty to enum attribute #667

Closed
jfiala opened this issue Apr 11, 2015 · 10 comments
Labels
Milestone

Comments

@jfiala
Copy link
Contributor

jfiala commented Apr 11, 2015

2.0.0-SNAPSHOT: springfox-core-2.0.0-20150411.131124-78

With:

@ApiModel(value="User", description="User object")
public class User {
....
private State state;
public enum State {
    ACTIVE, DISABLED;
}

the behaviour is correct:
"state":{"type":"string","enum":["ACTIVE","DISABLED"]}

But when I add the @ApiModelProperty annotation:

@ApiModel(value="User", description="User object")
public class User {
....
@ApiModelProperty(value = "Current state")
    private State state;

the following api-docs are generated:
"state":{"type":"string","description":"Current state"}

full api-docs:

{"swagger":"2.0","info":{"description":"Demo Swagger Spring 2 API Description","version":"1.0","title":"My Apps API Title","termsOfService":"My Apps API terms of service","contact":{"name":"My Apps API Contact Email"},"license":{"name":"My Apps API Licence Type","url":"My Apps API License URL"}},"host":"localhost:8080","basePath":"/","tags":[{"name":"search-services"},{"name":"basic-error-controller"},{"name":"user-crud-responseentity"},{"name":"user-crud"}],"paths":{"/error":{"get":{"tags":["basic-error-controller"],"summary":"errorHtml","description":"errorHtml","operationId":"errorHtmlUsingGET","consumes":["application/json"],"produces":["text/html"],"responses":{"404":{"description":"Not Found"},"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}}},"post":{"tags":["basic-error-controller"],"summary":"errorHtml","description":"errorHtml","operationId":"errorHtmlUsingPOST","consumes":["application/json"],"produces":["text/html"],"responses":{"404":{"description":"Not Found"},"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}}},"put":{"tags":["basic-error-controller"],"summary":"errorHtml","description":"errorHtml","operationId":"errorHtmlUsingPUT","consumes":["application/json"],"produces":["text/html"],"responses":{"404":{"description":"Not Found"},"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}}},"delete":{"tags":["basic-error-controller"],"summary":"errorHtml","description":"errorHtml","operationId":"errorHtmlUsingDELETE","consumes":["application/json"],"produces":["text/html"],"responses":{"204":{"description":"No Content"},"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}}},"options":{"tags":["basic-error-controller"],"summary":"errorHtml","description":"errorHtml","operationId":"errorHtmlUsingOPTIONS","consumes":["application/json"],"produces":["text/html"],"responses":{"204":{"description":"No Content"},"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}}},"patch":{"tags":["basic-error-controller"],"summary":"errorHtml","description":"errorHtml","operationId":"errorHtmlUsingPATCH","consumes":["application/json"],"produces":["text/html"],"responses":{"204":{"description":"No Content"},"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}}}},"/search":{"get":{"tags":["search-services"],"summary":"search for users by name-part","description":"search for users","operationId":"searchUsersUsingGET","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"query","in":"query","description":"query","required":true,"type":"string"}],"responses":{"404":{"description":"Not Found"},"200":{"description":"OK","schema":{"type":"array","items":{"$ref":"#/definitions/User"}}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}}}},"/user":{"get":{"tags":["user-crud"],"summary":"read User by ID","description":"pass ID to read user","operationId":"getUserUsingGET","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"id","in":"query","description":"id","required":true,"type":"integer","format":"int64"}],"responses":{"404":{"description":"Not Found"},"200":{"description":"OK","schema":{"$ref":"#/definitions/User"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}}},"post":{"tags":["user-crud"],"summary":"create or update a user name by id","description":"saveUser","operationId":"saveUserUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"id","in":"query","description":"id","required":true,"type":"integer","format":"int64"},{"name":"name","in":"query","description":"name","required":true,"type":"string"}],"responses":{"404":{"description":"Not Found"},"200":{"description":"OK","schema":{"$ref":"#/definitions/User"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}}}},"/user_with_responseentity":{"get":{"tags":["user-crud-responseentity"],"summary":"getUserResponseEntity","description":"getUserResponseEntity","operationId":"getUserResponseEntityUsingGET","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"id","in":"query","description":"id","required":true,"type":"integer","format":"int64"}],"responses":{"404":{"description":"Not Found"},"200":{"description":"OK","schema":{"type":"object"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"500":{"description":"Unexpected Error"}}}}},"definitions":{"User":{"required":["id","name"],"properties":{"categories":{"type":"array","items":{"$ref":"#/definitions/Category"}},"id":{"type":"integer","format":"int64","description":"ID of the user"},"locationMap":{"type":"object","additionalProperties":{"$ref":"#/definitions/Location"}},"locations":{"type":"array","items":{"$ref":"#/definitions/Location"}},"name":{"type":"string","description":"Name of the user"},"photo":{"type":"array","items":{"type":"string","format":"byte"}},"state":{"type":"string","description":"Current state"}},"description":"User object"},"View":{"properties":{"contentType":{"type":"string"}}},"Category":{"properties":{"id":{"type":"integer","format":"int64"},"name":{"type":"string"}}},"ModelAndView":{"properties":{"empty":{"type":"boolean"},"model":{"type":"object"},"modelMap":{"type":"object","additionalProperties":{"type":"object"}},"reference":{"type":"boolean"},"view":{"$ref":"#/definitions/View"},"viewName":{"type":"string"}}},"Location":{"properties":{"city":{"type":"string"},"country":{"type":"string"},"latitude":{"type":"number","format":"double"},"longitude":{"type":"number","format":"double"},"street":{"type":"string"},"zip":{"type":"string"}}}}}

demo:
https://github.com/jfiala/swagger-spring-demo/tree/master/user-rest-service-2.0.0

jfiala added a commit to jfiala/swagger-spring-demo that referenced this issue Apr 11, 2015
jfiala added a commit to jfiala/swagger-spring-demo that referenced this issue Apr 11, 2015
@dilipkrish dilipkrish added this to the 2.0 milestone Apr 11, 2015
@dilipkrish dilipkrish added the bug label Apr 11, 2015
@dilipkrish
Copy link
Member

@jfiala thanks for reporting! 👍

@jfiala
Copy link
Contributor Author

jfiala commented Apr 11, 2015

I just wanted to verify this, but after updating to the latest and starting spring:boot I get:

java.lang.NullPointerException: null key in entry: null=springfox.documentation.spring.web.plugins.Docket@5ef9ca83
    at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:31)
    at com.google.common.collect.ImmutableMultimap$Builder.put(ImmutableMultimap.java:169)
    at com.google.common.collect.ImmutableListMultimap$Builder.put(ImmutableListMultimap.java:167)
    at com.google.common.collect.Multimaps.index(Multimaps.java:1509)
    at com.google.common.collect.Multimaps.index(Multimaps.java:1455)
    at springfox.documentation.spring.web.plugins.DuplicateGroupsDetector.ensureNoDuplicateGroups(DuplicateGroupsDetector.java:41)

Can you please inspect this?

Can be immediately reproduced using:
https://github.com/jfiala/swagger-spring-demo/tree/master/user-rest-service-2.0.0

@dilipkrish
Copy link
Member

@jfiala Cannot reproduced this. This is my environment

Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T15:10:27-05:00)
Maven home: /usr/local/Cellar/maven/3.3.1/libexec
Java version: 1.7.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: US-ASCII
OS name: "mac os x", version: "10.10.3", arch: "x86_64", family: "mac"

@jfiala
Copy link
Contributor Author

jfiala commented Apr 12, 2015

entered commands:
git clone https://github.com/jfiala/swagger-spring-demo
cd swagger-spring-demo
cd user-rest-service-2.0.0
mvn spring-boot:run
==>
Exception in thread "main" java.lang.NullPointerException: null key in entry: null=springfox.documentation.spring.web.plugins.Docket@39810970

It fails in my Windows environment:
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: c:\progs\apache-maven-3.0.5\bin..
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_25\jre
Default locale: de_AT, platform encoding: Cp1252
OS name: "windows 8", version: "6.2", arch: "amd64", family: "windows"

It also fails in my Ubuntu environment:
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "2.6.32-042stab094.8", arch: "amd64", family: "unix"

I don't think it has to do with the Maven/Java version.
If you really do, I can upgrade Maven and Java.
This has been working a few hours ago, so it must be caused by one of the last commits.

@adrianbk
Copy link
Member

@jfiala will take a look now - doubt its maven or java version.

@adrianbk
Copy link
Member

Yep, it was recently introduced - I will fix it. springfox.documentation.spring.web.plugins.DuplicateGroupsDetector.ensureNoDuplicateGroups(DuplicateGroupsDetector.java:41)

@adrianbk
Copy link
Member

Should be fixed here: 8f01d4f

jfiala added a commit to jfiala/swagger-spring-demo that referenced this issue Apr 12, 2015
@jfiala
Copy link
Contributor Author

jfiala commented Apr 12, 2015

2.0.0-SNAPSHOT:
For Swagger 1.2: perfect, working again!
For Swagger 2.0 (@EnableSwagger2 + DocumentationType.SWAGGER_2): exception during startup:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [springfox.documentation.swagger.mappers.ServiceModelToSwaggerMapper]

Exception can be reproduced using:
jfiala/swagger-spring-demo@53acc8f

@adrianbk
Copy link
Member

It's an issue with component scanning plus the springfox-swagger and springfox-swagger-common modules have the same package namespace.

@adrianbk
Copy link
Member

@jfiala @dilipkrish I'm going to rename one of the modules and it package name: springfox-swagger > springfox-swagger and it's namespace from springfox.documentation.swagger to springfox.documentation.swagger1

adrianbk added a commit that referenced this issue Apr 12, 2015
Renaming springfox-swagger module to springfox-swagger1
dilipkrish added a commit that referenced this issue Apr 12, 2015
configuration to match the convention in swagger 2.0

related to #667
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants