swagger-akka-http / swagger-scala-module

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

Reflection issue since the version 2.7.3 #192

Closed VincentBrule closed 2 years ago

VincentBrule commented 2 years ago

Hello, Since the version 2.7.3, I'm getting this error: java.lang.NoClassDefFoundError: no Java class corresponding to T found I tried to create an example as minimal as possible to reproduce the error:

final case class DataExampleClass(
    data: CustomCollection[ExampleProperties]
)

final case class CustomCollection[T](
    features: Seq[FeatureExample[T]]
)

final case class FeatureExample[T](
    geometry: Option[T]
)

final case class ExampleProperties(
    p1: Int,
    p2: Double
)

And:

@Path(Example)
trait ExampleRoutesSwagger {

  @Path(Paths.Slash)
  @GET
  @Operation(
    summary = "",
    responses = Array(
      new ApiResponse(
        responseCode = "200",
        description  = "",
        content = Array(
          new Content(
            mediaType = MediaType.APPLICATION_JSON,
            array = new ArraySchema(
              schema = new Schema(
                implementation = classOf[DataExampleClass],
                required       = true
              )
            )
          )
        )
      ),
    )
  )
  def getAll: Route
}

With this, you can easily reproduce the bug normally.

Do you have an idea what can be the issue? I also tried with the latest code of develop.

pjfanning commented 2 years ago

I'm not sure how easy this is going to be to get working.

You could rewrite your classes - something like:

final case class DataExampleClass(
    data: CustomCollectionExampleProperties
)

final case class CustomCollectionExampleProperties(
    features: Seq[FeatureExampleProperties]
)

final case class FeatureExampleProperties(
    geometry: Option[ExampleProperties]
)
pjfanning commented 2 years ago

I have a PR that fixes the issue. Could you stick with swagger-scala-module v2.7.2? I don't plan to do a new release for a few weeks - until after Jackson v2.14.0 comes out.

VincentBrule commented 2 years ago

Yes sure no problem, I will stick with v2.7.2 until the new version is released. Thanks for your help and your quick answer @pjfanning 🙏

pjfanning commented 2 years ago

I released v2.7.5 with this fix, the scala 3 support has some extra experimental changes but the scala 2 builds should be safe to use.

pjfanning commented 2 years ago

@SamTheisens the v2.7.5 releases has some fixes, would you be able to try it out?

VincentBrule commented 2 years ago

Sorry for the delay @pjfanning, this specific issue is gone with the latest release, thanks.

SamTheisens commented 1 year ago

@SamTheisens the v2.7.5 releases has some fixes, would you be able to try it out?

Sorry, haven't tried this out yet. Will get back to you if I encounter any issues

SamTheisens commented 1 year ago

@pjfanning I found one issue. Here's a fix: https://github.com/swagger-akka-http/swagger-scala-module/pull/206