OpenAPITools / OpenAPITools/openapi-generator

[Bug] [Spring] Invalid @Valid for List body parameter

Open
#24,752 1 comment 1 reaction 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
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

A warning is logged for an endpoint that takes a list of items as the request body:

HV000271: Using @Valid on a container (java.util.List) is deprecated. You should apply the annotation on the type argument(s).

The endpoint works fine but may not do so in the future.

openapi-generator version

7.24.0

OpenAPI declaration file content or url

https://github.com/keesvandaalen/openapi-generator-demo/blob/main/api.yaml

Generation Details

https://github.com/keesvandaalen/openapi-generator-demo/blob/b38efb8270229f2f760dc4dae505e53d7420d1fa/pom.xml#L56

Steps to reproduce
  • Checkout https://github.com/keesvandaalen/openapi-generator-demo/tree/main
  • Run mvn spring-boot:run
  • Call the endpoint: curl -X POST -H 'Content-Type: application/json' -d '[1,2,3]' http://localhost:8080/api/v1/demo
  • Inspect the logs to see this warning: HV000271: Using @Valid on a container (java.util.List) is deprecated. You should apply the annotation on the type argument(s). Affected element: ApiApi#apiV1DemoPost(List)
Related issues/PRs

None

Suggest a fix

Uncomment templateDirectory and do the steps to reproduce again.
Now there is no warning.

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 demo's api.yaml and pom.xml, then inspect the Spring generator's templateDirectory and the generated ApiApi#apiV1DemoPost(List) signature. Reproduce the warning with the provided Maven and curl commands; done means the generated endpoint no longer applies @Valid directly to the List container and the warning is absent.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.