bcherny/json-schema-to-typescript

Dealing with objects that have titles beginning with a number

Open

#151 geöffnet am 20. März 2018

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (449 Forks)github user discovery
buggood first issuehelp wanted

Repository-Metriken

Stars
 (3.302 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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