[REQ] [Kotlin] Default optional parameters to null

Author: rupert-jung-mwCreated Sep 17, 2026Updated Sep 17, 2026
LabelsEnhancement: Feature

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:

xml
<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!

Source: OpenAPITools/openapi-generator