typescript-json-schema
typescript-json-schema copied to clipboard
Can not generate default value for using enum in class
enum Fruit {
Apple = 'apple',
Orange = 'orange'
}
class Test {
fruit: Fruit = Fruit.Apple;
}
Then I get:
{
fruit: {
enum: ['apple', 'orange'],
type: 'string',
}
}
I expect the default can be set in here.
I am having this same issue. Any updated @Saul-Mirone
having same issue default values are not being reflected in json-schema.
Facing the same issue. Any updates or workaround for this?
In addition to enums the handling of default values is broken for constants too. While this produces the default value in the schema:
class Test {
num = 10;
}
This does not:
const DEFAULT_NUM = 10;
class Test {
num = DEFAULT_NUM;
}
The PR #600 implements support for referencing enums and constants as default values, would be great if I could get some feedback on it.
See test/programs/default-properties-ref for a test case.