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

Property name "default" causes exception in this schema #253

Open
savasp opened this issue Oct 9, 2020 · 0 comments
Open

Property name "default" causes exception in this schema #253

savasp opened this issue Oct 9, 2020 · 0 comments
Labels

Comments

@savasp
Copy link

savasp commented Oct 9, 2020

I tried to simplify the schema. There is probably a simpler version of the following schema to illustrate the problem.

The following schema is valid. It declares a property named default somewhere in the structure...

{
    "$id": "https://example.org/foo",
    "$schema": "http://json-schema.org/draft-07/schema#",

    "type": "object",
    "additionalProperties": false,
    "required": [
        "bar"
    ],

    "properties": {
        "bar": { 
            "type": "string"
        },

        "arguments": {
            "type": "array",
            "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                    "name"
                ],
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "default": {
                        "$ref": "#/definitions/some-definition"
                    }
                }
            }
        }
    },

    "definitions": {
        "some-definition": {
            "$id": "https://example.org/some-definition",
            "items": {
                "oneOf": [
                    { "type": "string" },
                    { "$ref": "https://example.org/some-definition" }
                ]
            }
        }
    }
}

jsonschema2md throws the following exception:

loading 1 schemas
writing README
building readme
writing documentation
generating markdown
(node:89980) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'oneOf' -> object with constructor 'Object'
    |     index 1 -> object with constructor 'Object'
    --- property 'items' closes the circle
    at JSON.stringify (<anonymous>)
    at makedefault (/usr/local/lib/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:700:37)
    at /usr/local/lib/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:870:10
    at /usr/local/lib/node_modules/@adobe/jsonschema2md/node_modules/ferrum/src/sequence.js:1014:12
    at /usr/local/lib/node_modules/@adobe/jsonschema2md/node_modules/ferrum/src/sequence.js:604:5
    at each [CURRY] (/usr/local/lib/node_modules/@adobe/jsonschema2md/node_modules/ferrum/src/functional.js:175:12)
    at /usr/local/lib/node_modules/@adobe/jsonschema2md/node_modules/ferrum/src/sequence.js:1013:3
    at foldl [CURRY] (/usr/local/lib/node_modules/@adobe/jsonschema2md/node_modules/ferrum/src/functional.js:175:12)
    at /usr/local/lib/node_modules/@adobe/jsonschema2md/lib/markdownBuilder.js:862:21
    at /usr/local/lib/node_modules/@adobe/jsonschema2md/node_modules/ferrum/src/functional.js:88:53
(Use `node --trace-warnings ...` to show where the warning was created)
(node:89980) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:89980) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

If I rename the default property to something else, it works fine. For example, rename it to default-foo.

{
    "$id": "https://example.org/foo",
    "$schema": "http://json-schema.org/draft-07/schema#",

    "type": "object",
    "additionalProperties": false,
    "required": [
        "bar"
    ],

    "properties": {
        "bar": { 
            "type": "string"
        },

        "arguments": {
            "type": "array",
            "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                    "name"
                ],
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "default-foo": {
                        "$ref": "#/definitions/some-definition"
                    }
                }
            }
        }
    },

    "definitions": {
        "some-definition": {
            "$id": "https://example.org/some-definition",
            "items": {
                "oneOf": [
                    { "type": "string" },
                    { "$ref": "https://example.org/some-definition" }
                ]
            }
        }
    }
}

I use the following command...

> jsonschema2md -d schemas -o docs -e json -x -
@trieloff trieloff added the bug label Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants