adobe / adobe/jsonschema2md

Property name "default" causes exception in this schema

Open
#253 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
724
Forks
150
Avg merge
18h 22m
Merged PRs (30d)
4

Description

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...

```json
{
"$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 ()
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 -
```

Contributor guide

Open the contributing guide

Research direction

Start with lib/markdownBuilder.js at makedefault (line 700) and reproduce the failure using the supplied schema and jsonschema2md command. Done means a schema containing a property named default completes documentation generation without the circular-structure exception, while the renamed-property comparison remains successful.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.