Skip to content

Bug with decorator @Exclude processing on classes inheritance #77

@scarych

Description

@scarych

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions