class-transformer icon indicating copy to clipboard operation
class-transformer copied to clipboard

feat: extends discriminator lookup

Open getlarge opened this issue 4 years ago • 4 comments

Description

I truly appreciate the possibility to have polymorphic objects in my models. Unfortunately, it's not always possible to add a new specific property to make the discriminator lookup working and moreover, quite often the discriminator itself can already be found in the parent object (in my use cases at least).

My proposal is the following :

  • add a parentProperty flag in DiscriminatorDescriptor to indicate if we should look for the discriminator in the parent
  • allow DiscriminatorDescriptor.subTypes.name to be string or a number
  • allow DiscriminatorDescriptor.propertyto be either string or string[] to provide more complex path
  • create new helpers (getDiscriminator, setFromDiscriminator, removeDiscriminator) in TransformOperationExecutor.ts to delegate lookup and object updates.
  • update transform flow when the discriminator options are provided

Checklist

  • [x] the pull request title describes what this PR does (not a vague title like Update index.md)
  • [x] the pull request targets the default branch of the repository (develop)
  • [x] the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • [x] tests are added for the changes I made (if any source code was modified)
  • [x] documentation added or updated
  • [x] I have run the project locally and verified that there are no errors
  • [x] add extra unit tests in custom-transform.spec

Fixes

fixes #857

getlarge avatar Aug 05 '21 05:08 getlarge

Do you plan to review it ?

loic49 avatar Sep 10 '21 16:09 loic49

Is there have any update?

wangcode avatar Dec 27 '21 08:12 wangcode

Please merge this PR

golan-guy avatar Feb 03 '22 16:02 golan-guy

@NoNameProvided Hey, would it be possible for you to have a look at this PR, and/or eventually give your opinion on such a feature ?

getlarge avatar Apr 12 '22 09:04 getlarge