bcherny/json-schema-to-typescript

Dealing with objects that have titles beginning with a number

Open

#151 建立於 2018年3月20日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)TypeScript (449 fork)github user discovery
buggood first issuehelp wanted

倉庫指標

Star
 (3,302 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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?

貢獻者指南