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

Cannot convert type null with $ref #26

Open
janjagusch opened this issue Mar 27, 2020 · 0 comments
Open

Cannot convert type null with $ref #26

janjagusch opened this issue Mar 27, 2020 · 0 comments

Comments

@janjagusch
Copy link

janjagusch commented Mar 27, 2020

I am trying to convert a json schema that should either be null or a $ref to another object. In this case the reference is just a simple string but this could be arbitrarily complicated.

The design of the json schema follows the advice given here:

Input

{
    "anyOf": [
        {
            "$ref": "#/my_object"
        },
        {
            "type": "null"
        }
    ],
    "my_object": {
        "type": "string"
    }
}

I expected the output to be somewhat similar to this:

Expected Output

{
  "nullable": true,
  "$ref": "#/my_object",
  "my_object": {
    "type": "string"
  }
}

However, it actually caused the package to crash:

Error

Error
    at Object.<anonymous> ([...]/json-schema-to-openapi-schema/index.js:8:30)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> ([...]/json-schema-to-openapi/index.js:3:19)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10) {
  name: 'InvalidTypeError',
  message: 'Type "null" is not a valid type'
}

I believe this issue is similar to #21. However, in that case you could easily adjust the json schema using the "type": [] syntax. Here it is different. I guess the only alternative would be to make all referenced objects nullable, which I would like to avoid.

I believe this would be a great addition for converting rather complicated schemata. :)

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

1 participant