Skip to content

[BUG] x-pattern-message ignored for list items in Spring generator #21167

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

Open
5 of 6 tasks
mkurczuk opened this issue Apr 28, 2025 · 0 comments
Open
5 of 6 tasks

[BUG] x-pattern-message ignored for list items in Spring generator #21167

mkurczuk opened this issue Apr 28, 2025 · 0 comments

Comments

@mkurczuk
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating code with the Spring generator using OpenAPI Generator (7.13.0), the x-pattern-message extension works correctly for single strings, but does not work for list items.

openapi-generator version

7.13.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Sample API
  version: 1.0.0
paths:
  /api/v1/endpoint:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SomeRequest'
      responses:
        '204':
          description: Success
components:
  schemas:
    SomeRequest:
      type: object
      description: Request
      properties:
        patternList:
          description: List of patterns
          type: array
          items:
            type: string
            pattern: '^[\w\W]*$'
            x-pattern-message: Custom message for list
        patternString:
            type: string
            description: Pattern string
            pattern: '^[\w\W]*$'
            x-pattern-message: Custom message for string
Generation Details
openapi-generator-cli generate -g spring -c api-config.json -i test-api.yaml

api-config.json:

{
  "interfaceOnly": true,
  "apiTests": false,
  "modelTests": false,
  "hideGenerationTimestamp": true,
  "useSpringBoot3": true,
  "useJakartaEe": true,
  "useTags": true,
  "useEnumCaseInsensitive": true
}
Steps to reproduce

The generated model class should assign the custom message for both patternString and each item in patternList.

Actual Behavior:

  • For patternString, the custom message is correctly applied:
  private @Nullable String patternString;

  @Pattern(regexp = "^[\\w\\W]*$", message="Custom message for string") 
  @Schema(name = "patternString", description = "Pattern string", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
  @JsonProperty("patternString")
  public String getPatternString() {
    return patternString;
  }
  • For patternList, the custom message is missing:
  @Valid
  private List<@Pattern(regexp = "^[\\w\\W]*$") String> patternList;

  @Schema(name = "patternList", description = "List of patterns", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
  @JsonProperty("patternList")
  public List<@Pattern(regexp = "^[\\w\\W]*$")String> getPatternList() {
    return patternList;
  }
Related issues/PRs
Suggest a fix

It would be ideal if the generated annotation for list items was like:

  @Valid
  private List<@Pattern(regexp = "^[\\w\\W]*$", message="Custom message for list") String> patternList;
 
  @Schema(name = "patternList", description = "List of patterns", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
  @JsonProperty("patternList")
  public List<@Pattern(regexp = "^[\\w\\W]*$", message="Custom message for list")String> getPatternList() {
    return patternList;
  }

instead of omitting the message part.

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

No branches or pull requests

1 participant