OpenAPITools / OpenAPITools/openapi-generator
[REQ] expose parentContainer to templates, add itemsDepth property to container items
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I'm extending the models generated from swaggers with a deepCopy() method for java. For this I need to generate code based on the property types, but in case the baseType is List or Map, the detailed type information is lost to the templates (see: generateAliasAsModel).
I propose exposing the "parentContainer" type in these cases similar to how "items" are exposed for container properties.
The other issue is creating temporary variables for nested elements, as we can run into shadowing errors. To solve this issue I propose adding an "itemsDepth" property to nested properties ("items"), that reflects that depth in a container-hierarchy.
With these changes, one can generate code like this:
protected ArrArr deepCopyImpl(ArrArr source) {
this.strArrArr = (source.strArrArr == null
? null
: source.strArrArr.stream().map(v$1 -> (v$1 == null
? null
: v$1.stream().map(v$2 -> (v$2 == null
? null
: v$2.deepCopy())
).collect(Collectors.toList()))
).collect(Collectors.toList()));
return this;
}
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 at generateAliasAsModel and the template data for container properties, focusing on how items are currently exposed. Done means templates can access the parentContainer type for List and Map cases and an itemsDepth value for nested container items, supporting the proposed nested-variable generation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100