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

Restrict JSR-303 annotations to supported field types #1063

Merged

Conversation

rajpaulbagga
Copy link

I found that JSR-303 annotations were getting applied to types that didn't support them. For example, if a "pattern" was specified on a "string" property that also had a "format" of "uuid", then the generated field type is UUID class (rather than String) and @Pattern was still applied. Because that annotation isn't valid on a UUID type, then validators generate errors.

Continuing with this example, because a schema may be used to generate source classes in non-Java languages, there is still value to keep the "pattern" restriction on the source json schema itself for languages that might not have an in-built UUID type.

This patch updates the various JSR-303 Rules classes to enhance them to check the generated class type of potentially annotated fields against the classes/types that are documented to support the relevant annotation (as documented in each annotation's JavaDoc).

In a second logical commit, Unit tests were added for thes JSR-303 rules classes. This required updating Mockito to a newer version that (properly) supports mocking final classes.

In a third logical commit, integration tests were updated with schemas that generate unsupported field types for the various cases, in addition to the supported types.

…ally supported by those annotations.

E.g. Don't apply a `@Pattern` annotation to a `UUID` type as this can cause errors on validator implementations.
Adjust the integration tests for max and min to use integer types since the relevant annotations are documented to not support double & float.
… and applying the config file to allow this.

Mockito needed to be upgraded to a version that properly supports mocking `final` classes (version 1.9.5 did not work right)
The directive in `org.mockito.plugins.MockMaker` is what enables mocking of `final`s.
…re not applied and interfering with validation for field types not supported.
@rajpaulbagga rajpaulbagga reopened this Jan 2, 2020
@joelittlejohn joelittlejohn merged commit 9a2e644 into joelittlejohn:master Jan 8, 2020
@joelittlejohn joelittlejohn added this to the 1.0.2 milestone Jan 8, 2020
@rajpaulbagga rajpaulbagga deleted the feature/jsr-type-restrictions branch January 8, 2020 13:43
@rajpaulbagga
Copy link
Author

@joelittlejohn ,
Do you have any plans or notions when you might release 1.0.2?
Thank you.

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