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

A schema with a field called "description" throws "TypeError: comment.split is not a function" #540

Closed
timfarrar opened this issue Jul 20, 2023 · 1 comment

Comments

@timfarrar
Copy link

compiling this schema:

  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "definitions": {
    "Thing_1": {
      "type": "object",
      "properties": {
        "schema_version": {
          "type": "integer",
          "minimum": 0,
          "maximum": 18446744073709551615
        },
        "short_name": {
          "type": "string"
        },
        "long_name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      },
      "required": [
        "short_name"
      ],
      "additionalProperties": false
    }
  },
  "type": "object",
  "properties": {
    "$ref": "#/definitions/Thing_1"
  }
}

results in this error:

TypeError: comment.split is not a function
at generateComment (<path_redacted>/node_modules/json-schema-to-typescript/dist/src/generator.js:288:57)
at <path_redacted>/node_modules/json-schema-to-typescript/dist/src/generator.js:277:73
at Array.map ()
at generateInterface (<path_redacted>/node_modules/json-schema-to-typescript/dist/src/generator.js:275:14)
at generateStandaloneInterface (<path_redacted>/node_modules/json-schema-to-typescript/dist/src/generator.js:309:9)
at declareNamedInterfaces (<path_redacted>/node_modules/json-schema-to-typescript/dist/src/generator.js:71:21)
at generate (<path_redacted>/node_modules/json-schema-to-typescript/dist/src/generator.js:22:9)
at <path_redacted>/node_modules/json-schema-to-typescript/dist/src/index.js:161:58
at step (<path_redacted>/node_modules/json-schema-to-typescript/dist/src/index.js:59:23)
at Object.next (<path_redacted>/node_modules/json-schema-to-typescript/dist/src/index.js:40:53)

However:

  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "definitions": {
    "Thing_1": {
      "type": "object",
      "properties": {
        "schema_version": {
          "type": "integer",
          "minimum": 0,
          "maximum": 18446744073709551615
        },
        "short_name": {
          "type": "string"
        },
        "long_name": {
          "type": "string"
        },
        "not_a_description": {
          "type": "string"
        }
      },
      "required": [
        "short_name"
      ],
      "additionalProperties": false
    }
  },
  "type": "object",
  "properties": {
    "$ref": "#/definitions/Thing_1"
  }
}

does not.

danmichaelo added a commit to danmichaelo/json-schema-to-typescript that referenced this issue Aug 28, 2023
bcherny pushed a commit that referenced this issue Aug 29, 2023
* Add failing test case

* Fix crash when deprecated is defined without description

* Add test case for #540 too
@bcherny
Copy link
Owner

bcherny commented Aug 29, 2023

Published 13.1.1

@bcherny bcherny closed this as completed Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants