OpenAPITools / OpenAPITools/openapi-generator
[BUG][Kotlin][Spring] Option `useSpringBuiltInValidation` is not implemented
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
Java Spring generator introduced option useSpringBuiltInValidation to address new Spring Framework 6.1+ controller argument validation mechanism.
This option is also present in Kotlin Spring generator documentation, however it seems like it has never been implemented and has no effect.
When used in Spring Framework 6.1+ project (e.g. Spring Boot 4 uses Spring Framework 7), and have AOT processing enabled, this leads to legacy aspect to handle parameter validation.
This mechanism throws different exception, that is no longer handled, and results in HTTP response 500 Internal Server Error instead of expected 400 Bad Request.
openapi-generator version
Found in v7.20.0 - v7.22.0
OpenAPI declaration file content or url
any scheme that emits any Spring validation annotations, e.g.:
paths:
/user/{id}:
get:
parameters:
- name: id
in: path
description: User ID (8 digits)
required: true
schema:
type: string
pattern: '^\d{8}$'
Generation Details
- Kotlin 2.3.21
- Gradle 9.5.1
- openapi-generator gradle plugin (
org.openapi.generator) 7.22.0 - plugin options:
configOptions.put("useSpringBoot4", "true") configOptions.put("useSpringBuiltInValidation", "true") configOptions.put("interfaceOnly", "true")
Steps to reproduce
- Specify any parameter with
patternformat (example of validated parameter) - Use in Spring Boot 4 project
- Enable AOT processing in Spring Boot project
- Target Kotlin Spring server generator
- Specify
useSpringBoot4anduseSpringBuiltInValidation - Call with invalid parameter value.
- Observe incorrect HTTP response code 500.
Related issues/PRs
#22859, #23803, #23609
Suggest a fix
Implement the same behavior as used in Java Spring generator:
When the option useSpringBuiltInValidation is specified, don't render the @Validated annotation on api class/interface.
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 at the Kotlin Spring generator entry point and compare its handling of useSpringBuiltInValidation with the Java Spring generator behavior referenced in the issue. Generate a Kotlin Spring server from a spec containing a validated parameter, using useSpringBoot4 and the option; done means the option changes the generated validation annotations and invalid input no longer produces the described 500 response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, spring
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100