Skip to content
Merged
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 @@ -304,6 +304,7 @@ public AbstractJavaCodegen() {
typeMapping.put("date", "Date");
typeMapping.put("file", "File");
typeMapping.put("AnyType", "Object");
typeMapping.put("null", "Object");
typeMapping.put("enum", "Enum");

importMapping.put("BigDecimal", "java.math.BigDecimal");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1114,4 +1114,13 @@ public void removeAnnotationsTest() {
public void testSanitizedDataType() {
assertThat(codegen.sanitizeDataType("org.somepkg.DataType")).isEqualTo("orgsomepkgDataType");
}

@Test(description = "the OAS 3.1 null type maps to Object instead of a never-generated ModelNull (issue 24520)")
public void testNullTypeMapsToObject() {
Schema<?> nullSchema = new Schema<>().type("null");

assertThat(codegen.getSchemaType(nullSchema)).isEqualTo("Object");
assertThat(codegen.getTypeDeclaration(nullSchema)).isEqualTo("Object");
assertThat(codegen.getTypeDeclaration(new ArraySchema().items(nullSchema))).isEqualTo("List<Object>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1135,3 +1135,6 @@ components:
second_property:
description: just null type
type: null
third_property:
description: null type declared as the OAS 3.1 quoted string
type: 'null'
2 changes: 2 additions & 0 deletions samples/client/petstore/java/okhttp-gson-3.1/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,8 @@ components:
$ref: "#/components/schemas/Pet"
second_property:
description: just null type
third_property:
description: null type declared as the OAS 3.1 quoted string
updatePetWithForm_request:
properties:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
|------------ | ------------- | ------------- | -------------|
|**firstProperty** | [**Pet**](Pet.md) | | [optional] |
|**secondProperty** | **Object** | just null type | [optional] |
|**thirdProperty** | **Object** | null type declared as the OAS 3.1 quoted string | [optional] |



Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public class PetWithTypesObjectNullAndRef {
@javax.annotation.Nullable
private Object secondProperty = null;

public static final String SERIALIZED_NAME_THIRD_PROPERTY = "third_property";
@SerializedName(SERIALIZED_NAME_THIRD_PROPERTY)
@javax.annotation.Nullable
private Object thirdProperty = null;

public PetWithTypesObjectNullAndRef() {
}

Expand Down Expand Up @@ -103,6 +108,25 @@ public void setSecondProperty(@javax.annotation.Nullable Object secondProperty)
this.secondProperty = secondProperty;
}


public PetWithTypesObjectNullAndRef thirdProperty(@javax.annotation.Nullable Object thirdProperty) {
this.thirdProperty = thirdProperty;
return this;
}

/**
* null type declared as the OAS 3.1 quoted string
* @return thirdProperty
*/
@javax.annotation.Nullable
public Object getThirdProperty() {
return thirdProperty;
}

public void setThirdProperty(@javax.annotation.Nullable Object thirdProperty) {
this.thirdProperty = thirdProperty;
}

/**
* A container for additional, undeclared properties.
* This is a holder for any undeclared properties as specified with
Expand Down Expand Up @@ -159,7 +183,8 @@ public boolean equals(Object o) {
}
PetWithTypesObjectNullAndRef petWithTypesObjectNullAndRef = (PetWithTypesObjectNullAndRef) o;
return Objects.equals(this.firstProperty, petWithTypesObjectNullAndRef.firstProperty) &&
Objects.equals(this.secondProperty, petWithTypesObjectNullAndRef.secondProperty)&&
Objects.equals(this.secondProperty, petWithTypesObjectNullAndRef.secondProperty) &&
Objects.equals(this.thirdProperty, petWithTypesObjectNullAndRef.thirdProperty)&&
Objects.equals(this.additionalProperties, petWithTypesObjectNullAndRef.additionalProperties);
}

Expand All @@ -169,7 +194,7 @@ private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b)

@Override
public int hashCode() {
return Objects.hash(firstProperty, secondProperty, additionalProperties);
return Objects.hash(firstProperty, secondProperty, thirdProperty, additionalProperties);
}

private static <T> int hashCodeNullable(JsonNullable<T> a) {
Expand All @@ -185,6 +210,7 @@ public String toString() {
sb.append("class PetWithTypesObjectNullAndRef {\n");
sb.append(" firstProperty: ").append(toIndentedString(firstProperty)).append("\n");
sb.append(" secondProperty: ").append(toIndentedString(secondProperty)).append("\n");
sb.append(" thirdProperty: ").append(toIndentedString(thirdProperty)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
Expand All @@ -204,7 +230,7 @@ private String toIndentedString(Object o) {

static {
// a set of all properties/fields (JSON key names)
openapiFields = new HashSet<String>(Arrays.asList("first_property", "second_property"));
openapiFields = new HashSet<String>(Arrays.asList("first_property", "second_property", "third_property"));

// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>(0);
Expand Down
Loading