-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
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
/exampleendpoint 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
@NotNulland@Patternvalidation 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.