Skip to content

[BUG][Kotlin] Nullable attribute is ignored if field is not required #11962

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

Open
5 of 6 tasks
ggajews opened this issue Mar 24, 2022 · 0 comments
Open
5 of 6 tasks

[BUG][Kotlin] Nullable attribute is ignored if field is not required #11962

ggajews opened this issue Mar 24, 2022 · 0 comments

Comments

@ggajews
Copy link

ggajews commented Mar 24, 2022

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 generating model with fields not required nullable attribute is ignored

openapi-generator version

5.3.0

OpenAPI declaration file content or url
components:
  schemas:
    Cat:
          type: object
          xml:
            name: cat
          properties:
            id:
              type: integer
              format: int64
              nullable: false
            name:
              type: boolean
              nullable: true
Generation Details
Steps to reproduce

Generate this class. Expected result:

data class Cat (

    @SerializedName("id")
    val id: kotlin.Long,

    @SerializedName("name")
    val name: kotlin.Boolean? = null

)

actual:

data class Cat (

    @SerializedName("id")
    val id: kotlin.Long? = null,

    @SerializedName("name")
    val name: kotlin.Boolean? = null

)
Related issues/PRs

#4530

Suggest a fix

Copy the solution from /data_class_req_var.mustache to data_class_opt_var.mustache

{{#isNullable}}?{{/isNullable}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}
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