openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

spring generator validation annotations doesn't work

Open rajdippatel opened this issue 4 years ago • 2 comments

Bug Report Checklist

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

I am trying to generate spring code based on open-api spec version 3.0.1. When I run that project I noticed that sprin boot doesn't respect validation and it works like without validation.

openapi-generator version

5.2.1

OpenAPI declaration file content or url

https://gist.github.com/rajdippatel/1fa05a79f15bbcdd0b64c805973d9d13

Generation Details

openapi-generator-cli generate -g spring -i specs.yaml -o out/spring/openapi

Steps to reproduce
  • Generate spring code based on specs.yaml and above config
  • Once spring will be generated run code
  • You will see /auth/login will be executed even if required attributes are present
Related issues/PRs
  • None

  • Suggest a fix
  • Enable performBeanValidation or useBeanValidation. But if I enable it I can see it injects "hibernate-validation" package and it fails to build project.

  • If I add hibernate-validation in pom dependency, project compiles but still validation doesn't work

rajdippatel avatar Sep 26 '21 13:09 rajdippatel

Hi Rajdip,

I tried replicating the issue and it seems the javax.validation.constraints.* is not effective in the generated code. Did you try generating any other validation and see if it works?

zhuangheihei avatar Nov 28 '21 04:11 zhuangheihei

I had a similar issue. This fixed it

oluwoleeo avatar May 12 '24 10:05 oluwoleeo