swagger-akka-http / swagger-scala-module

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

Extraneous Schemas Generated for Models Containing Array Properties #195

Closed leedsalex closed 2 years ago

leedsalex commented 2 years ago

This might be related to #63

Note: We use this package directly, not as part of swagger-akka-http. We only generate schemas for models, and don't use any annotations.

Given a case class that contains a single property which is a Seq, there are two schemas generated, Foo and SeqString, i'm unsure why the SeqString schema is generated as it's not referenced in the Foo schema. This appears to be a bug.

    case class Foo(bar: Seq[String])
    val schema = ModelConverters.getInstance().readAll(classOf[Foo])
    val yaml = Yaml.pretty(schema)
    println(yaml)
Foo:
  required:
    - bar
  type: object
  properties:
    bar:
      type: array
      items:
        type: string
SeqString:
  type: array
  items:
    type: string
pjfanning commented 2 years ago

I'm afraid that swagger-scala-module is a set of hacks built on io.swagger.core.v3:swagger-core-jakarta.

ModelConverters.getInstance().readAll is not a method in this lib. It is a method in io.swagger.core.v3:swagger-core-jakarta.

It is io.swagger.core.v3:swagger-core-jakarta that decides to create a model for SeqString.

And I find the io.swagger team quite unresponsive when it comes to trying to get them to consider issues and PRs. So suggesting changes there is not something I'm interested in following up on.

One approach would be to create a method in this lib that wraps ModelConverters.getInstance().readAll and that can filter out excess models (or some angle like that).

If you want to try something yourself, I can review any changes. But because the extra model is just a minor annoyance as opposed to a major issue, I'm not super enthusiastic to spend much time on it myself.

leedsalex commented 2 years ago

Thanks for the quick response and pointing me in the right direction. I will see what type of solution I can come up with.

Thanks again for maintaining this library, it has been a huge help to my team!