-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): skip key that is a method in getPathRecursive
Class methods are stored on the prototype of the class. Hence, it does not make sense to try to automap any class methods. Naive approach is to check if the type of the property is function, then we skip it fix #396
- Loading branch information
Showing
4 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/integration-test/src/lib/with-classes/fixtures/models/issue-396.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
|
||
export class NestedOptionalClass { | ||
@AutoMap() | ||
name?: string; | ||
|
||
public getFullName(): string { | ||
return this.name; | ||
} | ||
} | ||
|
||
export class Source { | ||
@AutoMap() | ||
description?: string; | ||
@AutoMap({ typeFn: () => NestedOptionalClass }) | ||
options?: NestedOptionalClass; | ||
} | ||
|
||
export class SourceChild extends Source { | ||
@AutoMap() | ||
another?: string; | ||
} | ||
|
||
export class Destination { | ||
@AutoMap() | ||
description?: string; | ||
@AutoMap({ typeFn: () => NestedOptionalClass }) | ||
options?: NestedOptionalClass; | ||
} | ||
|
||
export class DestinationChild extends Destination { | ||
@AutoMap() | ||
another?: string; | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/integration-test/src/lib/with-classes/fixtures/profiles/issue-396.profile.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { mapFrom, MappingProfile } from '@automapper/core'; | ||
import { | ||
Destination, | ||
DestinationChild, | ||
Source, | ||
SourceChild, | ||
} from '../models/issue-396'; | ||
|
||
export const issue396Profile: MappingProfile = (mapper) => { | ||
mapper.createMap(Source, Destination).forMember( | ||
(d) => d.options, | ||
mapFrom((s) => s.options) | ||
); | ||
mapper.createMap(SourceChild, DestinationChild, { | ||
extends: [mapper.getMapping(Source, Destination)], | ||
}); | ||
}; |
32 changes: 32 additions & 0 deletions
32
packages/integration-test/src/lib/with-classes/issue-396.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { setupClasses } from '../setup.spec'; | ||
import { CamelCaseNamingConvention } from '@automapper/core'; | ||
import { issue396Profile } from './fixtures/profiles/issue-396.profile'; | ||
import { | ||
DestinationChild, | ||
NestedOptionalClass, | ||
SourceChild, | ||
} from './fixtures/models/issue-396'; | ||
|
||
describe('Issue 396', () => { | ||
const [mapper] = setupClasses('issue-396', new CamelCaseNamingConvention()); | ||
|
||
it('should map', () => { | ||
mapper.addProfile(issue396Profile); | ||
|
||
const options = new NestedOptionalClass(); | ||
options.name = 'name'; | ||
|
||
const input1 = new SourceChild(); | ||
input1.description = 'description'; | ||
input1.options = options; | ||
|
||
const output1 = mapper.map(input1, DestinationChild, SourceChild); | ||
expect(output1).toBeTruthy(); | ||
|
||
const input2 = new SourceChild(); | ||
input2.description = 'description 2'; | ||
|
||
const output2 = mapper.map(input2, DestinationChild, SourceChild); | ||
expect(output2).toBeTruthy(); | ||
}); | ||
}); |