-
Notifications
You must be signed in to change notification settings - Fork 21
feat(java): generic support for hits #829
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
Conversation
✗ The generated branch has been deleted.If the PR has been merged, you can check the generated code on the |
✅ Deploy Preview for api-clients-automation canceled.
|
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.
(GG!!!!)
first pass, looks like it's working for Java, what's the issue on the JS support side?
generators/src/main/java/com/algolia/codegen/GenericPropagator.java
Outdated
Show resolved
Hide resolved
generators/src/main/java/com/algolia/codegen/GenericPropagator.java
Outdated
Show resolved
Hide resolved
generators/src/main/java/com/algolia/codegen/GenericPropagator.java
Outdated
Show resolved
Hide resolved
generators/src/main/java/com/algolia/codegen/GenericPropagator.java
Outdated
Show resolved
Hide resolved
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.
Looks correct on the tree traversing side, I feel like we definitely need more comments otherwise we will forget if something break
private GenericPropagator() {} | ||
|
||
/** | ||
* Add the property x-true-generic to a model or property, meaning it should be replaced with T |
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 would be a false generic? Couldn't this be the x-is-generic
?
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.
True generic means that it can be replaced with T
directly, and I needed something different than x-is-generic
otherwise the tree traversal might eat it's own tail in markTrueGeneric
and go further than wanted.
I didn't actually try it so x-is-generic
might be enough but I wanted to be sure not to mix things between spec and generation
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.
Ok make sense! true
would imply that we encounter false one so maybe just a naming thing
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.
do you have a better name ? 😁
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.
Maybe rename x-is-generic
to x-is-base-generic
and all of the propagated ones are x-is-generic
, or call them x-is-propagated-generic
so the one in the spec remains
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.
the other one are propagated
too ahah, maybe x-is-original-generic
, or x-is-replaceable-generic
?
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.
IMO only the method and end object (the one in the spec) should be the "base" so x-is-generic
is good, the rest should be the propagated ones so x-propagate-generic
or keep the child logic
It's just for the naming so no big deal pick whatever sounds good to your ears, I just felt like true
was confusing :D
generators/src/main/java/com/algolia/codegen/GenericPropagator.java
Outdated
Show resolved
Hide resolved
generators/src/main/java/com/algolia/codegen/GenericPropagator.java
Outdated
Show resolved
Hide resolved
generators/src/main/java/com/algolia/codegen/GenericPropagator.java
Outdated
Show resolved
Hide resolved
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.
Small typos, feel free to ignore the suggestion, looks nice!! :D
generators/src/main/java/com/algolia/codegen/GenericPropagator.java
Outdated
Show resolved
Hide resolved
generators/src/main/java/com/algolia/codegen/GenericPropagator.java
Outdated
Show resolved
Hide resolved
generators/src/main/java/com/algolia/codegen/GenericPropagator.java
Outdated
Show resolved
Hide resolved
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.
Seems good! Nice implem :D
/** | ||
* Add the property x-propagated-generic to a model or property, meaning it should be replaced | ||
* with T directly | ||
*/ | ||
private static void setPropagatedGeneric(IJsonSchemaValidationProperties property) { | ||
setVendorExtension(property, "x-propagated-generic", true); | ||
} | ||
|
||
/** | ||
* Add the property x-has-child-generic to a model or property, meaning one of its members is | ||
* generic and it should propagate the T | ||
*/ | ||
private static void setHasChildGeneric(IJsonSchemaValidationProperties property) { | ||
setVendorExtension(property, "x-has-child-generic", true); | ||
} |
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 don't even need them but I can understand you want to keep it to make it clearer
🧭 What and Why
🎟 JIRA Ticket: APIC-575
Generic support for all models in theory, only works for
hits
and the java client for now.The goal was to make it as easy as possible to add a new generic, only add
x-is-generic
to a model in the spec and the property will be propagated to all of it's parent, up to the return type of the operation.Because java erases type at runtime, we need to pass a additional parameters to inform jackson about the type.
Changes included:
GenericPropagator
(name subject to discussion, but it rhymes with alligator so it's cool)innerType
to generic endpoint🧪 Test
CI