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 @@ -269,7 +269,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}

{{^lombok.Setter}}
{{! begin feature: fluent setter methods for inherited properties }}
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
public {{classname}} {{name}}({{>nullableArgument_chainSetter}} {{name}}) {
super.{{name}}({{name}});
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8415,6 +8415,37 @@ public void testJspecify_useOptional(String library, int springBootVersion, bool
}
}

@Test(dataProvider = "jspecifyLibraries")
public void testJspecify_inheritedFluentSettersKeepNullable(String library, int springBootVersion) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: This regression test only covers the useOptional=false path. The PR changes inherited setters to use nullableArgument_chainSetter, which has separate useOptional / optionalAcceptNullable branches, but no test case asserts those inherited setters. Add a case with useOptional enabled (and optionalAcceptNullable on and off) to lock in the intended signatures.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java, line 8419:

<comment>This regression test only covers the `useOptional=false` path. The PR changes inherited setters to use `nullableArgument_chainSetter`, which has separate `useOptional` / `optionalAcceptNullable` branches, but no test case asserts those inherited setters. Add a case with `useOptional` enabled (and `optionalAcceptNullable` on and off) to lock in the intended signatures.</comment>

<file context>
@@ -8415,6 +8415,37 @@ public void testJspecify_useOptional(String library, int springBootVersion, bool
     }
 
+    @Test(dataProvider = "jspecifyLibraries")
+    public void testJspecify_inheritedFluentSettersKeepNullable(String library, int springBootVersion) throws IOException {
+        // https://github.com/OpenAPITools/openapi-generator/issues/25831
+        String springVersionProperty = springBootVersion == 4? USE_SPRING_BOOT4: USE_SPRING_BOOT3;
</file context>

// https://github.com/OpenAPITools/openapi-generator/issues/25831
String springVersionProperty = springBootVersion == 4? USE_SPRING_BOOT4: USE_SPRING_BOOT3;
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/jspecify-allof-inherited-setters.yaml", library,
Map.of(USE_JSPECIFY, true,
SpringCodegen.OPENAPI_NULLABLE, false,
INTERFACE_ONLY, true,
springVersionProperty, springBootVersion > 2,
USE_JAKARTA_EE, springBootVersion > 2
),
codegenConfigurator ->
codegenConfigurator
.addTypeMapping("OffsetDateTime", "java.time.Instant"));

JavaFileAssert.assertThat(files.get("Base.java"))
.fileContains(
"public Base kind(String kind) {",
"public Base description(@Nullable String description) {",
"public Base createdAt(java.time.@Nullable Instant createdAt) {");
JavaFileAssert.assertThat(files.get("Child.java"))
.assertTypeAnnotations().doesImportAnnotation("org.jspecify.annotations.Nullable").toType()
.fileContains(
"public Child kind(String kind) {",
"public Child description(@Nullable String description) {",
"public Child createdAt(java.time.@Nullable Instant createdAt) {")
.fileDoesNotContain(
"public Child description(String description) {",
"public Child createdAt(java.time.Instant createdAt) {");
}

// -------------------------------------------------------------------------
// autoXSpringPaginated tests
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: 3.0.3
info:
title: jspecify inherited fluent setters
version: 1.0.0
paths: {}
components:
schemas:
Base:
type: object
required:
- kind
properties:
kind:
type: string
description:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: The fixture has no required property that is also nullable, so the regression test never covers that case. Add a nullable: true required property to Base and assert its inherited Child setter keeps @Nullable.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/test/resources/3_0/java/jspecify-allof-inherited-setters.yaml, line 15:

<comment>The fixture has no required property that is also nullable, so the regression test never covers that case. Add a `nullable: true` required property to `Base` and assert its inherited `Child` setter keeps `@Nullable`.</comment>

<file context>
@@ -0,0 +1,29 @@
+      properties:
+        kind:
+          type: string
+        description:
+          type: string
+          nullable: true
</file context>

type: string
nullable: true
createdAt:
type: string
format: date-time
discriminator:
propertyName: kind
Child:
allOf:
- $ref: '#/components/schemas/Base'
- type: object
properties:
extra:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void setKind(@Nullable KindEnum kind) {
}


