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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

baloo42
Copy link
Contributor

@baloo42 baloo42 commented Oct 13, 2024

Description

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

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.

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
Copy link

sonarcloud bot commented Nov 4, 2024

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarCloud

Copy link
Collaborator

@metacosm metacosm left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me.

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