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: Add JsonPropertyOrder annotation to all classes #2820

Conversation

samuel-hawker
Copy link
Contributor

Type of change

Select the type of your PR

  • Enhancement / new feature

Description

Stage 1 of Issue 2779
Validate @JsonPropertyOrder present for all CRD classes
and subclasses with exception of Java primitive Object

Added test class to validate this new functionality and
added Exception: InvalidCrdException

Followup PRs will see the check that JsonPropertyOrder
contains exactly all of the classes fields and these fields
will be ordered for each individual class

Contributes to: #2779

Signed-off-by: Samuel Hawker samuel.hawker@ibm.com

Checklist

Please go through this checklist and make sure all applicable tasks have been done

  • Update/write design documentation in ./design
  • Write tests
  • Make sure all tests pass
  • Update documentation
  • Check RBAC rights for Kubernetes / OpenShift roles
  • Try your changes from Pod inside your Kubernetes and OpenShift cluster, not just locally
  • Reference relevant issue(s) and close them after merging
  • Update CHANGELOG.md

@strimzi-ci
Copy link

Can one of the admins verify this patch?
Run tests: @strimzi-ci run tests

@samuel-hawker
Copy link
Contributor Author

samuel-hawker commented Apr 10, 2020

Things I would like reviewed:

  • Are you happy with the newly added Exception
  • Does my exception of the Object class make sense in the null check
  • Should I make the exception throwing if check only activated if flagged, i.e. pass --strict=true or something similar so you could for development purposes not have to properly annotate every class

@samuel-hawker samuel-hawker force-pushed the 2779-validate-json-property-order-present branch from 485bb7a to c56f30a Compare April 10, 2020 21:45
@scholzj
Copy link
Member

scholzj commented Apr 14, 2020

@samuel-hawker This looks good to me. But having feedback from Tom would be good. But I think he is off this week, so we might need to wait until next week for him.

@@ -427,9 +427,16 @@ private void checkClassOverrides(Class<?> crdClass, String methodName, Class<?>.
}
result.putAll(properties(crdClass));
JsonPropertyOrder order = crdClass.getAnnotation(JsonPropertyOrder.class);
if (order == null && !isExemptClass(crdClass)) {
throw new InvalidCrdException(crdClass.getName() + " missing @JsonPropertyOrder annotation");
Copy link
Member

Choose a reason for hiding this comment

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

I think you just need to call err() (which will log the error and exit at the end, that way you get told about all the errors, rather than having to fix them one at a time).

return sortedProperties(order != null ? order.value() : null, result).values();
}

private boolean isExemptClass(Class<?> crdClass) {
Copy link
Member

Choose a reason for hiding this comment

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

This method name is too generic. There's plenty of checks on classes in the CrdGenerator, so you need to give it a name which makes clear what it's exempt from. Maybe inverting it and calling it requiresPropertyOrder(Class<?>)?

Stage 1 of Issue 2779
Validate @JsonPropertyOrder present for all CRD classes
and subclasses with exception of Java primitive `Object`

Added test class to validate this new functionality and
added Exception: InvalidCrdException

Followup PRs will see the check that JsonPropertyOrder
contains exactly all of the classes fields and these fields
will be ordered for each individual class

Contributes to: strimzi#2779

Signed-off-by: Samuel Hawker <samuel.hawker@ibm.com>
Signed-off-by: Samuel Hawker <samuel.hawker@ibm.com>
@samuel-hawker samuel-hawker force-pushed the 2779-validate-json-property-order-present branch from c56f30a to dddbb2f Compare May 5, 2020 10:14
@samuel-hawker
Copy link
Contributor Author

Still ironing out some problems with the tests, closing for awhile

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.

4 participants