Finatra validation annotations (e.g. com.twitter.finatra.validation.constraint.Size) cause runtime error in swagger doc generation
mog1919 opened this issue · 1 comments
mog1919 commented
if I have a case class defined as follows,
case class MyRequest(id: String, @com.twitter.finatra.validation.constraint.Size(min=1, max=1024) value: String)
and use this class as a request type in my swagger doc:
postWithDoc("/foobar") { o =>
o.summary("example")
.request[MyRequest]
it will throw an exception at runtime from the bytebuddy
code due to the fact that the @Size
annotation does not have FIELD type as a target, and finatra-swagger is attempting to add it as a public field with this annotation:
Cause: java.lang.IllegalStateException: Cannot add @com.twitter.finatra.validation.constraints.Size(min=1, max=1024) on public java.lang.String swagger.MyRequest.value
at net.bytebuddy.dynamic.scaffold.InstrumentedType$Default.validated(InstrumentedType.java:1484)
at net.bytebuddy.dynamic.scaffold.MethodRegistry$Default.prepare(MethodRegistry.java:519)
at net.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:213)
at net.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:204)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:3595)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase$Delegator.make(DynamicType.java:3819)
at com.jakehschwartz.finatra.swagger.FinatraSwagger.getSwaggerBodyProp(FinatraSwagger.scala:155)
at com.jakehschwartz.finatra.swagger.FinatraSwagger.register(FinatraSwagger.scala:116)
at com.jakehschwartz.finatra.swagger.FinatraOperation.request(FinatraOperation.scala:32)
jakehschwartz commented
@mog1919 Thanks for finding this. I'll have time to look at this next week, but would of course accept a PR if you find a fix sooner!!