Skip to content

[BUG][Kotlin] JsonSetter(nulls = Nulls.FAIL) generated even with openApiNullable = false #23976

@mfunda-cen59049

Description

@mfunda-cen59049

Bug Report Checklist

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

Even after setting <openApiNullable>false</openApiNullable> in the Kotlin generate-sources config options, the generated model classes contain annotation @field:JsonSetter(nulls = Nulls.FAIL) for non-required fields.

openapi-generator version

7.23.0

OpenAPI declaration file content or url
type: object
properties:
  id:
    type: string
Generation Details
                    <execution>
                        <id>KOTLIN</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${openapi.output}</inputSpec>
                            ...
                            <generatorName>kotlin-spring</generatorName>
                            <generateSupportingFiles>false</generateSupportingFiles>
                            <configOptions>
                                <useBeanValidation>false</useBeanValidation>
                                <useJackson3>true</useJackson3>
                                <useSpringBoot4>true</useSpringBoot4>
                                <enumPropertyNaming>original</enumPropertyNaming>
                                <useTags>true</useTags>
                                <openApiNullable>false</openApiNullable>
                            </configOptions>
                        </configuration>
                    </execution>
Steps to reproduce
  1. Setup a project with Kotlin OpenAPI generator with the provided configuration.
  2. Create a schema with non-required field not annotated as nullable: true
  3. Generate the Kotlin classes and observe that the generated class contains @field:JsonSetter(nulls = Nulls.FAIL) annotation.
Related issues/PRs

#23804

Suggest a fix

With the openApiNullable = false setting, the JsonSetter(nulls = Nulls.FAIL) annotation should not be included in the generated classes the same way it works for Java.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions