Skip to content

Compilation crashes if a title prop starts with a number #489

Open
@erunion

Description

@erunion
const { compile } = require('.');

const schema = {
  "title": "2022 Example Schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "example": "61e36b8fc12c4d8fd0842f76"
    }
  }
};

compile(schema).then(ts => console.log);
(node:39640) UnhandledPromiseRejectionWarning: SyntaxError: Declaration or statement expected. (8:1)
   6 | */
   7 |
>  8 | export interface 22ExampleSchema {
     | ^
   9 | id?: string
  10 | [k: string]: unknown
  11 | }
    at Ve (/Users/erunion/code/erunion/json-schema-to-typescript/node_modules/prettier/parser-typescript.js:1:15607)
    at vz (/Users/erunion/code/erunion/json-schema-to-typescript/node_modules/prettier/parser-typescript.js:280:5919)
    at Object.yz [as parse] (/Users/erunion/code/erunion/json-schema-to-typescript/node_modules/prettier/parser-typescript.js:280:6242)
    at Object.parse (/Users/erunion/code/erunion/json-schema-to-typescript/node_modules/prettier/index.js:7334:23)
    at coreFormat (/Users/erunion/code/erunion/json-schema-to-typescript/node_modules/prettier/index.js:8645:18)
    at formatWithCursor2 (/Users/erunion/code/erunion/json-schema-to-typescript/node_modules/prettier/index.js:8837:18)
    at /Users/erunion/code/erunion/json-schema-to-typescript/node_modules/prettier/index.js:37229:12
    at format (/Users/erunion/code/erunion/json-schema-to-typescript/node_modules/prettier/index.js:37243:12)
    at format (/Users/erunion/code/erunion/json-schema-to-typescript/dist/src/formatter.js:20:34)
    at /Users/erunion/code/erunion/json-schema-to-typescript/dist/src/index.js:163:56
(Use `node --trace-warnings ...` to show where the warning was created)
(node:39640) 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:39640) [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.

I can fix this by removing proceeding numbers from title and name props in the schemas I'm supplying but it'd be nice if the library was able to detect this and strip them themselves so any interface or type name it generates is valid.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions