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?

贡献者指南