OpenAPITools / OpenAPITools/openapi-generator

[BUG] kotlin-spring will generate array of enum to only enum object when field is marked required

Open
#12,567 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

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 we are trying to generate a List of Enums as one of our object's field, we found that it will only generate it as Enum itself, interesting part is if I remove the field from required, it will be wrapped by List but with ?.

All works well for spring, so it should be a bug of kotlin-spring.

openapi-generator version

bug exists in latest as well (6.0.0)

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Test
  description: test
  version: '1.0.0'
servers:
  - url: http://localhost/v1/test
paths:
  /test:
    get:
      parameters:
        - name: "id"
          in: query
          description: id
          required: true
          schema:
            type: integer
            format: int64
      responses:
        200:
          description: reponse
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Response'

components:
  schemas:
    Response:
      type: object
      properties:
        flags:
          type: array
          items:
            type: string
            enum:
              - Value1
              - Value2
      required:
        - flags
Generation Details
/**
 * 
 * @param flags 
 */
data class Response(

        @field:NotNull 
        @JsonProperty("flags") val flags: Response.Flags
) {

    /**
    * 
    * Values: vaule1,vaule2
    */
    enum class Flags(val value: kotlin.String) {

        @JsonProperty("Vaule1") vaule1("Vaule1"),
        @JsonProperty("Vaule2") vaule2("Vaule2")
    }

}
Steps to reproduce

just generate

Suggest a fix

spring doesn't have this issue (java)

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

Start by running the kotlin-spring generator with the OpenAPI declaration in the issue, comparing the required and optional flags cases with the spring output. Trace the kotlin-spring generation entry point and verify that the required array-of-enum field is generated as a non-null list rather than a single enum; the generated Response model should match the schema.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.