bcherny/json-schema-to-typescript

Dealing with objects that have titles beginning with a number

Open

#151 aperta il 20 mar 2018

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)TypeScript (449 fork)github user discovery
buggood first issuehelp wanted

Metriche repository

Star
 (3302 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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?

Guida contributor