Skip to content
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][Spring] Process and generate variables/objects (and their annotations) recursively in mustache #19601

Open
DatApplePy opened this issue Sep 17, 2024 · 8 comments · May be fixed by #19630

Comments

@DatApplePy
Copy link
Contributor

DatApplePy commented Sep 17, 2024

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.

@DatApplePy DatApplePy changed the title [REQ][Java][Spring] Process and generate variables (and their annotations) recursively in mustache [REQ][Java][Spring] Process and generate variables/objects (and their annotations) recursively in mustache Sep 17, 2024
@DatApplePy
Copy link
Contributor Author

DatApplePy commented Sep 17, 2024

@mibarannikov
Copy link

Hi. A bit offtopic. How to achieve the result of generation from the problem header? How to generate classes with private List<@SiZe(max = 5) Set<@pattern(regexp = "^[0-9]{10,15}$") String>> testList;. help me

@mibarannikov
Copy link

how to turn this
image
into this
image

@DatApplePy
Copy link
Contributor Author

Hi @mibarannikov Sorry, but I don't understand your question exactly. What you wrote is correct, that code snippet will be generated from that api spec. Or maybe you got something else, which is not the one you posted here?

@mibarannikov
Copy link

I've already spent 2 days trying to generate such code Set<@pattern(regexp = "^[0-9]{10,15}$") String> testList; what conditions must be met for a set to be generated with a pattern

@mibarannikov
Copy link

I only get Set testList; , no pattern

@mibarannikov
Copy link

Sorry, as soon as I wrote the message, the solution came. Updating the maven plugin to 7.7.0 helped

@wing328
Copy link
Member

wing328 commented Nov 21, 2024

we just released v7.10.0 a few days ago. please give it a try when you've time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants