-
Notifications
You must be signed in to change notification settings - Fork 201
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
ENH: introduce conditional annotation for schema generation #4934
ENH: introduce conditional annotation for schema generation #4934
Conversation
Signed-off-by: George Chen <[email protected]>
@@ -0,0 +1,21 @@ | |||
package org.opensearch.dataprepper.model.schemas; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should put this in the package org.opensearch.dataprepper.model.annotations
.
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.FIELD, ElementType.METHOD}) | ||
public @interface IfPresentAlsoRequire { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Schemas and validations are tightly related. So we should aim to have a common language for both schemas and validations. Otherwise the developers will need to track schemas and validations independently and this may introduce misses.
I think a few modifications to the documentation and package will help here.
What do you think about using the name @AlsoRequires()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I am not able to find an out-of-the-box annotation from Jakarta or JsonProperty to achieve this schema property. Thus the custom annotation. I agree the tradeoff would be to maintain a set of custom annotation for schema only.
So we should aim to have a common language for both schemas and validations.
Could you specify what you mean here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you are correct - Jakarta does not have this annotation.
However, you are adding an annotation that you expect to be useful for schema generation. I suggest that we take a different approach. You should be adding annotations that let plugin developers express constraints in one place. Data Prepper should be able to use these annotations for both schema generation and for validation.
So:
- We need a new annotation because there is not one available.
- We should design it to support validation.
- We should document it as being able to express configuration constraints, not as simply a schema generation tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I will open a separate issue for that. To incorporate validation requires additional work in pipeline parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -65,6 +77,12 @@ static class TestConfig { | |||
@JsonProperty(defaultValue = "default_value") | |||
private String testAttributeWithDefaultValue; | |||
|
|||
@JsonProperty | |||
@IfPresentAlsoRequire(values = {"test_mutually_exclusive_attribute_b:null"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this :null
part for? Should we have a distinct model to represent the additional requirement?
e.g.
@IfPresentAlsoRequire({@Required(name = "test_mutually_exclusive_attribute", allowedValues = {null}))
Signed-off-by: George Chen <[email protected]>
Signed-off-by: George Chen <[email protected]>
Signed-off-by: George Chen <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a small documentation suggestion.
data-prepper-api/src/main/java/org/opensearch/dataprepper/model/annotations/AlsoRequires.java
Outdated
Show resolved
Hide resolved
Signed-off-by: George Chen <[email protected]>
…l/annotations/AlsoRequires.java STY: doc string Co-authored-by: David Venable <[email protected]> Signed-off-by: Qi Chen <[email protected]>
Signed-off-by: George Chen <[email protected]>
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Required { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the context clearer. Here are two options.
- Make this a nested annotation in
AlsoRequires
- Rename to
@AlsoRequired
.
I think I like option 1.
Signed-off-by: George Chen <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @chenqi0805 for this contribution!
Description
This PR
IfPresentAlsoRequire
annotation to mark mutually dependent properties in JSON schema generationNote: The generated schema example is as follows:
Issues Resolved
Resolves #[Issue number to be closed when this PR is merged]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.