-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[REQ][Java][Jersey2] Generate java method for each oneOf/anyOf #6892
Comments
@sebastien-rosset thanks for the feedback. Agreed with these improvements. I'll see what I can do to make it better. |
@sebastien-rosset I would also love the oneOf implementation to get better. Could you please provide a specific example of code where having
and with what you propose I'll have do
What I'm trying to say is that I don't see a benefit in LoC/how the code reads/how fast you write the code/how the code is performant. Could you explain the use case where this helps? |
In practice I see the problems below: // How do you know getActualInstance can return an instance of X, Y and Z?
// How do you know getActualInstance cannot return an instance of W?
// How do you know you are handling all possible classes?
Object o = foo.getActualInstance();
if (o instanceof X) {
X x = (X) o;
// do something with x
}
X x = foo.getX(); I'm not advocating that we eliminate the |
Ok, that makes sense, thanks for the explanation. That said, we have to ensure that we have protection set to ensure there are no method name clashes (e.g. if someone had a |
@bkabrda good catch about the edge case. We'll handle it when there's a report on the issue. |
Is your feature request related to a problem? Please describe.
Currently, in the generated Java jersey2 library, a class is generated for every oneOf, anyOf schema in the OpenAPI document. Every oneOf/anyOf class inherits from
AbstractOpenApiSchema
. The AbstractOpenApiSchema.java class has thepublic Object getActualInstance()
andObject getActualInstanceRecursively()
methods which both return anObject
. There is no type information in the return value besides being anObject
.IMO, there are two problems that could be improved:
Describe the solution you'd like
Suppose the OpenAPI document has
oneOf: [X, Y, Z]
. It would be helpful to:getActualInstance
can be a X, Y or Z. This could be done by overriding getActualInstance() which would just invoke super.getActualInstance(), and there would be generated method comments listing the possible type values.Describe alternatives you've considered
Currently, the developer must read the
oneOf
oranyOf
sections of the OpenAPI document, find out what are the possible types. Then when calling getActualInstance(), the developer must cast the return value to the expected class.Additional context
This would work well if the oneOf/anyOf schemas don't have recursion and if the oneOf/anyOf children are concrete. If there is recursion or if there are abstract classes involved, the developer may still have to cast the return value, but it would still be an improvement over what we have now.
The text was updated successfully, but these errors were encountered: