Closed a0js closed 5 months ago
You can do something like this:
{
"title": "Example Schema",
"type": "object",
"definitions": {
"circle": {
"type": "string",
"enum": [
"circle"
]
},
"square": {
"type": "string",
"enum": [
"square"
]
},
"shape": {
"oneOf": [
{
"$ref": "#/definitions/circle"
},
{
"$ref": "#/definitions/square"
}
]
}
},
"properties": {
"shape": {
"$ref": "#/definitions/shape"
}
}
}
=>
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/
export type Shape = Circle | Square;
export type Circle = "circle";
export type Square = "square";
export interface ExampleSchema {
shape?: Shape;
[k: string]: unknown;
}
Thank you @bcherny!
Is it possible to reference a specific enum value that is defined in another referenced definition? For example in defining a discriminating union:
Ideally it would output something like this: