#Swagger - DTO's extended type properties do not appear in request body

13 messages · Page 1 of 1 (latest)

green nexus
#

Hi,

export class ListApiKeyDto extends PaginationDto {
  @IsOptional()
  @IsNumber()
  @Min(1)
  user_id?: number;

  @IsOptional()
  @IsEnum(Role)
  @ApiProperty({ enum: Role })
  role?: Role;

  @IsOptional()
  @IsNumber()
  @Min(1)
  search_configuration_id?: number;

  @IsOptional()
  description: string;
}
export class PaginationDto {
  @IsNumber()
  @IsOptional()
  @Transform(({ value }) => toNumber(value))
  skip = 0;

  @IsNumber()
  @IsOptional()
  @Transform(({ value }) => toNumber(value))
  take = 10;
}
  @Get()
  getAll(@Query() dto: ListApiKeyDto, @GetUser() user: AuthentifiedUser) {
    if (user.role !== Role.READ_WRITE_ALL) {
      dto.user_id = user.sub;
    }

    return this.apiKeysService.findAll(dto);
  }

This DTO appears properly inside the swagger (as the attached iamge shows). However, the extended DTO properties do not appear, any ideas ?

molten dagger
#

Add ApiProperty tag

green nexus
#

I did try that and it didn't fix it

#
export class PaginationDto {
  @IsNumber()
  @IsOptional()
  @Transform(({ value }) => toNumber(value))
  @ApiProperty()
  skip = 0;

  @IsNumber()
  @IsOptional()
  @Transform(({ value }) => toNumber(value))
  @ApiProperty()
  take = 10;
}
green nexus
#

Any ideas ?

molten dagger
#

Did you try this endpoint with the skip and take properties from postman?

green nexus
#

Course I did, it works it even has tests

#

turned out the issue was the fields not having types

#

so I added :number = 0

#

and it fixed it

molten dagger
#

Can you have it like take: number = 10 and same for skip

#

Was some delay, you already did that sorry

green nexus
#
export class PaginationDto {
  @IsNumber()
  @IsOptional()
  @Transform(({ value }) => toNumber(value))
  skip: number = 0;

  @IsNumber()
  @IsOptional()
  @Transform(({ value }) => toNumber(value))
  take: number = 10;
}