swagger-api / swagger-api/swagger-codegen

custom validation message in bean validation annotations

Open
#9,512 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description
[JAVA]
When i try to generate the objects using the below , generate objects does not have message value .
expected:
@JsonProperty("inlineString")
@Nullable
@Size(max=100, message='validation message')
public String getinlineString();

instead getting

@JsonProperty("inlineString")
@Nullable
@Size(max=100)
public String getinlineString();

Test.yaml File
efinitions:
stringPattern:
type: string
minLength: 1
maxLength: 20
pattern: '^([a-zA-Z0-9])*$'
decimalNumber:
type: number
minimum: 0
maximum: 9999999999999.99
multipleOf: 0.01
ApiRequest:
type: object
properties:
stringPattern:
$ref: '#/definitions/stringPattern'
decimalNumber:
$ref: '#/definitions/decimalNumber'
inlineString:
type: string
minLength: 1
maxLength: 20
message :" max number should 20"

Swagger-codegen version

using swagger codegen version 2.4.5

Can you please suggest a way to pull the custom validation message in the yaml file and which in turn generates a object with the same messages.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Test.yaml example and trace how its validation constraints are converted into Java Bean Validation annotations by the Java generation templates. Check the generated ApiRequest output and determine how a custom message should be represented and preserved; done means the generated @Size annotation includes the requested message.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.