softwaremill / sttp-apispec

OpenAPI, AsyncAPI and JSON Schema Scala models.
Apache License 2.0
23 stars 11 forks source link

Wrong null-type for optional ref-type in openapi 3.0.3 #130

Closed cornerman closed 9 months ago

cornerman commented 9 months ago

When updating to sttp-apispec 0.7.1, I think, I found a regression regarding nullability.

Having defined:

case class ConfirmationModalDescription(title: String)
case class PublishInput(confirmationModal: Option[ConfirmationModalDescription])

This results in the following openapi definitions:

sttp-apispec 0.3.2 (openapi: 3.0.3):

      "PublishInput" : {
        "properties" : {
          "confirmationModal" : {
            "$ref" : "#/components/schemas/ConfirmationModalDescription"
          }
        },
        "type" : "object"
      }

sttp-apispec 0.7.1 (openapi: 3.0.3):

      "PublishInput" : {
        "properties" : {
          "confirmationModal" : {
            "oneOf" : [
              {
                "$ref" : "#/components/schemas/ConfirmationModalDescription"
              },
              {
                "type" : "null"
              }
            ]
          }
        },
        "type" : "object"
      }

sttp-apispec 0.7.1 (openapi: 3.1.0):

      "PublishInput" : {
        "properties" : {
          "confirmationModal" : {
            "oneOf" : [
              {
                "$ref" : "#/components/schemas/ConfirmationModalDescription"
              },
              {
                "type" : "null"
              }
            ]
          }
        },
        "type" : "object"
      }

After updating, we get type: "null" in our openapi spec (version 3.0.3), which seems be invalid (see: https://swagger.io/docs/specification/data-models/data-types/). I think, it is only introduced in openapi version 3.1.0.

cornerman commented 9 months ago

Sorry, I mixed up something in my configuration. It actually works correct now.

cornerman commented 9 months ago

Sorry for the confusion, I have updated the description. It was the other way around. In sttp-apispec 0.7.1, we get type: "null", which is not valid in openapi 3.0.3 (according to https://swagger.io/docs/specification/data-models/data-types/).

cornerman commented 9 months ago

Now, I understand that this is actually coming from tapir. I opened a PR there: https://github.com/softwaremill/tapir/pull/3331