json-schema-to-typescript icon indicating copy to clipboard operation
json-schema-to-typescript copied to clipboard

Generated types order and optional exports

Open jeremymelchor opened this issue 5 months ago • 0 comments

Let suppose I have those 2 schemas

example-ref-schema.json

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "$id": "example-ref",
  "properties": {
    "_id": {
      "type": "string"
    },
    "_key": {
      "type": "string"
    }
  },
  "required": ["_id", "_key"],
  "additionalProperties": false
}

example.json

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "allOf": [
    {
      "$ref": "./example-ref-schema.json"
    },
    {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      },
      "required": ["name"],
      "additionalProperties": false
    }
  ]
}

It produces the following output:

example-ref-schema.d.ts

export interface ExampleRef {
  _id: string;
  _key: string;
}

example.d.ts

export type Example = ExampleRef & {
  name: string;
  description?: string;
};

export interface ExampleRef {
  _id: string;
  _key: string;
}

Is it possible to:

  1. have the ExampleRef interface declared before the ExampleWithArangoMetadata type ? I would like to generate Typebox types from this but the order creates an This variable is used before its declaration. error.
  2. Not having the ExampleRef interface from the schema.d.ts (and other schema files) exported but only the one from the example-ref-schema.d.ts ?

jeremymelchor avatar Jul 03 '25 11:07 jeremymelchor