Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
{{/isContainer}}
{{/vars}}
{{#vendorExtensions.x-java-no-args-constructor}}
{{^openApiNullable}}

public {{classname}}() {
super();
}
{{/vendorExtensions.x-java-no-args-constructor}}
public {{classname}}() {
super();
}
{{/openApiNullable}}
{{/vendorExtensions.x-java-no-args-constructor}}
{{^lombok.Data}}
{{^lombok.RequiredArgsConstructor}}
{{#generatedConstructorWithRequiredArgs}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2877,11 +2877,12 @@ public void shouldUseTheSameTagNameForTheInterfaceAndTheMethod_issue11570() thro
}

@Test
public void shouldGenerateConstructorWithOnlyRequiredParameters() throws IOException {
public void shouldGenerateConstructorWithOnlyRequiredParametersAndNoArgConstructorWithOpenApiNullable() throws IOException {
final Map<String, File> output = generateFromContract(
"src/test/resources/3_0/spring/issue_9789.yml",
SPRING_BOOT,
Map.of(GENERATE_CONSTRUCTOR_WITH_ALL_ARGS, "false")
Map.of(GENERATE_CONSTRUCTOR_WITH_ALL_ARGS, "false",
OPENAPI_NULLABLE, "false")
);

JavaFileAssert.assertThat(output.get("ObjectWithNoRequiredParameter.java")).hasNoConstructor("String");
Expand All @@ -2899,6 +2900,30 @@ public void shouldGenerateConstructorWithOnlyRequiredParameters() throws IOExcep
.bodyContainsLines("super(param2, param3)", "this.param6 = param6");
}

@Test
public void shouldGenerateConstructorWithOnlyRequiredParametersWhenNoOpenapiNullable() throws IOException {
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 30, 2025

Choose a reason for hiding this comment

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

P2: Test method name is misleading: shouldGenerateConstructorWithOnlyRequiredParametersWhenNoOpenapiNullable implies OPENAPI_NULLABLE is disabled, but the test sets OPENAPI_NULLABLE, "true". Consider renaming to shouldGenerateConstructorWithOnlyRequiredParametersWhenOpenapiNullableEnabled or similar to accurately reflect the test configuration.

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

<comment>Test method name is misleading: `shouldGenerateConstructorWithOnlyRequiredParametersWhenNoOpenapiNullable` implies `OPENAPI_NULLABLE` is disabled, but the test sets `OPENAPI_NULLABLE, &quot;true&quot;`. Consider renaming to `shouldGenerateConstructorWithOnlyRequiredParametersWhenOpenapiNullableEnabled` or similar to accurately reflect the test configuration.</comment>

<file context>
@@ -2899,6 +2900,30 @@ public void shouldGenerateConstructorWithOnlyRequiredParameters() throws IOExcep
     }
 
+    @Test
+    public void shouldGenerateConstructorWithOnlyRequiredParametersWhenNoOpenapiNullable() throws IOException {
+        final Map&lt;String, File&gt; output = generateFromContract(
+                &quot;src/test/resources/3_0/spring/issue_9789.yml&quot;,
</file context>
Fix with Cubic

final Map<String, File> output = generateFromContract(
"src/test/resources/3_0/spring/issue_9789.yml",
SPRING_BOOT,
Map.of(GENERATE_CONSTRUCTOR_WITH_ALL_ARGS, "false",
OPENAPI_NULLABLE, "true")
);

JavaFileAssert.assertThat(output.get("ObjectWithNoRequiredParameter.java")).hasNoConstructor("String");

JavaFileAssert.assertThat(output.get("ObjectWithRequiredParameter.java")).hasNoConstructor();
JavaFileAssert.assertThat(output.get("ObjectWithRequiredParameter.java")).assertConstructor("String", "String")
.hasParameter("param2").toConstructor()
.hasParameter("param3");

JavaFileAssert.assertThat(output.get("ObjectWithInheritedRequiredParameter.java")).hasNoConstructor();
JavaFileAssert.assertThat(output.get("ObjectWithInheritedRequiredParameter.java")).assertConstructor("Integer", "String", "String")
.hasParameter("param2").toConstructor()
.hasParameter("param3").toConstructor()
.hasParameter("param6").toConstructor()
.bodyContainsLines("super(param2, param3)", "this.param6 = param6");
}

private Map<String, File> generateFromContract(String url, String library) throws IOException {
return generateFromContract(url, library, new HashMap<>());
}
Expand Down Expand Up @@ -4958,6 +4983,7 @@ public void testLombokAnnotations() throws IOException {
.hasNoMethod("setName")
;
additionalProperties.put(AbstractJavaCodegen.ADDITIONAL_MODEL_TYPE_ANNOTATIONS, "@lombok.ToString");
additionalProperties.put(AbstractJavaCodegen.OPENAPI_NULLABLE, "false");
output = generateFromContract("src/test/resources/3_0/petstore.yaml", SPRING_BOOT, additionalProperties);
JavaFileAssert.assertThat(output.get("Pet.java"))
.assertConstructor().toFileAssert()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public class Pet {
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate dateOfBirth = LocalDate.parse("2021-01-01");

public Pet() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ public static StatusEnum fromValue(String value) {

private @Nullable StatusEnum status;

public Pet() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ public static StatusEnum fromValue(String value) {
@Deprecated
private @Nullable StatusEnum status;

public Pet() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ public static StatusEnum fromValue(String value) {

private @Nullable StatusEnum status;

public Pet() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ public static StatusEnum fromValue(String value) {
@Deprecated
private @Nullable StatusEnum status;

public Pet() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public class AnimalDto {

private String color = "red";

public AnimalDto() {
super();
}

public AnimalDto className(String className) {
this.className = className;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ public static KindEnum fromValue(String value) {

private @Nullable KindEnum kind;

public BigCatDto() {
super();
}

public BigCatDto kind(@Nullable KindEnum kind) {
this.kind = kind;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public class CatDto extends AnimalDto {

private @Nullable Boolean declawed;

public CatDto() {
super();
}

public CatDto declawed(@Nullable Boolean declawed) {
this.declawed = declawed;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public class CategoryDto {

private String name = "default-name";

public CategoryDto() {
super();
}

public CategoryDto id(@Nullable Long id) {
this.id = id;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public class ContainerDefaultValueDto {

private JsonNullable<List<String>> nullableArrayWithDefault = JsonNullable.<List<String>>undefined();

public ContainerDefaultValueDto() {
super();
}

public ContainerDefaultValueDto nullableArray(List<String> nullableArray) {
this.nullableArray = JsonNullable.of(nullableArray);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public class DogDto extends AnimalDto {

private @Nullable String breed;

public DogDto() {
super();
}

public DogDto breed(@Nullable String breed) {
this.breed = breed;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ public static EnumNumberEnum fromValue(Double value) {

private @Nullable OuterEnumDto outerEnum;

public EnumTestDto() {
super();
}

public EnumTestDto enumString(@Nullable EnumStringEnum enumString) {
this.enumString = enumString;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public class FormatTestDto {

private @Nullable BigDecimal bigDecimal;

public FormatTestDto() {
super();
}

public FormatTestDto integer(@Nullable Integer integer) {
this.integer = integer;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public class NameDto {

private @Nullable Integer _123number;

public NameDto() {
super();
}

public NameDto name(Integer name) {
this.name = name;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ public static StatusEnum fromValue(String value) {
@Deprecated
private @Nullable StatusEnum status;

public PetDto() {
super();
}

public PetDto id(@Nullable Long id) {
this.id = id;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public class TypeHolderDefaultDto {

private List<Integer> arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3));

public TypeHolderDefaultDto() {
super();
}

public TypeHolderDefaultDto stringItem(String stringItem) {
this.stringItem = stringItem;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public class TypeHolderExampleDto {

private List<Integer> arrayItem = new ArrayList<>();

public TypeHolderExampleDto() {
super();
}

public TypeHolderExampleDto stringItem(String stringItem) {
this.stringItem = stringItem;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public class Animal {

private String color = "red";

public Animal() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ public static KindEnum fromValue(String value) {

private @Nullable KindEnum kind;

public BigCat() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public class Cat extends Animal {

private @Nullable Boolean declawed;

public Cat() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public class Category {

private String name = "default-name";

public Category() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public class ContainerDefaultValue {

private JsonNullable<List<String>> nullableArrayWithDefault = JsonNullable.<List<String>>undefined();

public ContainerDefaultValue() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public class Dog extends Animal {

private @Nullable String breed;

public Dog() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ public static EnumNumberEnum fromValue(Double value) {

private @Nullable OuterEnum outerEnum;

public EnumTest() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public class FormatTest {

private @Nullable BigDecimal bigDecimal;

public FormatTest() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public class Name {

private @Nullable Integer _123number;

public Name() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ public static StatusEnum fromValue(String value) {
@Deprecated
private @Nullable StatusEnum status;

public Pet() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public class TypeHolderDefault {

private List<Integer> arrayItem = new ArrayList<>(Arrays.asList(0, 1, 2, 3));

public TypeHolderDefault() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public class TypeHolderExample {

private List<Integer> arrayItem = new ArrayList<>();

public TypeHolderExample() {
super();
}

/**
* Constructor with only required parameters
*/
Expand Down
Loading
Loading