Skip to content

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

Merged
merged 17 commits into from
Jul 21, 2022
Merged

feat(java): generic support for hits #829

merged 17 commits into from
Jul 21, 2022

Conversation

millotp
Copy link
Collaborator

@millotp millotp commented Jul 15, 2022

🧭 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:

  • Create GenericPropagator (name subject to discussion, but it rhymes with alligator so it's cool)
  • Add parameter innerType to generic endpoint

🧪 Test

CI

@algolia-bot
Copy link
Collaborator

algolia-bot commented Jul 15, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.
You can still access the code generated on main via this commit.

@netlify
Copy link

netlify bot commented Jul 15, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit b3cd596
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/62d9431b472cad0009e08d79

@millotp millotp self-assigned this Jul 18, 2022
@millotp millotp requested a review from shortcuts July 18, 2022 09:20
Copy link
Member

@shortcuts shortcuts left a 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?

@millotp millotp requested a review from shortcuts July 20, 2022 12:39
Copy link
Member

@shortcuts shortcuts left a 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
Copy link
Member

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?

Copy link
Collaborator Author

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

Copy link
Member

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

Copy link
Collaborator Author

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 ? 😁

Copy link
Member

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

Copy link
Collaborator Author

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 ?

Copy link
Member

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

@millotp millotp requested a review from shortcuts July 21, 2022 09:01
Copy link
Member

@shortcuts shortcuts left a 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

@millotp millotp requested a review from shortcuts July 21, 2022 12:29
Copy link
Member

@shortcuts shortcuts left a 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

Comment on lines +23 to +37
/**
* 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);
}
Copy link
Member

@shortcuts shortcuts Jul 21, 2022

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

@millotp millotp merged commit d3fb62c into main Jul 21, 2022
@millotp millotp deleted the feat/generic-java branch July 21, 2022 12:33
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.

3 participants