bcherny/json-schema-to-typescript

Is it possible to use the property keys for nested interface names and not the title?

dclaze opened this issue · 1 comments

dclaze commented

I would like to use the schema object properties as the name of interfaces instead of the title because the titles in my schema are verbose and produce ugly looking interfaces.

Example Time

Example Input (example.json)

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Example Object",
  "type": "object",
  "properties": {
    "nestedObject": {
      "type": "object",
      "properties": {
        "field1": {
          "type": "string"
        },
        "field2": {
          "type": "number"
        },
        "field3": {
          "type": "boolean"
        }
      },
      "required": ["field1", "field2", "field3"]
    }
  },
  "required": ["nestedObject"]
}

Example Command
json2ts -i example.json -o example.ts

Example Output

interface NestedObject {
  field1: string;
  field2: number;
  field3: boolean;
}

interface ExampleObject {
  nestedObject: NestedObject;
}

Can you change your schema's titles to match the interface names you want to emit?