springfox-grails-integration
springfox-grails-integration copied to clipboard
Unknown type: null.
Here is my log:
2019-03-19 19:04:50.013 INFO pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [public org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)]
2019-03-19 19:04:56.821 INFO d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2019-03-19 19:04:56.925 INFO d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2019-03-19 19:04:57.146 WARN o.grails.core.DefaultGrailsDomainClass : The GrailsDomainClass API should no longer be used to retrieve data about domain classes. Use the mapping context API instead
2019-03-19 19:04:59.889 WARN o.grails.core.DefaultGrailsDomainClass : The GrailsDomainClass API should no longer be used to retrieve data about domain classes. Use the mapping context API instead
2019-03-19 19:04:59.906 WARN o.grails.core.DefaultGrailsDomainClass : The GrailsDomainClass API should no longer be used to retrieve data about domain classes. Use the mapping context API instead
2019-03-19 19:04:59.946 WARN o.grails.core.DefaultGrailsDomainClass : The GrailsDomainClass API should no longer be used to retrieve data about domain classes. Use the mapping context API instead
2019-03-19 19:04:59.983 ERROR o.s.boot.SpringApplication : Application startup failed
java.lang.IllegalArgumentException: Unknown type: null
at net.bytebuddy.description.type.TypeDefinition$Sort.describe(TypeDefinition.java:213)
at net.bytebuddy.description.type.TypeDefinition$Sort.describe(TypeDefinition.java:190)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.defineField(DynamicType.java:2487)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.defineField(DynamicType.java:2482)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.defineField(DynamicType.java:2477)
at springfox.documentation.builders.AlternateTypePropertyBuilder.apply(AlternateTypePropertyBuilder.java:69)
at springfox.documentation.builders.AlternateTypeBuilder.build(AlternateTypeBuilder.java:64)
at springfox.documentation.grails.GrailsSerializationTypeGenerator.from(GrailsSerializationTypeGenerator.java:39)
at springfox.documentation.grails.DefaultGrailsAlternateTypeRuleConvention.lambda$rules$0(DefaultGrailsAlternateTypeRuleConvention.java:42)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at springfox.documentation.grails.DefaultGrailsAlternateTypeRuleConvention.rules(DefaultGrailsAlternateTypeRuleConvention.java:43)
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper$1.apply(DocumentationPluginsBootstrapper.java:125)
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper$1.apply(DocumentationPluginsBootstrapper.java:122)
Here is my Grails application project: https://github.com/dteam-top/grails-rest-seed
And I find the reason is that some fields cannot use property.getReferencedPropertyType();(Here will get null: https://github.com/springfox/springfox-grails-integration/blob/88052cbe0c4869b34f8544ef992ea54ea8bcba24/springfox-grails/src/main/java/springfox/documentation/grails/DefaultGrailsPropertyTransformer.java#L9)
Here will trigger this error: https://github.com/DTeam-Top/grails-rest-seed/blob/1a5eeee346dd14b81fa54b2ba9a25d9a3156e169/grails-app/domain/top/dteam/earth/backend/user/User.groovy#L24
And this line: https://github.com/DTeam-Top/grails-rest-seed/blob/1a5eeee346dd14b81fa54b2ba9a25d9a3156e169/grails-app/domain/top/dteam/earth/backend/user/User.groovy#L54
I comment out these lines and works very well.
One is
Set<Role> getAuthorities() {
(UserRole.findAllByUser(this) as List<UserRole>)*.role as Set<Role>
}
Another is
static transients = ['accountExpired', 'accountLocked']
Hi. The only way I could work around this issue was to declare a new GrailsPropertySelector bean in the Application class inside the init directory. This way you can ignore properties which are causing problems. I know this is not a real solution, just a workaround. But this way you can get the application running, at least.
This is how my bean declaration looks like:
@Bean
GrailsPropertySelector propertySelector() {
return new DefaultGrailsPropertySelector() {
@Override
boolean test(GrailsDomainClassProperty each) {
boolean b = super.test(each) &&
!(each.referencedPropertyType == null && each.name == 'instituicaoId') &&
(each.isPersistent() || each.getName().endsWith("Id")) &&
!(Geometry.isAssignableFrom(each.type))
return b
}
}
}