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

feat: enable forbidUnknownValues by default #1798

Merged
merged 2 commits into from
Nov 20, 2022

Conversation

NoNameProvided
Copy link
Member

@NoNameProvided NoNameProvided commented Nov 20, 2022

Description

This PR enables forbidUnknownValues by default. This is done to prevent objects pass validation when no check would be done on them. After this change is released any validated object that has no metadata associated with it will fail the validation.

One notable example of this is validating with groups. If the called validation excludes all metadata due to the specified group then the validation will fail from now on instead of passing. Example:

class MyPayload {
    @IsString({ groups: ['A']})
    property: string;

    constructor(property: string) {
      this.property = property;
    }
}

validate(new MyPayload('value'), { groups: ['B'] }).then(console.log);

Calling the above will result in an error from now on:

[
  ValidationError {
    target: MyPayload { property: 'value' },
    value: undefined,
    property: undefined,
    children: [],
    constraints: {
      unknownValue: 'an unknown value was passed to the validate function'
    }
  }
]

Checklist

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

Fixes

references #438, references #1422

@NoNameProvided NoNameProvided added the flag: BREAKING CHANGE Issues containing a breaking change, requiring a major release. label Nov 20, 2022
@NoNameProvided NoNameProvided merged commit 54a2cdf into develop Nov 20, 2022
@NoNameProvided NoNameProvided deleted the feat/enable-forbid-unknown-values-by-default branch November 20, 2022 17:29
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
flag: BREAKING CHANGE Issues containing a breaking change, requiring a major release.
Development

Successfully merging this pull request may close these issues.

1 participant