Bug Report Checklist
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
minimum or maximum annotations,
- 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.
Bug Report Checklist
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:
Instead of this:
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
Steps to reproduce
minimumormaximumannotations,Related issues/PRs
Suggest a fix
The simplest fix would seem to be to use the
DecimalMaxandDecimalMinvariants 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.