OpenAPITools / OpenAPITools/openapi-generator
[REQ][Java] Add covariant overrides for inherited allOf setters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
When generating a model class which is an allOf, the Java generators make it a subclass (of the first allOf entry anyway) with all the getter/setter methods inherited from the parent. This means that if you are using the fluent setters, the result of calling any inherited setter is the parent not the subclass. It would be useful if it returned the subclass.
For example, consider this fragment
Foo:
type: object
properties:
a:
type: string
Bar:
allOf:
- $ref: '#/components/schemas/Foo'
- type: object
properties:
b:
type: string
The following code will fail, because Bar.a() returns a Foo instead of a Bar. It would be safe to override the method to return Bar, since covariant return types are allowed in Java.
Bar bar = new Bar().a("a").b("b")
This would make using the fluent setters easier when allOf is used.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no implementation files or tests; start with the Java model-generation path for schemas using allOf and the Foo/Bar example. Verify that generated Bar fluent setter calls can chain a("a").b("b") with a Bar result, and add or run coverage for this generated-model case if the repository provides a corresponding generator test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- backend-api-design, devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 56/100