Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java][feign] Fix model combining properties and additional properties #19713

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions bin/utils/test_file_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
sha256: 8b1b8f2a2ad00ccb090873a94a5f73e328b98317d2ec715f53bd7a1accb2a023
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java"
sha256: a1f8a70bf7b0c382a8def5bacf7b1fb189e687fabb40235aa799001e0597f545
# java feign test files
- filename: "samples/client/petstore/java/feign/src/test/java/org/openapitools/client/JacksonTest.java"
sha256: 537158f7cb5a372c63acf0ade4a221d13a145892e4156f39c71afae3a223bf5f
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,14 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("ParamExpander.mustache", invokerFolder, "ParamExpander.java"));
}
supportingFiles.add(new SupportingFile("EncodingUtils.mustache", invokerFolder, "EncodingUtils.java"));

// Composed schemas can have the 'additionalProperties' keyword, as specified in JSON schema.
// In principle, this should be enabled by default for all code generators. However due to limitations
// in other code generators, support needs to be enabled on a case-by-case basis.
// The flag below should be set for all Java libraries, but the templates need to be ported
// one by one for each library.
supportsAdditionalPropertiesWithComposedSchema = true;

} else if (OKHTTP_GSON.equals(getLibrary()) || StringUtils.isEmpty(getLibrary())) {
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
}{{#hasVars}}
{{classname}} {{classVarName}} = ({{classname}}) o;
return {{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}equalsNullable(this.{{name}}, {{classVarName}}.{{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{#isByteArray}}Arrays{{/isByteArray}}{{^isByteArray}}Objects{{/isByteArray}}.equals(this.{{name}}, {{classVarName}}.{{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}} &&
{{/-last}}{{/vars}}{{#parent}} &&
{{/-last}}{{/vars}}{{#additionalPropertiesType}} &&
Objects.equals(this.additionalProperties, {{classVarName}}.additionalProperties){{/additionalPropertiesType}}{{#parent}} &&
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
return {{#parent}}super.equals(o){{/parent}}{{^parent}}true{{/parent}};{{/hasVars}}
{{/useReflectionEqualsHashCode}}
Expand All @@ -279,7 +280,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
return HashCodeBuilder.reflectionHashCode(this);
{{/useReflectionEqualsHashCode}}
{{^useReflectionEqualsHashCode}}
return Objects.hash({{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}hashCodeNullable({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
return Objects.hash({{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}hashCodeNullable({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}{{#additionalPropertiesType}}, additionalProperties{{/additionalPropertiesType}});
{{/useReflectionEqualsHashCode}}
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}

Expand All @@ -300,6 +301,9 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{#vars}}
sb.append(" {{name}}: ").append({{#isPassword}}"*"{{/isPassword}}{{^isPassword}}toIndentedString({{name}}){{/isPassword}}).append("\n");
{{/vars}}
{{#additionalPropertiesType}}
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
{{/additionalPropertiesType}}
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -41,13 +39,12 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
public class AdditionalPropertiesAnyType extends HashMap<String, Object> {
public class AdditionalPropertiesAnyType {
public static final String JSON_PROPERTY_NAME = "name";
@javax.annotation.Nullable
private String name;

public AdditionalPropertiesAnyType() {

}

public AdditionalPropertiesAnyType name(@javax.annotation.Nullable String name) {
Expand Down Expand Up @@ -134,8 +131,8 @@ public int hashCode() {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AdditionalPropertiesAnyType {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -42,13 +40,12 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
public class AdditionalPropertiesArray extends HashMap<String, List> {
public class AdditionalPropertiesArray {
public static final String JSON_PROPERTY_NAME = "name";
@javax.annotation.Nullable
private String name;

public AdditionalPropertiesArray() {

}

public AdditionalPropertiesArray name(@javax.annotation.Nullable String name) {
Expand Down Expand Up @@ -135,8 +132,8 @@ public int hashCode() {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AdditionalPropertiesArray {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -41,13 +39,12 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
public class AdditionalPropertiesBoolean extends HashMap<String, Boolean> {
public class AdditionalPropertiesBoolean {
public static final String JSON_PROPERTY_NAME = "name";
@javax.annotation.Nullable
private String name;

public AdditionalPropertiesBoolean() {

}

public AdditionalPropertiesBoolean name(@javax.annotation.Nullable String name) {
Expand Down Expand Up @@ -134,8 +131,8 @@ public int hashCode() {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AdditionalPropertiesBoolean {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -41,13 +39,12 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
public class AdditionalPropertiesInteger extends HashMap<String, Integer> {
public class AdditionalPropertiesInteger {
public static final String JSON_PROPERTY_NAME = "name";
@javax.annotation.Nullable
private String name;

public AdditionalPropertiesInteger() {

}

public AdditionalPropertiesInteger name(@javax.annotation.Nullable String name) {
Expand Down Expand Up @@ -134,8 +131,8 @@ public int hashCode() {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AdditionalPropertiesInteger {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -42,13 +40,12 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
public class AdditionalPropertiesNumber extends HashMap<String, BigDecimal> {
public class AdditionalPropertiesNumber {
public static final String JSON_PROPERTY_NAME = "name";
@javax.annotation.Nullable
private String name;

public AdditionalPropertiesNumber() {

}

public AdditionalPropertiesNumber name(@javax.annotation.Nullable String name) {
Expand Down Expand Up @@ -135,8 +132,8 @@ public int hashCode() {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AdditionalPropertiesNumber {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;
Expand All @@ -41,13 +40,12 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
public class AdditionalPropertiesObject extends HashMap<String, Map> {
public class AdditionalPropertiesObject {
public static final String JSON_PROPERTY_NAME = "name";
@javax.annotation.Nullable
private String name;

public AdditionalPropertiesObject() {

}

public AdditionalPropertiesObject name(@javax.annotation.Nullable String name) {
Expand Down Expand Up @@ -134,8 +132,8 @@ public int hashCode() {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AdditionalPropertiesObject {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -41,13 +39,12 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
public class AdditionalPropertiesString extends HashMap<String, String> {
public class AdditionalPropertiesString {
public static final String JSON_PROPERTY_NAME = "name";
@javax.annotation.Nullable
private String name;

public AdditionalPropertiesString() {

}

public AdditionalPropertiesString name(@javax.annotation.Nullable String name) {
Expand Down Expand Up @@ -134,8 +131,8 @@ public int hashCode() {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AdditionalPropertiesString {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
NullableClass.JSON_PROPERTY_OBJECT_ITEMS_NULLABLE
})
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
public class NullableClass extends HashMap<String, Object> {
public class NullableClass {
public static final String JSON_PROPERTY_INTEGER_PROP = "integer_prop";
private JsonNullable<Integer> integerProp = JsonNullable.<Integer>undefined();

Expand Down Expand Up @@ -97,7 +97,6 @@ public class NullableClass extends HashMap<String, Object> {
private Map<String, Object> objectItemsNullable = new HashMap<>();

public NullableClass() {

}

public NullableClass integerProp(@javax.annotation.Nullable Integer integerProp) {
Expand Down Expand Up @@ -620,7 +619,7 @@ public boolean equals(Object o) {
equalsNullable(this.objectNullableProp, nullableClass.objectNullableProp) &&
equalsNullable(this.objectAndItemsNullableProp, nullableClass.objectAndItemsNullableProp) &&
Objects.equals(this.objectItemsNullable, nullableClass.objectItemsNullable) &&
super.equals(o);
Objects.equals(this.additionalProperties, nullableClass.additionalProperties);
}

private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
Expand All @@ -629,7 +628,7 @@ private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b)

@Override
public int hashCode() {
return Objects.hash(hashCodeNullable(integerProp), hashCodeNullable(numberProp), hashCodeNullable(booleanProp), hashCodeNullable(stringProp), hashCodeNullable(dateProp), hashCodeNullable(datetimeProp), hashCodeNullable(arrayNullableProp), hashCodeNullable(arrayAndItemsNullableProp), arrayItemsNullable, hashCodeNullable(objectNullableProp), hashCodeNullable(objectAndItemsNullableProp), objectItemsNullable, super.hashCode());
return Objects.hash(hashCodeNullable(integerProp), hashCodeNullable(numberProp), hashCodeNullable(booleanProp), hashCodeNullable(stringProp), hashCodeNullable(dateProp), hashCodeNullable(datetimeProp), hashCodeNullable(arrayNullableProp), hashCodeNullable(arrayAndItemsNullableProp), arrayItemsNullable, hashCodeNullable(objectNullableProp), hashCodeNullable(objectAndItemsNullableProp), objectItemsNullable, additionalProperties);
}

private static <T> int hashCodeNullable(JsonNullable<T> a) {
Expand All @@ -643,7 +642,6 @@ private static <T> int hashCodeNullable(JsonNullable<T> a) {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class NullableClass {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" integerProp: ").append(toIndentedString(integerProp)).append("\n");
sb.append(" numberProp: ").append(toIndentedString(numberProp)).append("\n");
sb.append(" booleanProp: ").append(toIndentedString(booleanProp)).append("\n");
Expand All @@ -656,6 +654,7 @@ public String toString() {
sb.append(" objectNullableProp: ").append(toIndentedString(objectNullableProp)).append("\n");
sb.append(" objectAndItemsNullableProp: ").append(toIndentedString(objectAndItemsNullableProp)).append("\n");
sb.append(" objectItemsNullable: ").append(toIndentedString(objectItemsNullable)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -37,13 +35,12 @@
})
@JsonTypeName("testInlineFreeformAdditionalProperties_request")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.11.0-SNAPSHOT")
public class TestInlineFreeformAdditionalPropertiesRequest extends HashMap<String, Object> {
public class TestInlineFreeformAdditionalPropertiesRequest {
public static final String JSON_PROPERTY_SOME_PROPERTY = "someProperty";
@javax.annotation.Nullable
private String someProperty;

public TestInlineFreeformAdditionalPropertiesRequest() {

}

public TestInlineFreeformAdditionalPropertiesRequest someProperty(@javax.annotation.Nullable String someProperty) {
Expand Down Expand Up @@ -125,20 +122,20 @@ public boolean equals(Object o) {
}
TestInlineFreeformAdditionalPropertiesRequest testInlineFreeformAdditionalPropertiesRequest = (TestInlineFreeformAdditionalPropertiesRequest) o;
return Objects.equals(this.someProperty, testInlineFreeformAdditionalPropertiesRequest.someProperty) &&
super.equals(o);
Objects.equals(this.additionalProperties, testInlineFreeformAdditionalPropertiesRequest.additionalProperties);
}

@Override
public int hashCode() {
return Objects.hash(someProperty, super.hashCode());
return Objects.hash(someProperty, additionalProperties);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class TestInlineFreeformAdditionalPropertiesRequest {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append(" someProperty: ").append(toIndentedString(someProperty)).append("\n");
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Loading