OpenAPITools / OpenAPITools/openapi-generator

[REQ][Java][Spring] Process and generate variables/objects (and their annotations) recursively in mustache

Open
#19,601 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Currently, all container objects (List, Set and Map) with their elements are processed as one in the generator (AbstractJavaCodegen).
Example:

testList:
  type: array
  maxItems: 10
  items:
    type: array
    maxItems: 5
    uniqueItems: true
    items:
      type: string
      pattern: "^[0-9]{10,15}$"

datatypeWithEnum value of testList: List<@Size(max = 5) Set<@Pattern(regexp = "^[0-9]{10,15}$") String>>

Generated code:

@Size(max = 10)
private List<@Size(max = 5) Set<@Pattern(regexp = "^[0-9]{10,15}$") String>> testList;

This leads to 2 problems (that's all I've found so far):

  1. Cannot create and apply custom annotations
  2. Custom messages cannot be applied to Jakarta annotations

Describe the solution you'd like

It would be better if the dataTypeWithEnum value of the variables contained only the type of the current schema.
Using the previous example, the result would be this:

name: testList
dataTypeWithEnum: List
isContainer: true
isArray: true
uniqueItems: false
...
items:
  dataTypeWithEnum: Set
  isContainer: true
  isArray: true
  uniqueItems: true
  ...
  items:
    dataTypeWithEnum: String

This way we can generate these structures recursively and also apply custom annotation and more.

Additional context

Since this issue is the extended form of another issue (#19557), I am already working on the feature.

Note: The development process can be slow because I read a lot of documentation (and StackOverFlow) and experiment a lot to make everything work as intended.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AbstractJavaCodegen and the related issue #19557, then trace how container schemas currently produce dataTypeWithEnum and annotations. The intended result is recursive variable/object metadata for nested List, Set, and Map structures, with custom annotations and Jakarta annotation messages applied at the appropriate level; verify the generated Java output against the nested YAML example.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.