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

Support primitive validation - limited to int,long with @Range initially #137

Merged
merged 2 commits into from
Aug 9, 2023

Conversation

rob-bygrave
Copy link
Contributor

@rob-bygrave rob-bygrave commented Aug 9, 2023

Generated code changes the type to ValidationAdapter.Primitive and uses .primitive() like:

  private final ValidationAdapter.Primitive valueValidationAdapter;

  public APrimitiveLongRangeValidationAdapter(ValidationContext ctx) {
    this.valueValidationAdapter = 
        ctx.<Long>adapter(Range.class, Map.of("min",1L, "max",3L, "message","{avaje.Range.message}", "_type","Long"))
            .primitive();

  }

@rob-bygrave
Copy link
Contributor Author

If we like this we can extend it to @Max, @Min, @Positive, @Negative etc

Copy link
Collaborator

@SentryMan SentryMan left a comment

Choose a reason for hiding this comment

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

hey wait this works

@rob-bygrave
Copy link
Contributor Author

I'll push the changes to support Min, Max, Positive, Negative etc

@SentryMan
Copy link
Collaborator

Inspiration strikes me, when you merge I'll do for all the primitives.

@rob-bygrave rob-bygrave merged commit 562bcb8 into main Aug 9, 2023
2 checks passed
@rob-bygrave rob-bygrave deleted the feature/primitive-validation branch August 9, 2023 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants