-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[BUG] [kotlin-server] double used in constraint annotation for integer types #23445
Copy link
Copy link
Open
Labels
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?
Description
When declaring a integer schema, and referencing it as property with addional validation annotations
the generated code attampts to insert doubles in place of integers / longs
This:
/**
*
* @param validatedInteger
*/
data class ValidatedObject(
@get:Min(value=1)
@get:Max(value=5000.0)
@get:JsonProperty("validatedInteger") val validatedInteger: kotlin.Int? = null
) {
}
Instead of this:
/**
*
* @param validatedInteger
*/
data class ValidatedObject(
@get:Min(value=1)
@get:Max(value=5000)
@get:JsonProperty("validatedInteger") val validatedInteger: kotlin.Int? = null
) {
}
##### openapi-generator version
7.21.0
##### OpenAPI declaration file content or url
```yaml
openapi: 3.1.2
info:
description: API
title: API
version: v0
servers: []
paths:
/example:
get:
operationId: get
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/ValidatedObject'
description: List of car models for a given make
components:
schemas:
validatedInteger:
type: integer
format: int32
description: Some Description
minimum: 1
ValidatedObject:
type: object
properties:
validatedInteger:
$ref: '#/components/schemas/validatedInteger'
maximum: 5000
Generation Details
I've been using the gradle plugin for this with following settings:
openApiGenerate {
generatorName.set("kotlin-spring")
inputSpec.set(rootProject.file("openapi.yaml").toString())
outputDir.set(generatedOpenApiCodeDir.map { it.asFile.toString() })
packageName.set("com.example")
configOptions.put("annotationLibrary", "none")
configOptions.put("basePackage", "com.example")
configOptions.put("configPackage", "com.example.config")
configOptions.put("documentationProvider", "none")
configOptions.put("gradleBuildFile", "false")
configOptions.put("includeHttpRequestContext", "true")
configOptions.put("interfaceOnly", "true")
configOptions.put("library", "spring-boot")
configOptions.put("requestMappingMode", "api_interface")
configOptions.put("useSpringBoot4", "true")
configOptions.put("useJackson3", "true")
}So in config based settings it should be
generatorName: kotlin-spring
outputDir: samples/server/petstore/kotlin-springboot-4
library: spring-boot
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
additionalProperties:
documentationProvider: none
annotationLibrary: none
basePackage: "com.example"
configPackage: "com.example.config"
gradleBuildFile: "false"
includeHttpRequestContext: "true"
useSpringBoot4: "true"
useJackson3: "true"
requestMappingMode: api_interface
interfaceOnly: "true"Steps to reproduce
- Create an integer or long schema, and reference it as a property adding
minimumormaximumannotations, - attempt to generate classes
- classes are unable to compile due to type mismatch on the annotation.
Related issues/PRs
Suggest a fix
The simplest fix would seem to be to use the DecimalMax and DecimalMin variants always, as it seems like they should be able to support integer types too.
But otherwise I'm not sure what makes it start interpreting the integer as a double.
Reactions are currently unavailable