adobe / adobe/jsonschema2md

$id in properties - TypeError: Cannot convert object to primitive value

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

Description

## What did you do

I got the following error:

```
UnhandledPromiseRejectionWarning: TypeError: Cannot convert object to primitive value
at Object.get (XXX/node_modules/@adobe/jsonschema2md/lib/schemaProxy.js:140:50)
```

## What did you expect to happen

I was expecting that it would not happen when generation markdown.

## What happened

Similar to: https://github.com/adobe/jsonschema2md/issues/198

This is totally due to my schema having `$id` (and maybe other JSON schema kewords) as properties of an object.
This JSON schema is intended to validate another JSON schema (a subset of) so i need to use those keywords.

## What's your environment

* Operating System: MacOS Catalina
* node.js version: 13.5.0

## Do you have example files:

For this schema
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "...REMOVED...",
"title": "Country configuration",
"description": "An object with country-specific configuration",
"type": "object",
"required": ["schemas"],
"additionalProperties": false,
"properties": {
"schemas": {
"type": "array",
"items": [
{
"allOf": [
{ "$ref": "#/definitions/Schema" },
{
"properties": {
"entityName": { "const": "Model" }
}
}
]
}
],
"additionalItems": false
}
},
"definitions": {
"Schema": {
"$id": "#/definitions/Schema",
"type": "object",
"required": ["$schema", "$id", "entityName", "type", "required", "properties"],
"additionalProperties": false,
"properties": {
"$schema": { "const": "http://json-schema.org/draft-07/schema#" },
"$id": { "type": "string", "pattern": "...REMOVED..." },
"entityName": { "type": "string" },
"title": { "type": "string" },
"description": { "type": "string" },
"type": { "const": "object" },
"required": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
"properties": {
"type": "object",
"additionalProperties": {
"oneOf": [
{ "$ref": "#/definitions/StringField" },
{ "$ref": "#/definitions/IntegerField" }
]
}
}
}
},
"BaseField": {
"$id": "#/definitions/BaseField",
"type": "object",
"required": ["$id", "type", "title", "translationKey"],
"properties": {
"$id": { "type": "string", "pattern": "^#\\/properties(\\/[A-Za-z0-9_\\-.])+" },
"type": { "type": "string" },
"readOnly": { "type": "boolean", "default": false },
"title": { "type": "string" },
"translationKey": { "type": "string", "pattern": "^[a-zA-Z0-9_\\-.]+$" }
}
},
"StringField": {
"$id": "#/definitions/StringField",
"allOf": [
{
"$ref": "#/definitions/BaseField"
}
],
"additionalProperties": false,
"properties": {
"$id": {},
"readOnly": {},
"title": {},
"translationKey": {},
"type": { "const": "string" },
"enum": { "type": "array", "items": { "type": "string" } },
"pattern": { "type": "string" },
"minLength": { "type": "integer" },
"maxLength": { "type": "integer" }
}
},
"IntegerField": {
"$id": "#/definitions/IntegerField",
"allOf": [
{
"$ref": "#/definitions/BaseField"
}
],
"additionalProperties": false,
"properties": {
"$id": {},
"readOnly": {},
"title": {},
"translationKey": {},
"type": { "const": "integer" },
"enum": { "type": "array", "items": { "type": "integer" } },
"minimum": { "type": "integer" },
"maximum": { "type": "integer" }
}
}
}
}

```

Note: This is my first try at this package, and I won't be using it then. But i just prefer file this issue for the record.

Contributor guide

Open the contributing guide

Research direction

The failure is reported at node_modules/@adobe/jsonschema2md/lib/schemaProxy.js:140; start by reproducing Markdown generation with the provided schema and inspect that access path. Done means the package generates Markdown without a TypeError when schema properties include $id.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.