Skip to content

Enable spring bean validation custom-message on fields #6375

@jarpz

Description

@jarpz

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions