swagger-api / swagger-api/swagger-codegen

[Kotlin] Wrong array of objects code generation

Open
#9,263 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Kotlin class generation is broken for specific .yaml shown bellow, but works correctly for Swift4. An arrayOf is not object at all and does not exists.

Swagger-codegen version

2.4.2

Swagger declaration file content or url
"swagger": "2.0"
Activities:
    type: array
    items:
      $ref: '#/definitions/ActivityItem'

ActivityItem:
    type: object
    required:
      - date
      - water
      - rest
      - food
    properties:
      date:
        type: string
        format: date-time
      water:
        type: number
      rest:
        type: number
      activity:
        type: number
      food:
        type: number
Generates this corrupt kotlin file
import io.swagger.client.models.ActivityItem
import io.swagger.client.models.arrayOf

/**
 * 
 */
data class Activities () {}
Swift4 same file correct generation
import Foundation

public typealias Activities = [ActivityItem]
Command line used for kotlin generation

swagger-codegen generate -l kotlin -i swagger.api.yaml -c swagger-codegen.config.json -o my_directory

Command line used for swift4 generation

swagger-codegen generate -l swift4 -i swagger.api.yaml -c swagger-codegen.config.json -o my_directory

Suggest a fix/enhancement

your parser is missing test for array of objects but i am not quite sure if it should look like this typealias also for kotlin typealias Activities = Array<ActivityItem>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided swagger-codegen Kotlin command with the included Swagger YAML and inspect the Kotlin generation path that handles the Activities array schema. Compare the generated output with the Swift4 result and establish regression coverage; done means valid Kotlin represents Activities as an array of ActivityItem without the nonexistent arrayOf import.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.