Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common): apply options to plaintoclass in classserializerinterceptor #12764

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kmw14641
Copy link

@kmw14641 kmw14641 commented Nov 16, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: Closes #12763

What is the new behavior?

options can be applied to plainToClass method too, which is needed for options like exposeDefaultValues.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

fixed issue that with type option which is not already converted,
any other option cannot be applied to plainToClass

Closes nestjs#12763
@coveralls
Copy link

Pull Request Test Coverage Report for Build 36d8ee9e-355b-4c7c-afec-7cf9f5073e60

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.26%

Totals Coverage Status
Change from base Build 23ebebfc-1ad4-4b2b-8c07-2691151ef178: 0.0%
Covered Lines: 6687
Relevant Lines: 7248

💛 - Coveralls

const instance = classTransformer.plainToClass(
options.type,
plainOrClass,
options,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is intentional. We only passed options to the classToPlain function so far - wondering if changing this now wouldn't cause any breaking changes in existing projects.

Copy link
Author

@kmw14641 kmw14641 Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After I searched plainToClass method in this repository, I found that except example code there is only one use case in validationPipe and it applied option. I think if developer explicitly used option, then any transform methods which is related to that option should use that option, too. If developer wants to apply option to only classToPlain, I think making developer use toPlainOnly option to decorator(for example Expose) is right. In this file, plainToClass is called only when developer used type option to convert type, and in this case applying option to both transform method seems like correct action, so maybe there is no breaking changes.

@jobcespedes
Copy link

Anyway to help this get resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Applying type option to ClassSerializerInterceptor can cause other options to be ignored
4 participants