Hello.
I've found some serious problem with @Exclude decorator processing on filtering metadata with isExcluded when I trying to overload some properties on classes inheritance.
Trying to explain on code sample:
// create some basic class
class UserProfile {
@IsString()
name: string;
@IsString()
surname: string;
@IsDate()
birthDate: Date;
}
// declare class with overloaded `birthDate`
class UserProfileSkipDate extends UserProfile {
@Exclude()
@IsOptional()
birthDate: Date;
}
But after creating JSONSchema for UserProfileSkipDate I see that data:
{
"properties":{
"name":{
"type":"string"
},
"surname":{
"type":"string"
},
"birthDate":{
"oneOf":[
{
"format":"date",
"type":"string"
},
{
"format":"date-time",
"type":"string"
}
]
}
},
"type":"object",
"required":[
"name",
"surname",
"birthDate"
]
}
You may see, that the resulting JSON still contains the birthDate attributes into properties and required.
That happens because filter for metas value into function validationMetadataArrayToSchemas detect IsExclude on the top of list and correctly ignores birthDate meta the first iteration, but on the next steps still keeps metadata from getInheritedMetadatas list and in fact restores the default metadata for overloaded property.
I've prepared the PR to fix this bug. Hope you'll approve that.
Hello.
I've found some serious problem with
@Excludedecorator processing on filtering metadata withisExcludedwhen I trying to overload some properties on classes inheritance.Trying to explain on code sample:
But after creating JSONSchema for
UserProfileSkipDateI see that data:{ "properties":{ "name":{ "type":"string" }, "surname":{ "type":"string" }, "birthDate":{ "oneOf":[ { "format":"date", "type":"string" }, { "format":"date-time", "type":"string" } ] } }, "type":"object", "required":[ "name", "surname", "birthDate" ] }You may see, that the resulting JSON still contains the
birthDateattributes intopropertiesandrequired.That happens because filter for
metasvalue into functionvalidationMetadataArrayToSchemasdetectIsExcludeon the top of list and correctly ignoresbirthDatemeta the first iteration, but on the next steps still keeps metadata fromgetInheritedMetadataslist and in fact restores the default metadata for overloaded property.I've prepared the PR to fix this bug. Hope you'll approve that.