public BigCatDto declawed(Boolean declawed) {
public BigCatDto declawed(@Nullable Boolean declawed) {
super.declawed(declawed);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setOtherProperty(@Nullable String otherProperty) {
}


public ChildWithNullableDto type(TypeEnum type) {
public ChildWithNullableDto type(@Nullable TypeEnum type) {
super.type(type);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void setKind(@Nullable KindEnum kind) {
}


public BigCatDto declawed(Boolean declawed) {
public BigCatDto declawed(@Nullable Boolean declawed) {
super.declawed(declawed);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void setOtherProperty(@Nullable String otherProperty) {
}


public ChildWithNullableDto type(TypeEnum type) {
public ChildWithNullableDto type(@Nullable TypeEnum type) {
super.type(type);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void setKind(@Nullable KindEnum kind) {
}


public BigCat declawed(Boolean declawed) {
public BigCat declawed(@Nullable Boolean declawed) {
super.declawed(declawed);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void setOtherProperty(@Nullable String otherProperty) {
}


public ChildWithNullable type(TypeEnum type) {
public ChildWithNullable type(@Nullable TypeEnum type) {
super.type(type);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void setKind(@Nullable KindEnum kind) {
}


public BigCat declawed(Boolean declawed) {
public BigCat declawed(@Nullable Boolean declawed) {
super.declawed(declawed);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void setOtherProperty(@Nullable String otherProperty) {
}


public ChildWithNullable type(TypeEnum type) {
public ChildWithNullable type(@Nullable TypeEnum type) {
super.type(type);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void setKind(@Nullable KindEnum kind) {
}


public BigCat declawed(Boolean declawed) {
public BigCat declawed(@Nullable Boolean declawed) {
super.declawed(declawed);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void setOtherProperty(@Nullable String otherProperty) {
}


public ChildWithNullable type(TypeEnum type) {
public ChildWithNullable type(@Nullable TypeEnum type) {
super.type(type);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void setKind(@Nullable KindEnum kind) {
}


public BigCatDto declawed(Boolean declawed) {
public BigCatDto declawed(@Nullable Boolean declawed) {
super.declawed(declawed);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public void setOtherProperty(@Nullable String otherProperty) {
}


public ChildWithNullableDto type(TypeEnum type) {
public ChildWithNullableDto type(@Nullable TypeEnum type) {
super.type(type);
return this;
}

public ChildWithNullableDto nullableProperty(String nullableProperty) {
public ChildWithNullableDto nullableProperty(@Nullable String nullableProperty) {
super.nullableProperty(nullableProperty);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void setKind(@Nullable KindEnum kind) {
}


public BigCat declawed(Boolean declawed) {
public BigCat declawed(@Nullable Boolean declawed) {
super.declawed(declawed);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void setOtherProperty(@Nullable String otherProperty) {
}


public ChildWithNullable type(TypeEnum type) {
public ChildWithNullable type(@Nullable TypeEnum type) {
super.type(type);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void setKind(@Nullable KindEnum kind) {
}


public BigCatDto declawed(Boolean declawed) {
public BigCatDto declawed(@Nullable Boolean declawed) {
super.declawed(declawed);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void setOtherProperty(@Nullable String otherProperty) {
}


public ChildWithNullableDto type(TypeEnum type) {
public ChildWithNullableDto type(@Nullable TypeEnum type) {
super.type(type);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void setKind(@Nullable KindEnum kind) {
}


public BigCat declawed(Boolean declawed) {
public BigCat declawed(@Nullable Boolean declawed) {
super.declawed(declawed);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setOtherProperty(@Nullable String otherProperty) {
}


public ChildWithNullable type(TypeEnum type) {
public ChildWithNullable type(@Nullable TypeEnum type) {
super.type(type);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ public void setFoo(@Nullable FooRefOrValue foo) {
}


public Bar href(String href) {
public Bar href(@Nullable String href) {
super.href(href);
return this;
}

public Bar atSchemaLocation(String atSchemaLocation) {
public Bar atSchemaLocation(@Nullable String atSchemaLocation) {
super.atSchemaLocation(atSchemaLocation);
return this;
}

public Bar atBaseType(String atBaseType) {
public Bar atBaseType(@Nullable String atBaseType) {
super.atBaseType(atBaseType);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ public void setFoo(@Nullable FooRefOrValue foo) {
}


public BarCreate href(String href) {
public BarCreate href(@Nullable String href) {
super.href(href);
return this;
}

public BarCreate id(String id) {
public BarCreate id(@Nullable String id) {
super.id(id);
return this;
}

public BarCreate atSchemaLocation(String atSchemaLocation) {
public BarCreate atSchemaLocation(@Nullable String atSchemaLocation) {
super.atSchemaLocation(atSchemaLocation);
return this;
}

public BarCreate atBaseType(String atBaseType) {
public BarCreate atBaseType(@Nullable String atBaseType) {
super.atBaseType(atBaseType);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ public BarRef(String atType) {
}


public BarRef href(String href) {
public BarRef href(@Nullable String href) {
super.href(href);
return this;
}

public BarRef id(String id) {
public BarRef id(@Nullable String id) {
super.id(id);
return this;
}

public BarRef atSchemaLocation(String atSchemaLocation) {
public BarRef atSchemaLocation(@Nullable String atSchemaLocation) {
super.atSchemaLocation(atSchemaLocation);
return this;
}

public BarRef atBaseType(String atBaseType) {
public BarRef atBaseType(@Nullable String atBaseType) {
super.atBaseType(atBaseType);
return this;
}
Expand All @@ -62,12 +62,12 @@ public BarRef atType(String atType) {
return this;
}

public BarRef name(String name) {
public BarRef name(@Nullable String name) {
super.name(name);
return this;
}

public BarRef atReferredType(String atReferredType) {
public BarRef atReferredType(@Nullable String atReferredType) {
super.atReferredType(atReferredType);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ public void setFooPropB(@Nullable String fooPropB) {
}


public Foo href(String href) {
public Foo href(@Nullable String href) {
super.href(href);
return this;
}

public Foo id(String id) {
public Foo id(@Nullable String id) {
super.id(id);
return this;
}

public Foo atSchemaLocation(String atSchemaLocation) {
public Foo atSchemaLocation(@Nullable String atSchemaLocation) {
super.atSchemaLocation(atSchemaLocation);
return this;
}

public Foo atBaseType(String atBaseType) {
public Foo atBaseType(@Nullable String atBaseType) {
super.atBaseType(atBaseType);
return this;
}
Expand Down
Loading