Skip to content

[BUG][Kotlin-Spring] Query Parameter Bean Validation missing since 7.13.0 #21238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 of 6 tasks
jothepro opened this issue May 7, 2025 · 0 comments
Closed
5 of 6 tasks

Comments

@jothepro
Copy link

jothepro commented May 7, 2025

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

In 7.13.0 the bean validation in the kotlin-spring generator is missing. Apparently it was removed in this PR: https://github.com/OpenAPITools/openapi-generator/pull/20885/files#diff-31eb66768f4412e178af87d063b704a1e3a3ef250e1a69af791ec24298cea6c7

I could not find any explanation on why it was removed in the PR or the Release notes for 7.13.0.

openapi-generator version

This is a regression since 7.13.0

OpenAPI declaration file content or url

Example spec that defines a regex pattern for a query parameter:

openapi: 3.0.3
info:
  title: Sample API
  version: 1.0.0
  description: A small OpenAPI spec with one endpoint and a query parameter.
paths:
  /example:
    get:
      parameters:
        - name: queryParam
          in: query
          required: true
          schema:
            type: string
            pattern: '^[a-zA-Z0-9_-]{3,10}$'
      responses:
        '200':
          description: Successful response
Generation Details

This was executed in order to generate the code:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate \
    -i /local/spec.yaml \
    -g kotlin-spring \
    -o /local/out/kotlin-spring

According to this documentation useBeanValidation is enabled by default. No special configurations where given to the generator.

Steps to reproduce
  • In v7.12.0 the kotlin-spring generator produced the following output for the /example endpoint in the openapi-spec provided above:
        @RequestMapping(
            method = [RequestMethod.GET],
            value = ["/example"]
        )
        fun exampleGet(@NotNull @Pattern(regexp="^[a-zA-Z0-9_-]{3,10}$") @Parameter(description = "", required = true) @Valid @RequestParam(value = "queryParam", required = true) queryParam: kotlin.String): ResponseEntity<Unit> {
            return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
        }
  • Running the same generator on v7.13.0 or latest results in the following. The output misses the @NotNull and @Pattern validation annotations, which is unexpected because no such regression was documented in the release:
        @RequestMapping(
            method = [RequestMethod.GET],
            value = ["/example"]
        )
        fun exampleGet( @RequestParam(value = "queryParam", required = true) queryParam: kotlin.String): ResponseEntity<Unit> {
            return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
        }

The bean validation is now missing. This is also reflected in these adjustments to the testing in the Misk Kotlin Generator PR.

Related issues/PRs
Suggest a fix

I suggest to undo the changes from https://github.com/OpenAPITools/openapi-generator/pull/20885/files#diff-31eb66768f4412e178af87d063b704a1e3a3ef250e1a69af791ec24298cea6c7 that introduced the regression.

@jothepro jothepro changed the title [BUG][Kotlin-Spring] Bean Validation missing since 7.13.0 [BUG][Kotlin-Spring] Query Parameter Bean Validation missing since 7.13.0 May 7, 2025
pstorch added a commit to pstorch/openapi-generator that referenced this issue May 9, 2025
pstorch added a commit to pstorch/openapi-generator that referenced this issue May 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant