PickType ignore parent's @Transform when grandparent use @Transform
KuanWenChen opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
My ValidationPipe setting is
app.useGlobalPipes(new ValidationPipe({ transform: true }));
My Dto is
import { PickType } from '@nestjs/swagger';
import { Expose, Transform } from 'class-transformer';
export class TestDto1 {
@Expose()
@Transform(() => {
console.log('TestDto1 Transform');
return 1;
})
version!: number;
}
export class TestDto2 extends PickType(TestDto1, ['version']) {
@Transform(() => {
console.log('TestDto2 Transform');
return 2;
})
version!: number;
}
export class TestDto3PickTypeVersion extends PickType(TestDto2, ['version']) {
@Transform(() => {
console.log('TestDto3 Transform');
return 3;
})
version!: number;
}
export class TestDto3ExtendVersion extends TestDto2 {
@Transform(() => {
console.log('TestDto3 Transform');
return 3;
})
version!: number;
}
My Controller is
@Controller('test')
export class TestController {
@Post('/pick-type-version')
test1(@Body() testDto3PickTypeVersion: TestDto3PickTypeVersion) {
return testDto3PickTypeVersion;
}
@Post('/extend-version')
test2(@Body() testDto3ExtendVersion: TestDto3ExtendVersion) {
return testDto3ExtendVersion;
}
}
When I call 「http://localhost:3000/pick-type-version」
TestDto3PickTypeVersion ignore TestDto2's @Transform.
When I call 「http://localhost:3000/extend-version」
TestDto2's @Transform would work.
If I change TestDto1 as
export class TestDto1 {
@Expose()
version!: number;
}
TestDto2's @Transform would be work too.
Minimum reproduction code
https://github.com/KuanWenChen/swagger-issue
Steps to reproduce
npm install
npm run start:dev
goto website http://localhost:3000/swagger
Call Api and See log.
Expected behavior
When I call「http://localhost:3000/pick-type-version」, I need to see 「TestDto2 Transform」
TestDto3PickTypeVersion should not ignore TestDto2's @Transform.
Package version
^7.1.13
NestJS version
10.2.7
Node.js version
v18.16.0
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response
Would you like to create a PR for this issue?
OK, I has found the problem is happen at mapped-types function inheritTransformationMetadata
The problem is occurring at existingRules, and targetMetadataEntries are overwriting values taht with the same key ; they should merge.
I have created another issue for this problem.