softwaremill / tapir

Rapid development of self-documenting APIs
https://tapir.softwaremill.com
Apache License 2.0
1.35k stars 405 forks source link

schemaForCirceJson produces incorrect OpenAPI schema #420

Closed skennedy closed 4 years ago

skennedy commented 4 years ago

The schema defined for the io.circe.Json data type (https://github.com/softwaremill/tapir/blob/master/json/circe/src/main/scala/sttp/tapir/json/circe/TapirJsonCirce.scala#L25-L31), currently generates the following OpenAPI schema:

components:
  schemas:
    Json:
      type: object

This doesn't seem correct as io.circe.Json encodes any JSON value, including primitives, arrays, null, as well as objects.

I couldn't see a proper way of encoding the schema of "anything" in tapir. However, a hacky workaround I found was that an empty co-product...

  implicit val schemaForCirceJson: Schema[Json] =
    Schema(
      SCoproduct(
        SObjectInfo("io.circe.Json"),
        List.empty,
        None
      )
    )

...currently results in the empty schema...

components:
  schemas:
    Json: {}

...which seems to be the Json schema / OpenAPI to encode this.

skennedy commented 4 years ago

Happy to submit a PR of the above if it's deemed acceptable :wink:

adamw commented 4 years ago

Please do! It makes sense: the Json type is a coproduct (as it has strings, arrays, objects, ...), with unknown implementations

Thanks!