How to define a Nullable
Enum
property?
#2730
-
Hey everyone, export enum BarEnum {
Bar1 = "bar1",
Bar2 = "bar2"
}
export class Foo {
@Required(true, null)
@Enum(BarEnum)
public bar: BarEnum | null;
} I get the following part in the "Foo": { "type": "object", "properties": { "bar": { "type": "string", "enum": ["bar1", "bar2"], "nullable": true, "minLength": 1 } }, "required": ["bar"] } but if I actually use this model with a I don't really see the reason why. A workaround is to use something like export class Foo {
@Required(true, null)
@Enum(BarEnum, null)
public bar: BarEnum | null;
} but that adds |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
You can try to use export enum BarEnum {
Bar1 = "bar1",
Bar2 = "bar2"
}
export class Foo {
@Enum(BarEnum)
@Any('string', 'null')
public bar: BarEnum | null;
} |
Beta Was this translation helpful? Give feedback.
Hello @KBroichhausen
I tried that:
The json-schema is correctly generated, but the problem isn't related to Ts.ED.
AJV doesn't seems to support this kind of rules (ajv-validator/ajv#824). I don't be able to fix that until ajv doesn't support correctly null value for an enum value.
I suggest you to add a default enum value like this: