Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Schema - Definitions #29

Open
jasonterando opened this issue Dec 15, 2020 · 2 comments
Open

JSON Schema - Definitions #29

jasonterando opened this issue Dec 15, 2020 · 2 comments

Comments

@jasonterando
Copy link

Hi, does this routine support the definitions keyword as described in the JSON Schema documentation? Using json-schema-to-openapi-schema, converting a JSON Schema with a "definitions" property does not seem to handle nullable types properly (sending the individual interfaces to json-schema-to-openapi-schema works. Note that I am not using #refs.

Here is an example:

JSON Schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "Product": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "price": {
          "type": "number"
        },
        "rating": {
          "type": [
            "null",
            "number"
          ]
        }
      },
      "required": [
        "name",
        "price",
        "rating"
      ]
    },
    "ProductList": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "version": {
          "type": "string"
        },
        "products": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "price": {
                "type": "number"
              },
              "rating": {
                "type": [
                  "null",
                  "number"
                ]
              }
            },
            "required": [
              "name",
              "price",
              "rating"
            ]
          }
        }
      },
      "required": [
        "name",
        "products",
        "version"
      ]
    }
  }
}

Results in OpenAPI JSON (note "null" types):

{
   "Product": {
      "type": "object",
      "properties": {
         "name": {
            "type": "string"
         },
         "price": {
            "type": "number"
         },
         "rating": {
            "type": [
               "null",
               "number"
            ]
         }
      },
      "required": [
         "name",
         "price",
         "rating"
      ]
   },
   "ProductList": {
      "type": "object",
      "properties": {
         "name": {
            "type": "string"
         },
         "version": {
            "type": "string"
         },
         "products": {
            "type": "array",
            "items": {
               "type": "object",
               "properties": {
                  "name": {
                     "type": "string"
                  },
                  "price": {
                     "type": "number"
                  },
                  "rating": {
                     "type": [
                        "null",
                        "number"
                     ]
                  }
               },
               "required": [
                  "name",
                  "price",
                  "rating"
               ]
            }
         }
      },
      "required": [
         "name",
         "products",
         "version"
      ]
   }
}

I was hoping to see something like this:

{
   "Product": {
      "type": "object",
      "properties": {
         "name": {
            "type": "string"
         },
         "price": {
            "type": "number"
         },
         "rating": {
            "type": "number",
            "nullable": true
         }
      },
      "required": [
         "name",
         "price",
         "rating"
      ]
   },
   "ProductList": {
      "type": "object",
      "properties": {
         "name": {
            "type": "string"
         },
         "version": {
            "type": "string"
         },
         "products": {
            "type": "array",
            "items": {
               "type": "object",
               "properties": {
                  "name": {
                     "type": "string"
                  },
                  "price": {
                     "type": "number"
                  },
                  "rating": {
                     "type": "number",
                     "nullable": true
                  }
               },
               "required": [
                  "name",
                  "price",
                  "rating"
               ]
            }
         }
      },
      "required": [
         "name",
         "products",
         "version"
      ]
   }
}
@omkarnix
Copy link

Facing same issue, Please can someone update on if definitions keyword supported? @mikunn @philsturgeon

@philsturgeon
Copy link
Contributor

This version hasn't been supported in years, and the new version is not being actively developed as OpenAPI v3.1 is now proper JSON Schema. Yaaaaay.

Anyhow, let's keep the discussion going over here, maybe you could help with a PR? openapi-contrib#25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants