OpenAPITools / OpenAPITools/openapi-generator
Is It Necessary to set Parent's member data through Child member function
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [Y] Have you provided a full/minimal spec to reproduce the issue?
- [Y] Have you validated the input using an OpenAPI validator (example)?
- [Y] Have you tested with the latest master to confirm the issue still exists?
- [Y] Have you searched for related issues/PRs?
- [Y] What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Defined a java inheritance relationship with openapi input file and found that the child class sets its parent member data through a function with the same name as the member data of the parent. Is that a best practice suggested by Java world or following some standards? Could somebody explain what the reason putting the function there.
public Child address(String address) {
super.setAddress(address);
return this;
}
openapi-generator version
OpenAPI 3 7.0.0-beta branch
OpenAPI declaration file content or url
{
"openapi": "3.0.1",
"info": {
"title": "Table for school children",
"description": "## Students' information",
"version": "4.0.0"
},
"paths": {
},
"components": {
"schemas": {
"Child": {
"allOf": [
{
"$ref": "#/components/schemas/Parent"
},
{
"required": [
"name"
],
"type": "object",
"properties": {
"description": {
"type": "string",
"description": "Child information"
},
"name": {
"type": "string",
"description": "Name of the child"
}
},
"description": "Child class"
}
]
},
"Parent": {
"type": "object",
"properties": {
"address": {
"type": "string",
"description": "Family address"
}
},
"discriminator": {
"propertyName": "address"
},
"description": "Parent information"
}
}
}
}
Generation Details
java -jar openapi-generator-cli.jar generate -g spring -c ../bug-report/springOptions.json -v -i "../bug-report/inheritance.json" -o "../bug-report/school_src"
Steps to reproduce
Above
Related issues/PRs
Suggest a fix
Either remove the function, or provide the rational for providing it.
Alternative could be make it an option with adding a configuration flag.
Thanks.
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
Start by running the reported spring generator command with inheritance.json and springOptions.json, then inspect the generated Child class and its inherited address handling. Trace how the Java Spring generator represents the allOf relationship and compare the generated fluent function with the parent setter. Done means the behavior has a documented rationale or a clearly specified change, supported by a regression test if the behavior is changed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100