OpenAPITools / OpenAPITools/openapi-generator

[BUG][Kotlin][Spring] Option `useSpringBuiltInValidation` is not implemented

Open Beginner friendly
#23,950 0 comments 0 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
  • 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
  1. Specify any parameter with pattern format (example of validated parameter)
  2. Use in Spring Boot 4 project
  3. Enable AOT processing in Spring Boot project
  4. Target Kotlin Spring server generator
  5. Specify useSpringBoot4 and useSpringBuiltInValidation
  6. Call with invalid parameter value.
  7. 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.