OpenAPITools / OpenAPITools/openapi-generator
[Bug] [Spring] Invalid @Valid for List body parameter
Nobody has claimed this yet.
- 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
@Validon 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
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
@Validon 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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