Skip to content

Schema $ref to standalone type results in generation of type in generated typescript interface. #141

Closed
@AndyDBell

Description

@AndyDBell

I am not sure whether this is a configuration problem, expected behaviour or a bug but...

I declare a json schema file id.schema.json containing:

{
  "title": "TId",
  "type": "string"
}

Running json-schema-to-typescript.compileFromFile( id.schema.json ) generates:

export type TId = string

I create a second json schema file example.schema.json referencing id.schema.json and containing:

{
  "title": "IExample",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "id.schema.json"
    },
    "name": {
      "type": "string"
    }
  },
  "required":[
    "id"
  ],
  "additionalProperties": false
}

Running json-schema-to-typescript.compileFromFile( example.schema.json ) generates:

export type TId = string

export interface IExample {
  id: TId
  name?: string
}

Here the type TId is generated in addition to the interface IExample. i.e. TId is defined twice, once in each file.

This makes it impossible to use the generated code in a typescript program with out manual editing to remove the second definition of TId.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions