Skip to content

[REQ] [Kotlin] Default optional parameters to null #24958

Description

@rupert-jung-mw

Is your feature request related to a problem? Please describe.

While non-required properties of generatered DTOs are defaulted to null this is not true to non-required parameters.

Example:

Image

Describe the solution you'd like

= null added to optional parameters

Image

Additional context

Generator: kotlin-server
Library: jaxrs-spec

Options:

<configOptions>
    <library>jaxrs-spec</library>
    <!-- Required for Quarkus 3.x (Jakarta EE 10): uses jakarta.* instead of javax.* imports -->
    <useJakartaEe>true</useJakartaEe>
    <useSwaggerAnnotations>false</useSwaggerAnnotations>
    <sourceFolder>src/main/java</sourceFolder>
    <dateLibrary>java8</dateLibrary>
    <serializationLibrary>jackson</serializationLibrary>
    <useBeanValidation>true</useBeanValidation>
    <openApiNullable>false</openApiNullable>
    <sortModelPropertiesByRequiredFlag>true</sortModelPropertiesByRequiredFlag>
    <sortParamsByRequiredFlag>true</sortParamsByRequiredFlag>
    <interfaceOnly>true</interfaceOnly>
</configOptions>

I got it to work by adding a custom Mustache template querParams.mustache to my template directory:

{{#isQueryParam}}@QueryParam("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue({{#lambda.doublequote}}{{{.}}}{{/lambda.doublequote}}){{/defaultValue}}{{/isContainer}} {{paramName}}: {{{dataType}}}{{#isNullable}}?{{/isNullable}}{{^isNullable}}{{^defaultValue}}{{^required}}? = null{{/required}}{{/defaultValue}}{{/isNullable}}{{/isQueryParam}}

(Code above has been generated by Claude Sonnet 5)

Maybe this could be validated by some experienced dev and included in one of the next releases :)

Thank you!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions