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

How to include custom message holder for javax - bean-validation #2238

Closed
jarpz opened this issue May 19, 2020 · 2 comments
Closed

How to include custom message holder for javax - bean-validation #2238

jarpz opened this issue May 19, 2020 · 2 comments

Comments

@jarpz
Copy link

jarpz commented May 19, 2020

Given a openapi.yml with any object with field constraints like this:

lastNames:
  type: "string"
  description: "Affiliate last names"
  maxLength: 10
birthdate:
  type: "string"
  format: "date"
  example: '2020-02-02'
names:
  type: "string"
  maxLength: 5

When we apply the plugin to generate code with java + spring-reactive we can obtain an object like this:

@ApiModelProperty(required = true, value = "")
@NotNull
@Size(max=5) 
public String getNames() {
  return names;
}

@ApiModelProperty(required = true, value = "Affiliate last names")
@NotNull
@Size(max=10) 
public String getLastNames() {
  return lastNames;
}

With javax. bean validation we can customize the message with a placeholder or hard-coded text.

@Size(max=10,message="{my-error}")

Is there any way to customize javax annotation messages with place holders or text?

Regards

@handrews
Copy link
Member

@jarpz this repository is for the OpenAPI specification itself. Please raise tooling issues with the tooling vendor.

More generally, it will be easier to extend JSON Schema within OpenAPI in OAS 3.1, and things like adding annotations for error messages would be a good use case for a set of extension keywords. This is the sort of thing that tooling vendors will probably drive, though. Over at the JSON Schema project, we've been asked about this several times but it's quite a challenge because competing desires around message behavior and I18N/L10N. So we have avoided adding it to the main JSON Schema specification.

@jarpz
Copy link
Author

jarpz commented May 20, 2020

Thanks for your review. I have posted this enhancement on plugin repo.

Regards

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

No branches or pull requests

3 participants