bcherny/json-schema-to-typescript

Dealing with objects that have titles beginning with a number

Open

#151 opened on Mar 20, 2018

View on GitHub
 (3 comments) (0 reactions) (0 assignees)TypeScript (449 forks)github user discovery
buggood first issuehelp wanted

Repository metrics

Stars
 (3,302 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Given the following json schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "title": "Product Export Schema",
  "properties": {
    "products": {
      "type": "array",
      "title": "Products",
      "items": {
        "oneOf": [
          {
            "type": "object",
            "title": "3D Model",
            "properties": {
              "type": {
                "type": "string",
                "title": "Type",
                "constant": "3d_surface_model"
              },
              "description": {
                "type": "string",
                "title": "Description",
                "default": ""
              }
            }
          }
        ]
      },
      "minItems": 1
    }
  }
}

json-schema-to-typescript will produce the following error:

$ ./node_modules/.bin/json2ts demo.json demo.d.ts
';' expected. (9:25)
   7 | export type Type = string
   8 | export type Description = string
>  9 | export type Products = 3DModel[]
     |                         ^
  10 | 
  11 | export interface ProductExportSchema {
  12 | products?: Products┌[chrlu][yeti][master]:~/so

Would it be possible to modify json-schema-to-typescript to perhaps prefix these types so that they become legal TS identifiers/names?

Contributor guide