Closed workfel closed 7 years ago
You must define a custom type. Since vulcainjs v1.1.140, you can create a type with annotation like this:
@SchemaTypeDefinition()
export class ArrayOfEnum implements ISchemaTypeDefinition {
// Overrided properties
$values: any[];
validate(val) {
if (!this.$values)
return "You must define array item type with the 'items' property.";
if (!Array.isArray(val))
return "Invalid value '{$value}' for '{$propertyName}', value must be an array.";
let error = false;
for(let e of val) {
if (this.$values.indexOf(val) === -1) {
error = true;
break;
}
}
if (error)
return "Invalid value '{$value}' for '{$propertyName}', all values must be one of [{$values}].";
}
// bind(val: any): any {}
}
and use it like that:
@Property({type: "ArrayOfEnum", values: ["a", "b"]})
enums: string[];
Hey,
I would like to know if it's possible to have an Array of enum on the
Property
. I have thisCan do have an property type like
Thx