jsonschema2md icon indicating copy to clipboard operation
jsonschema2md copied to clipboard

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

Open ArTiSTiX opened this issue 5 years ago • 4 comments

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

{
  "$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.

ArTiSTiX avatar Jan 29 '20 14:01 ArTiSTiX

Thanks for the bug report and the example file, @ArTiSTiX that will make it easier to fix this.

trieloff avatar Jan 29 '20 17:01 trieloff

I recently ran into the same issue, but using the property name of "maximum"

It threw an error here: https://github.com/adobe/jsonschema2md/blob/master/lib/markdownBuilder.js#L562

ThomasDotCodes avatar Mar 04 '20 16:03 ThomasDotCodes

Similar issue with a property named "pattern":

{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "http://example.com/schemas/some",
    "type": "object",
    "title": "Field validation",
    "description": "Field validation definition.",
    "default": {},
    "examples": [
        {
            "isRequired": true,
            "maxLength": 128,
            "pattern": "^CP[0-9]{9}$"
        }
    ],
    "required": [
        "isRequired"
    ],
    "properties": {
        "isRequired": {
            "$id": "#/properties/isRequired",
            "type": "boolean",
            "title": "Required",
            "description": "Set to true if the field is mandatory.",
            "default": false,
            "examples": [
                true
            ]
        },
        "maxLength": {
            "$id": "#/properties/maxLength",
            "type": "integer",
            "title": "Maximum length",
            "description": "The maximum length of a string field.",
            "examples": [
                128
            ]
        },
        "pattern": {
            "$id": "#/properties/pattern",
            "type": [ "string", "null" ],
            "format": "regex",
            "title": "Pattern",
            "description": "A regex for validation of a string field.",
            "default": null,
            "examples": [
                "^CP[0-9]{9}$"
            ]
        }
    },
    "additionalProperties": false
}

throws the error at https://github.com/adobe/jsonschema2md/blob/master/lib/markdownBuilder.js#L611

jbouduin avatar Nov 26 '20 19:11 jbouduin

I'm just starting to checkout this library and running into this issue still. Last update was 2.5 years ago. Wondering if a fix for this is on the roadmap.

jedijashwa avatar Jun 17 '23 16:06 jedijashwa