Open
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- 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
When using the generator for kotlin
with the kotlinx serialization method, integer enums will be correctly serialized from integer to kotlin integer, but will be incorrectly deserialized from kotlin integer to string
This:
@Serializable
enum class SomeCode(val value: kotlin.Int) {
@SerialName(value = "0")
_0(0)
}
Should be this:
@Serializable
enum class SomeCode(val value: kotlin.Int) {
@SerialName(value = 0)
_0(0),
}
openapi-generator version
Latest (7.12.0
)
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Demo
version: v1
components:
schemas:
Code:
type: integer
enum:
- 0
paths:
/do:
get:
summary: Do something
responses:
200:
description: Successful response
content:
application/json:
schema:
type: object
required:
- code
properties:
code:
$ref: '#/components/schemas/Code'
Generation Details
Generate with Docker command:
docker run --rm -v $(pwd):/local openapitools/openapi-generator-cli generate -i /local/Test.yml -g kotlin -o /local/out/kotlin
Steps to reproduce
Generate with Docker command:
docker run --rm -v $(pwd):/local openapitools/openapi-generator-cli generate -i /local/Test.yml -g kotlin -o /local/out/kotlin
Related issues/PRs
Suggest a fix
The bug seems to be caused by the following line:
@SerialName(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}})
Where double quotes are hard-coded
They should be conditionally added, whether it's a dataType
string or integer.
I'm not sure if we can do conditional checks like that is the mustaches syntax, let me know if we can, it would be a pleasure to create a PR