Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
public static final String GRADLE_BUILD_FILE = "gradleBuildFile";
public static final String SERVICE_INTERFACE = "serviceInterface";
public static final String SERVICE_IMPLEMENTATION = "serviceImplementation";
public static final String OMIT_DEFAULT_NULL_VALUES = "omitDefaultNullValues";
public static final String SKIP_DEFAULT_INTERFACE = "skipDefaultInterface";
public static final String SKIP_DEFAULT_API_INTERFACE = "skipDefaultApiInterface";
public static final String SKIP_DEFAULT_DELEGATE_INTERFACE = "skipDefaultDelegateInterface";
Expand Down Expand Up @@ -141,6 +142,7 @@ public String getDescription() {
private String title = "OpenAPI Kotlin Spring";
private boolean useBeanValidation = true;
@Setter private boolean skipDefaultInterface = false;
@Setter private boolean omitDefaultNullValues = false;
@Setter private boolean skipDefaultApiInterface = false;
@Setter private boolean skipDefaultDelegateInterface = false;
@Setter private boolean exceptionHandler = true;
Expand Down Expand Up @@ -243,6 +245,7 @@ public KotlinSpringServerCodegen() {
"interfaces. If this is set to true service interfaces will also be generated", serviceImplementation);
addSwitch(USE_BEANVALIDATION, "Use BeanValidation API annotations to validate data types", useBeanValidation);
addSwitch(SKIP_DEFAULT_INTERFACE, "Whether to skip generation of default implementations for interfaces (Api interfaces or Delegate interfaces depending on the delegatePattern option)", skipDefaultInterface);
addSwitch(OMIT_DEFAULT_NULL_VALUES, "Whether to skip default values for data classes", omitDefaultNullValues);
addSwitch(REACTIVE, "use coroutines for reactive behavior", reactive);
addSwitch(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.", interfaceOnly);
addSwitch(USE_FEIGN_CLIENT_URL, "Whether to generate Feign client with url parameter.", useFeignClientUrl);
Expand Down Expand Up @@ -586,6 +589,11 @@ public void processOpts() {
}
writePropertyBack(SKIP_DEFAULT_INTERFACE, skipDefaultInterface);

if (additionalProperties.containsKey(OMIT_DEFAULT_NULL_VALUES)) {
this.setOmitDefaultNullValues(convertPropertyToBoolean(OMIT_DEFAULT_NULL_VALUES));
}
Comment on lines +592 to +594
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Public option key rename removed backward compatibility: legacy ommitDefaultNullValues is no longer accepted, breaking existing generator configurations.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java, line 592:

<comment>Public option key rename removed backward compatibility: legacy `ommitDefaultNullValues` is no longer accepted, breaking existing generator configurations.</comment>

<file context>
@@ -589,10 +589,10 @@ public void processOpts() {
 
-        if (additionalProperties.containsKey(OMMIT_DEFAULT_NULL_VALUES)) {
-            this.setOmmitDefaultNullValues(convertPropertyToBoolean(OMMIT_DEFAULT_NULL_VALUES));
+        if (additionalProperties.containsKey(OMIT_DEFAULT_NULL_VALUES)) {
+            this.setOmitDefaultNullValues(convertPropertyToBoolean(OMIT_DEFAULT_NULL_VALUES));
         }
</file context>
Suggested change
if (additionalProperties.containsKey(OMIT_DEFAULT_NULL_VALUES)) {
this.setOmitDefaultNullValues(convertPropertyToBoolean(OMIT_DEFAULT_NULL_VALUES));
}
if (additionalProperties.containsKey(OMIT_DEFAULT_NULL_VALUES) || additionalProperties.containsKey("ommitDefaultNullValues")) {
String omitDefaultNullValuesKey = additionalProperties.containsKey(OMIT_DEFAULT_NULL_VALUES)
? OMIT_DEFAULT_NULL_VALUES
: "ommitDefaultNullValues";
this.setOmitDefaultNullValues(convertPropertyToBoolean(omitDefaultNullValuesKey));
}
Fix with Cubic

writePropertyBack(OMIT_DEFAULT_NULL_VALUES, omitDefaultNullValues);

if (additionalProperties.containsKey(REACTIVE)) {
if (SPRING_CLOUD_LIBRARY.equals(library)) {
throw new IllegalArgumentException("Currently, reactive option doesn't supported by Spring Cloud");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
@ApiModelProperty({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}{{#deprecated}}
@Deprecated(message = ""){{/deprecated}}{{#vendorExtensions.x-field-extra-annotation}}
{{{.}}}{{/vendorExtensions.x-field-extra-annotation}}
@get:JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInPascalCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{^defaultValue}}null{{/defaultValue}}{{#defaultValue}}{{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}
@get:JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInPascalCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}?{{^defaultValue}}{{^omitDefaultNullValues}} = null{{/omitDefaultNullValues}}{{/defaultValue}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}
Original file line number Diff line number Diff line change
Expand Up @@ -4663,6 +4663,25 @@ public void testSealedResponseInterfacesVoidResponse() throws IOException {
Assert.assertTrue(petContent.contains(") : CreatePetResponse {") || petContent.contains(") : CreatePetResponse"),
"Pet should implement CreatePetResponse");
}
}

@Test
public void testOmitDefaultNullValues() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();

final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(OMIT_DEFAULT_NULL_VALUES, true);

new DefaultGenerator().opts(new ClientOptInput()
.openAPI(TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"))
.config(codegen))
.generate();

// Pet model has optional properties that would normally get "= null" defaults
assertFileNotContains(
Paths.get(output + "/src/main/kotlin/org/openapitools/model/Pet.kt"),
"= null"
);
}
}