Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #13506
Closed
Open
Issue created Sep 23, 2022 by Administrator@rootContributor4 of 4 checklist items completed4/4 checklist items

[BUG] [Kotlin] Wrong default value is generated for non-integer numbers

Created by: aghajani

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • [ x 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

If the model has fields with

  • type number and format float or double
  • type integer and format int64 then the generated models for kotlin will have syntax errors. Samples below
openapi-generator version

6.1.1

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: 'Issue X default value number with format'
  version: latest
paths:
  '/':
    get:
      operationId: operation
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ModelWithPropertyHavingDefault'
components:
  schemas:
    ModelWithPropertyHavingDefault:
      properties:
        propertyInt:
          type: integer
          default: 0
          format: int32
        propertyLong:
          type: integer
          default: 0
          format: int64
        propertyFloat1:
          type: number
          default: 0
          format: float
        propertyFloat2:
          type: number
          default: 0.0
          format: float
        propertyFloat3:
          type: number
          default: 0.01
          format: float
        propertyDouble1:
          type: number
          default: 0
          format: double
        propertyDouble2:
          type: number
          default: 0.0
          format: double
        propertyDouble3:
          type: number
          default: 0.01
          format: double
Generation Details
Steps to reproduce

Try to generate kotlin (client) models, and the output will have:

    @SerializedName("propertyLong")
    val propertyLong: kotlin.Long? = 0,

    @SerializedName("propertyFloat1")
    val propertyFloat1: kotlin.Float? = 0,

    @SerializedName("propertyFloat2")
    val propertyFloat2: kotlin.Float? = 0,

    @SerializedName("propertyFloat3")
    val propertyFloat3: kotlin.Float? = 0.01,

    @SerializedName("propertyDouble1")
    val propertyDouble1: kotlin.Double? = 0,

    @SerializedName("propertyDouble2")
    val propertyDouble2: kotlin.Double? = 0,

which is clearly invalid in Kotlin.
Expected output:

    @SerializedName("propertyInt")
    val propertyInt: kotlin.Int? = 0,

    @SerializedName("propertyLong")
    val propertyLong: kotlin.Long? = 0L,

    @SerializedName("propertyFloat1")
    val propertyFloat1: kotlin.Float? = 0f,

    @SerializedName("propertyFloat2")
    val propertyFloat2: kotlin.Float? = 0.0f,

    @SerializedName("propertyFloat3")
    val propertyFloat3: kotlin.Float? = 0.01f,

    @SerializedName("propertyDouble1")
    val propertyDouble1: kotlin.Double? = 0.0,

    @SerializedName("propertyDouble2")
    val propertyDouble2: kotlin.Double? = 0.0,

    @SerializedName("propertyDouble3")
    val propertyDouble3: kotlin.Double? = 0.01
Suggest a fix

The fix should consider the type and shape the output default value (better to be in abstract Kotlin generator)

Assignee
Assign to
Time tracking