Skip to content

Commit

Permalink
[java][feign] Fix model combining properties and additional properties
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoBrlt committed Oct 16, 2024
1 parent 38dac13 commit cf99d83
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 62 deletions.
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 @@ -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 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.10.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 @@ -125,20 +122,20 @@ public boolean equals(Object o) {
}
AdditionalPropertiesAnyType additionalPropertiesAnyType = (AdditionalPropertiesAnyType) o;
return Objects.equals(this.name, additionalPropertiesAnyType.name) &&
super.equals(o);
Objects.equals(this.additionalProperties, additionalPropertiesAnyType.additionalProperties);
}

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

@Override
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 @@ -24,9 +24,7 @@
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.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -38,13 +36,12 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.10.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 @@ -126,20 +123,20 @@ public boolean equals(Object o) {
}
AdditionalPropertiesArray additionalPropertiesArray = (AdditionalPropertiesArray) o;
return Objects.equals(this.name, additionalPropertiesArray.name) &&
super.equals(o);
Objects.equals(this.additionalProperties, additionalPropertiesArray.additionalProperties);
}

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

@Override
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 @@ -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 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.10.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 @@ -125,20 +122,20 @@ public boolean equals(Object o) {
}
AdditionalPropertiesBoolean additionalPropertiesBoolean = (AdditionalPropertiesBoolean) o;
return Objects.equals(this.name, additionalPropertiesBoolean.name) &&
super.equals(o);
Objects.equals(this.additionalProperties, additionalPropertiesBoolean.additionalProperties);
}

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

@Override
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 @@ -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 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.10.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 @@ -125,20 +122,20 @@ public boolean equals(Object o) {
}
AdditionalPropertiesInteger additionalPropertiesInteger = (AdditionalPropertiesInteger) o;
return Objects.equals(this.name, additionalPropertiesInteger.name) &&
super.equals(o);
Objects.equals(this.additionalProperties, additionalPropertiesInteger.additionalProperties);
}

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

@Override
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 @@ -25,8 +25,6 @@
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
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 @@ -38,13 +36,12 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.10.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 @@ -126,20 +123,20 @@ public boolean equals(Object o) {
}
AdditionalPropertiesNumber additionalPropertiesNumber = (AdditionalPropertiesNumber) o;
return Objects.equals(this.name, additionalPropertiesNumber.name) &&
super.equals(o);
Objects.equals(this.additionalProperties, additionalPropertiesNumber.additionalProperties);
}

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

@Override
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 @@ -24,7 +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 +36,12 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.10.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 @@ -125,20 +123,20 @@ public boolean equals(Object o) {
}
AdditionalPropertiesObject additionalPropertiesObject = (AdditionalPropertiesObject) o;
return Objects.equals(this.name, additionalPropertiesObject.name) &&
super.equals(o);
Objects.equals(this.additionalProperties, additionalPropertiesObject.additionalProperties);
}

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

@Override
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 @@ -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 @@
})
@javax.annotation.concurrent.Immutable
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.10.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 @@ -125,20 +122,20 @@ public boolean equals(Object o) {
}
AdditionalPropertiesString additionalPropertiesString = (AdditionalPropertiesString) o;
return Objects.equals(this.name, additionalPropertiesString.name) &&
super.equals(o);
Objects.equals(this.additionalProperties, additionalPropertiesString.additionalProperties);
}

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

@Override
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
Loading

0 comments on commit cf99d83

Please sign in to comment.