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] Generate validation for type arguments in containers via mustache template #19557

Open
DatApplePy opened this issue Sep 9, 2024 · 1 comment · May be fixed by #19630
Open

Comments

@DatApplePy
Copy link
Contributor

DatApplePy commented Sep 9, 2024

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

On our project, we would like to specify individual error messages for each constraint (e.g. @Pattern or @Size). For this, there is already a vendor extension (x-pattern-message) in the BeanValidationCore.mustache template as an example. The problem is that while validation annotations are generated for non-container types, such as String, based on the mustache template, annotations for type arguments in containers are merged with the container type in the generator itself. Therefore, in such a case, we have no chance to provide a unique error message and we receive the default messages given by Jakarta.


Non-container example:

exampleString:
  type: string
  pattern: "^\d{10,50}$"
  x-pattern-message: "invalid example"
@Pattern(regex = "^\\d{10,50}$", message = "invalid example")
public String getExampleString() {
  return exampleString;
}

Container example:

exampleList:
  type: array
  items:
    type: string
    pattern: "^\d{10,50}$"
    x-pattern-message: "invalid example"
public List<@Pattern(regex = "^\\d{10,50}$") String> getExampleList() {
  return exampleList;
}

Describe the solution you'd like

Currently, annotations for type arguments are "hard-coded" (source) and assigned to the dataType along with the container type. It should be split into two separate variables and used in mustache templates that way. I think it would be good if the generator used the BeanValidationCore.mustache template (or a new one) for container types as well as for non-container types. This would provide the opportunity to take control over what we want the generator to do in these cases by customizing the mustache templates.

Note

If no one applies for the task, I will gladly take it on, because we really need this feature (or something similar) on the project :D

@DatApplePy DatApplePy changed the title [REQ][Java] Generate validation for type arguments in containers via mustache template [REQ][Java][Spring] Generate validation for type arguments in containers via mustache template Sep 17, 2024
@DatApplePy
Copy link
Contributor Author

This issue has an extended version (#19601). In case it is closed, this can also be closed.

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