Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Kotlin-generator uses immutable empty initializers when using modelMutable #21004

Open
5 of 6 tasks
mkoertgen opened this issue Apr 1, 2025 · 0 comments
Open
5 of 6 tasks

Comments

@mkoertgen
Copy link

mkoertgen commented Apr 1, 2025

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
openapi-generator version

7.12.0

OpenAPI declaration file content or url

Image

Generation Details

Using the latest gradle-plugin, the kotlin-client-generator and mutable models

Steps to reproduce

Server: Simple Spring Boot WebMvc app using SpringDoc. Having a Response object like

@Schema(
            description = "Membership roles",
            example = """["ADMIN", "USER"]""",
            defaultValue = "[]"
        )
        @JsonView(ApiView.Get::class)
        val roles: Set<String> = emptySet(),

generates a schema like

  "roles": {
      "uniqueItems": true,
      "type": "array",
      "description": "Membership roles",
      "example": ["ADMIN", "USER_ADMIN"],
      "items": {
          "type": "string",
          "description": "Membership roles",
          "example": "[\"ADMIN\",\"USER\"]",
          "default": "[]"
      },
      "default": []
  },

Client: Using this schema with the kotlin-client-generator together with modelMutable=true will correctly use a MutableSet yet the defaultValue-initializer will still point to an immutable setOf()

    /* Membership roles */
    @get:JsonProperty("roles")
    var roles: kotlin.collections.MutableSet<kotlin.String>? = setOf(),
Related issues/PRs

The mutableModel-features has been addressed in #11088

Suggest a fix

As a workaround, one can skip the default-Value annotation and agree on not skipping null/empty-values in json-serialization between server and client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant