swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.39k stars 2.19k forks source link

Why does specifying OpenAPI 3.1.0 remove all "type" properties? #4296

Closed Yaytay closed 2 years ago

Yaytay commented 2 years ago

I'm working on a pretty basic REST API with quite a complex object model. The only differences between the output when: openAPI31(Boolean.TRUE) and openAPI31(Boolean.FALSE) are:

  1. All of the "type" properties have been removed from the Schema properties.
  2. The version number has changed.
  3. The jsonSchemaDialect is specified.

An example subset from OpenAPI 3.0.1:

  "components" : {
    "schemas" : {
      "Directory" : {
        "type" : "object",
        "properties" : {
          "path" : {
            "type" : "string"
          },
          "modified" : {
            "type" : "string",
            "format" : "date-time"
          },
          "name" : {
            "type" : "string"
          },
          "children" : {
            "type" : "array",
            "items" : {
              "$ref" : "#/components/schemas/Node"
            }
          }
        }
      },

and from 3.1.0:

  "components" : {
    "schemas" : {
      "Directory" : {
        "properties" : {
          "path" : { },
          "modified" : {
            "format" : "date-time"
          },
          "name" : { },
          "children" : {
            "items" : {
              "$ref" : "#/components/schemas/Node"
            }
          }
        }
      },

Is this something a bug in the OpenAPI library, or am I missing something on my side?

It's not just string "types" that are missing, they've all gone.

I have specified dependencies on swagger-jaxrs2-jakarta:2.2.6 and swagger-annotations-jakarta:2.2.6.

Thanks.

frantuma commented 2 years ago

from your outcome above I suspect that the spec gets serialized using the 3.0 Yaml class instead of the 3.1 Yaml31. Can you share some more details about your scenario (how are you integrating Swagger, how do you serialize the spec, etc)?

Please see also this comment for some details about 3.0 Schema type vs 3.1 types

Yaytay commented 2 years ago

Hmm, well now it's working and I don't know why :( I suspect I had invalid combinations of dependencies somewhere. I'm going to close this issue, but I'd be really grateful if you could give me the actual link to type vs types differences.

Yaytay commented 2 years ago

It's working for me now.

frantuma commented 2 years ago

Updated link to related comment

Yaytay commented 2 years ago

Thank you. I had to do more digging on this and it was entirely my fault. I have to initiate the rendering of the schema myself (because the documented endpoints are Resteasy but the OpenAPI endpoint is Vert.x) and I hadn't picked up on the need to use a different class for 3.1.0. Your first comment pointed me in the right direction.