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(crd-generator): Add support for more validation constraints #6447

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

baloo42
Copy link
Contributor

@baloo42 baloo42 commented Oct 13, 2024

Description

Add support for the following validation constraints:

  • exclusiveMinimum / exclusiveMaximum by extending @Min and @Max annotations
  • minLength / maxLength for strings with new @Size annotation
  • minItems / maxItems for array like containers with new @Size annotation
  • minProperties / maxProperties for map like containers with @Size annotation

Notes:

  • @Size will be detected on container types similar to @Pattern and @Min/@Max.
  • The use of @Min/@Max and @Size is now restricted to their intended types,
    e.g. @Min/@Max is only intended to be used on number types and not on strings.
  • This implementation uses regarding "exclusivness" the same strategy as described in JSR-303:
    A boolean inclusive flag in the annotation, defaulting to true.

Fixes #5836 (Add support for size constraints)
Fixes #5868 (Add support for exclusiveMinimum/exclusiveMaximum)

TBD:

  • Should @Size be detected on container types, if the type itself is a container?
    e.g. List<@Size(min=1) List<@Size(min=2) String>>
  • I think our @Min/@Max annotation has the wrong type for the value. It feels wrong that we are using double. Are there any plans or thoughts to tackle this?

TODO:

  • Add documentation

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@baloo42 baloo42 changed the title feat(crd-generator): Add support for more validation constratins feat(crd-generator): Add support for more validation constraints Oct 13, 2024
@baloo42 baloo42 marked this pull request as ready for review October 13, 2024 15:39
@@ -148,6 +152,14 @@ static Stream<TestCase> crdApprovalBaseCases(String crdVersion) {
return cases.stream();
}

static Stream<TestCase> crdApprovalCasesApiV2(String crdVersion) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@manusa I have started here with splitting test cases into two groups:

  • The existing tests for api-v1 and api-v2.
  • Test cases targeting new features in api-v2 only.

I think this change is also important for other feature additions. Please let me know if I should prepare this in an extra PR to be able to merge this faster.

Copy link

sonarcloud bot commented Oct 22, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
77.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

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