OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] HV000271: Using `@Valid` on a container (java.util.List) is deprecated

Open
#23,614 10 comments 31 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
Description

Hibernate 9.1 emits warnings about the deprecated use of @Valid on containers:
https://docs.hibernate.org/validator/9.1/whats-new/en-US/html_single/#_deprecating_the_use_of_valid_at_the_container_level

2026-04-24 13:49:27,838 WARN  [org.hibernate.validator.internal.metadata.aggregated.CascadingMetaDataBuilder] (main) HV000271: Using `@Valid` on a container (java.util.List) is deprecated. You should apply the annotation on the type argument(s). Affected element: data
2026-04-24 13:49:27,838 WARN  [org.hibernate.validator.internal.metadata.aggregated.CascadingMetaDataBuilder] (main) HV000271: Using `@Valid` on a container (java.util.List) is deprecated. You should apply the annotation on the type argument(s). Affected element: ItemList#getData()
openapi-generator version

7.21.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Sample API
  version: 1.0.0

paths:
  /items:
    get:
      summary: Get all items
      operationId: listItems
      responses:
        '200':
          description: A list of items
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ItemList'

components:
  schemas:
    ItemList:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/Item'
        total:
          type: integer
    Item:
      type: object
      properties:
        id:
          type: integer
          example: 1
        name:
          type: string
Generation Details

java -jar openapi-generator-cli.jar generate -g jaxrs-spec -i openapi.yaml -p apiPackage=com.example.api -p modelPackage=com.example.model -p useJakartaEe=true

  private @Valid List<@Valid Item> data = new ArrayList<>();

  @ApiModelProperty(value = "")
  @JsonProperty("data")
  @Valid public List<@Valid Item> getData() {
    return data;
  }

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

Reproduce the issue with the supplied OpenAPI declaration and the jaxrs-spec generation command, then trace the generated ItemList annotations to the responsible generator templates or code. Done means the generated Java output no longer places @Valid on the List container while retaining valid type-argument validation, with the warning eliminated.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.