fix(java): default values from allOfs are not correctly definied (#22200)

* fix: extend check for default values of integer and number schema

* add testcases to openapi specs

* generate java clients with the updated fix
This commit is contained in:
Marcel Jacek
2025-10-31 08:58:20 +01:00
committed by GitHub
parent 9b8ab659ac
commit 66b742038a
65 changed files with 3848 additions and 5 deletions

View File

@@ -6,6 +6,9 @@ api/openapi.yaml
build.gradle
build.sbt
docs/AdditionalPropertiesClass.md
docs/AllOfRefToDouble.md
docs/AllOfRefToFloat.md
docs/AllOfRefToLong.md
docs/Animal.md
docs/AnotherFakeApi.md
docs/Apple.md
@@ -116,6 +119,9 @@ src/main/java/org/openapitools/client/api/StoreApi.java
src/main/java/org/openapitools/client/api/UserApi.java
src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java
src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java
src/main/java/org/openapitools/client/model/AllOfRefToDouble.java
src/main/java/org/openapitools/client/model/AllOfRefToFloat.java
src/main/java/org/openapitools/client/model/AllOfRefToLong.java
src/main/java/org/openapitools/client/model/Animal.java
src/main/java/org/openapitools/client/model/Apple.java
src/main/java/org/openapitools/client/model/AppleReq.java
@@ -190,3 +196,6 @@ src/main/java/org/openapitools/client/model/TriangleInterface.java
src/main/java/org/openapitools/client/model/User.java
src/main/java/org/openapitools/client/model/Whale.java
src/main/java/org/openapitools/client/model/Zebra.java
src/test/java/org/openapitools/client/model/AllOfRefToDoubleTest.java
src/test/java/org/openapitools/client/model/AllOfRefToFloatTest.java
src/test/java/org/openapitools/client/model/AllOfRefToLongTest.java

View File

@@ -201,6 +201,9 @@ Class | Method | HTTP request | Description
## Documentation for Models
- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [AllOfRefToDouble](docs/AllOfRefToDouble.md)
- [AllOfRefToFloat](docs/AllOfRefToFloat.md)
- [AllOfRefToLong](docs/AllOfRefToLong.md)
- [Animal](docs/Animal.md)
- [Apple](docs/Apple.md)
- [AppleReq](docs/AppleReq.md)

View File

@@ -2295,6 +2295,42 @@ components:
$ref: "#/components/schemas/Bar"
type: array
type: object
LongId:
description: Id as long
format: int64
type: integer
Weight:
description: Weight as float
format: float
type: number
Height:
description: Height as double
format: double
type: number
AllOfRefToLong:
description: Object with allOf ref to long
properties:
id:
allOf:
- $ref: "#/components/schemas/LongId"
default: 10
type: object
AllOfRefToFloat:
description: Object with allOf ref to float
properties:
weight:
allOf:
- $ref: "#/components/schemas/Weight"
default: 7.89
type: object
AllOfRefToDouble:
description: Object with allOf ref to double
properties:
height:
allOf:
- $ref: "#/components/schemas/Height"
default: 32.1
type: object
_foo_get_default_response:
example:
string:

View File

@@ -0,0 +1,14 @@
# AllOfRefToDouble
Object with allOf ref to double
## Properties
| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**height** | **Double** | Height as double | [optional] |

View File

@@ -0,0 +1,14 @@
# AllOfRefToFloat
Object with allOf ref to float
## Properties
| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**weight** | **Float** | Weight as float | [optional] |

View File

@@ -0,0 +1,14 @@
# AllOfRefToLong
Object with allOf ref to long
## Properties
| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**id** | **Long** | Id as long | [optional] |

View File

@@ -0,0 +1,152 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.StringJoiner;
import java.util.Objects;
import java.util.Map;
import java.util.HashMap;
import java.util.Locale;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.openapitools.client.ApiClient;
/**
* Object with allOf ref to double
*/
@JsonPropertyOrder({
AllOfRefToDouble.JSON_PROPERTY_HEIGHT
})
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.17.0-SNAPSHOT")
public class AllOfRefToDouble {
public static final String JSON_PROPERTY_HEIGHT = "height";
@javax.annotation.Nullable
private Double height = 32.1d;
public AllOfRefToDouble() {
}
public AllOfRefToDouble height(@javax.annotation.Nullable Double height) {
this.height = height;
return this;
}
/**
* Height as double
* @return height
*/
@javax.annotation.Nullable
@JsonProperty(value = JSON_PROPERTY_HEIGHT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public Double getHeight() {
return height;
}
@JsonProperty(value = JSON_PROPERTY_HEIGHT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setHeight(@javax.annotation.Nullable Double height) {
this.height = height;
}
/**
* Return true if this AllOfRefToDouble object is equal to o.
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AllOfRefToDouble allOfRefToDouble = (AllOfRefToDouble) o;
return Objects.equals(this.height, allOfRefToDouble.height);
}
@Override
public int hashCode() {
return Objects.hash(height);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AllOfRefToDouble {\n");
sb.append(" height: ").append(toIndentedString(height)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
/**
* Convert the instance into URL query string.
*
* @return URL query string
*/
public String toUrlQueryString() {
return toUrlQueryString(null);
}
/**
* Convert the instance into URL query string.
*
* @param prefix prefix of the query string
* @return URL query string
*/
public String toUrlQueryString(String prefix) {
String suffix = "";
String containerSuffix = "";
String containerPrefix = "";
if (prefix == null) {
// style=form, explode=true, e.g. /pet?name=cat&type=manx
prefix = "";
} else {
// deepObject style e.g. /pet?id[name]=cat&id[type]=manx
prefix = prefix + "[";
suffix = "]";
containerSuffix = "]";
containerPrefix = "[";
}
StringJoiner joiner = new StringJoiner("&");
// add `height` to the URL query string
if (getHeight() != null) {
joiner.add(String.format(Locale.ROOT, "%sheight%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getHeight()))));
}
return joiner.toString();
}
}

View File

@@ -0,0 +1,152 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.StringJoiner;
import java.util.Objects;
import java.util.Map;
import java.util.HashMap;
import java.util.Locale;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.openapitools.client.ApiClient;
/**
* Object with allOf ref to float
*/
@JsonPropertyOrder({
AllOfRefToFloat.JSON_PROPERTY_WEIGHT
})
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.17.0-SNAPSHOT")
public class AllOfRefToFloat {
public static final String JSON_PROPERTY_WEIGHT = "weight";
@javax.annotation.Nullable
private Float weight = 7.89f;
public AllOfRefToFloat() {
}
public AllOfRefToFloat weight(@javax.annotation.Nullable Float weight) {
this.weight = weight;
return this;
}
/**
* Weight as float
* @return weight
*/
@javax.annotation.Nullable
@JsonProperty(value = JSON_PROPERTY_WEIGHT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public Float getWeight() {
return weight;
}
@JsonProperty(value = JSON_PROPERTY_WEIGHT, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setWeight(@javax.annotation.Nullable Float weight) {
this.weight = weight;
}
/**
* Return true if this AllOfRefToFloat object is equal to o.
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AllOfRefToFloat allOfRefToFloat = (AllOfRefToFloat) o;
return Objects.equals(this.weight, allOfRefToFloat.weight);
}
@Override
public int hashCode() {
return Objects.hash(weight);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AllOfRefToFloat {\n");
sb.append(" weight: ").append(toIndentedString(weight)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
/**
* Convert the instance into URL query string.
*
* @return URL query string
*/
public String toUrlQueryString() {
return toUrlQueryString(null);
}
/**
* Convert the instance into URL query string.
*
* @param prefix prefix of the query string
* @return URL query string
*/
public String toUrlQueryString(String prefix) {
String suffix = "";
String containerSuffix = "";
String containerPrefix = "";
if (prefix == null) {
// style=form, explode=true, e.g. /pet?name=cat&type=manx
prefix = "";
} else {
// deepObject style e.g. /pet?id[name]=cat&id[type]=manx
prefix = prefix + "[";
suffix = "]";
containerSuffix = "]";
containerPrefix = "[";
}
StringJoiner joiner = new StringJoiner("&");
// add `weight` to the URL query string
if (getWeight() != null) {
joiner.add(String.format(Locale.ROOT, "%sweight%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getWeight()))));
}
return joiner.toString();
}
}

View File

@@ -0,0 +1,152 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.StringJoiner;
import java.util.Objects;
import java.util.Map;
import java.util.HashMap;
import java.util.Locale;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.openapitools.client.ApiClient;
/**
* Object with allOf ref to long
*/
@JsonPropertyOrder({
AllOfRefToLong.JSON_PROPERTY_ID
})
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.17.0-SNAPSHOT")
public class AllOfRefToLong {
public static final String JSON_PROPERTY_ID = "id";
@javax.annotation.Nullable
private Long id = 10l;
public AllOfRefToLong() {
}
public AllOfRefToLong id(@javax.annotation.Nullable Long id) {
this.id = id;
return this;
}
/**
* Id as long
* @return id
*/
@javax.annotation.Nullable
@JsonProperty(value = JSON_PROPERTY_ID, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public Long getId() {
return id;
}
@JsonProperty(value = JSON_PROPERTY_ID, required = false)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setId(@javax.annotation.Nullable Long id) {
this.id = id;
}
/**
* Return true if this AllOfRefToLong object is equal to o.
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AllOfRefToLong allOfRefToLong = (AllOfRefToLong) o;
return Objects.equals(this.id, allOfRefToLong.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AllOfRefToLong {\n");
sb.append(" id: ").append(toIndentedString(id)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
/**
* Convert the instance into URL query string.
*
* @return URL query string
*/
public String toUrlQueryString() {
return toUrlQueryString(null);
}
/**
* Convert the instance into URL query string.
*
* @param prefix prefix of the query string
* @return URL query string
*/
public String toUrlQueryString(String prefix) {
String suffix = "";
String containerSuffix = "";
String containerPrefix = "";
if (prefix == null) {
// style=form, explode=true, e.g. /pet?name=cat&type=manx
prefix = "";
} else {
// deepObject style e.g. /pet?id[name]=cat&id[type]=manx
prefix = prefix + "[";
suffix = "]";
containerSuffix = "]";
containerPrefix = "[";
}
StringJoiner joiner = new StringJoiner("&");
// add `id` to the URL query string
if (getId() != null) {
joiner.add(String.format(Locale.ROOT, "%sid%s=%s", prefix, suffix, ApiClient.urlEncode(ApiClient.valueToString(getId()))));
}
return joiner.toString();
}
}

View File

@@ -0,0 +1,48 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Model tests for AllOfRefToDouble
*/
class AllOfRefToDoubleTest {
private final AllOfRefToDouble model = new AllOfRefToDouble();
/**
* Model tests for AllOfRefToDouble
*/
@Test
void testAllOfRefToDouble() {
// TODO: test AllOfRefToDouble
}
/**
* Test the property 'height'
*/
@Test
void heightTest() {
// TODO: test height
}
}

View File

@@ -0,0 +1,48 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Model tests for AllOfRefToFloat
*/
class AllOfRefToFloatTest {
private final AllOfRefToFloat model = new AllOfRefToFloat();
/**
* Model tests for AllOfRefToFloat
*/
@Test
void testAllOfRefToFloat() {
// TODO: test AllOfRefToFloat
}
/**
* Test the property 'weight'
*/
@Test
void weightTest() {
// TODO: test weight
}
}

View File

@@ -0,0 +1,48 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Model tests for AllOfRefToLong
*/
class AllOfRefToLongTest {
private final AllOfRefToLong model = new AllOfRefToLong();
/**
* Model tests for AllOfRefToLong
*/
@Test
void testAllOfRefToLong() {
// TODO: test AllOfRefToLong
}
/**
* Test the property 'id'
*/
@Test
void idTest() {
// TODO: test id
}
}