SMILEY4/schema-kenerator

Swagger `@Schema` annotation is ignored

Closed this issue · 3 comments

Reproducer

import io.swagger.v3.oas.annotations.media.Schema
import io.github.smiley4.schemakenerator.core.annotations.Default

enum class OrderBy {
    ASC,
    DESC
}

data class Query(
    val limit: Int,
    @Schema(defaultValue = "asc")
    val order: OrderBy = OrderBy.ASC
)

data class AnotherQuery(
    val limit: Int,
    @Default("asc")
    val order: OrderBy = OrderBy.ASC
)

Some more info:

  • This is using the kotlinx-generator (have not tested with reflection)
  • @Default did not work for me due to #34. Other core annotations are working as expected
  • @Schema is the only annotation I am having issues with (seems like none of the properties are being forwarded)
  generator = { type ->
      type
          .processKotlinxSerialization()
          .connectSubTypes()
          .handleNameAnnotation()
          .addDiscriminatorProperty()
          .generateSwaggerSchema { optionalHandling = OptionalHandling.NON_REQUIRED }
          .withTitle(TitleType.OPENAPI_SIMPLE)
          .handleCoreAnnotations()
          .handleSwaggerAnnotations()
          .handleSchemaAnnotations()
          .compileReferencingRoot(RefType.OPENAPI_SIMPLE)
  }

I think this is related to #17.
Kotlinx-serialization drops annotations that are not annotated with @SerialInfo (which @Schema isnt). So unfortunately (afaik) there is no way to get the information when using "processKotlinxSerialization".

Ahh, I see. That makes sense.

I'm going to take this conversation over to #17