Skip to content

[Java][Spring] Add support for custom validation messages in Beanvalidation annotations #5643

@TomSoflow321

Description

@TomSoflow321

The PR #4600 added support for beanvalidation annotations, which work fine, but generated annotations also support a message property to specify a custom error message if the validation for that annotation fails.
This can look like this:

@ApiModelProperty(example = "VGVzdA==", value = "")
@Pattern(regexp="^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$", message = "The provided String is not Base64 encoded")
public String getFoo() {
    return foo;
}

Are there plans to add support for such a message? It might be possible to add it to the declaration file like:

foo:
    type: string
    pattern: "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$"
        message: "The provided String is not Base64 encoded"
    example: "VGVzdA=="

I guess this feature must be added in the beanValidationCore.mustache template (in swagger-codegen/src/main/java/resources/), but I'm not proficient enough with that template language to do that myself.

(I've tested the release version of 2.2.0 and the current master version, but both don't support these message properties)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions