swagger-akka-http / swagger-scala-module

Swagger support for scala
Apache License 2.0
10 stars 10 forks source link

Swagger Generation Confused when Case Class method name starts with get #189

Closed tomasphelan closed 1 year ago

tomasphelan commented 2 years ago

When including a function name prefixed with get to a case class, for example, getOptionalAmount swagger will generate as a required field OptionalAmount

We believe it might be due to due to the fact that it uses a (Java) bean introspector to inspect the case classes.

https://github.com/swagger-akka-http/swagger-scala-module/blob/1d764e5b5a191199a84df4990aa7fdb4a061a385/src/main/scala/com/github/swagger/scala/converter/SwaggerScalaModelConverter.scala#L117

pjfanning commented 2 years ago

I have reproduced this issue. See https://github.com/swagger-akka-http/swagger-scala-module/commit/abbecc32fe6ad2a7b9c4c64c0889d2f1502b4548

com.fasterxml.jackson.module.scala.introspect.BeanIntrospector ignores the getOptionalAmount - the fact that optionalAmount is added as swagger model property is not this - and I haven't yet found what that is - note the package name on com.fasterxml.jackson.module.scala.introspect.BeanIntrospector - this not a Java class

I have limited time to spend on this over the next few days. I suggest you rename your function. Or you can put a JsonIgnore annotation on the getOptionalAmount function. There are other swagger and jackson annotations you could use too. If you do find a solution, could you add a comment here so other users can benefit from the knowledge.

I'll come back to this at some point in the future to see if the behaviour can be improved.

pjfanning commented 2 years ago

@tomasphelan the main branch latest code should handle this better now. It will probably be a few weeks before I release a new jar though - other stuff I want to get in before that release.

tomasphelan commented 2 years ago

Awesome work @pjfanning !

pjfanning commented 2 years ago

v2.7.5 is out

pjfanning commented 1 year ago

Using swagger-scala-module with swagger-core v2.2.5 and above breaks the hack I put in swagger-scala-module. This issue needs more investigation.

pjfanning commented 1 year ago

https://github.com/swagger-akka-http/swagger-scala-module/pull/220 (will be part of v2.8.1 release) appears to fix latest issue