adobe / jsonschema2md

Convert Complex JSON Schemas into Markdown Documentation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Property name "default" causes exception in this schema

savasp opened this issue · comments

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 -