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

Adds getAdditionalPropertiesIsAnyType to java schema classes #8908

Merged
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 @@ -65,6 +65,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
public String arrayModelType;
public boolean isAlias; // Is this effectively an alias of another simple type
public boolean isString, isInteger, isLong, isNumber, isNumeric, isFloat, isDouble, isDate, isDateTime;
private boolean additionalPropertiesIsAnyType;
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>(); // all properties (without parent's properties)
public List<CodegenProperty> allVars = new ArrayList<CodegenProperty>(); // all properties (with parent's properties)
public List<CodegenProperty> requiredVars = new ArrayList<CodegenProperty>(); // a list of required properties
Expand Down Expand Up @@ -712,6 +713,16 @@ public void setIsNull(boolean isNull) {
this.isNull = isNull;
}

@Override
public boolean getAdditionalPropertiesIsAnyType() {
return additionalPropertiesIsAnyType;
}

@Override
public void setAdditionalPropertiesIsAnyType(boolean additionalPropertiesIsAnyType) {
this.additionalPropertiesIsAnyType = additionalPropertiesIsAnyType;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down Expand Up @@ -742,6 +753,7 @@ public boolean equals(Object o) {
hasOnlyReadOnly == that.hasOnlyReadOnly &&
isNull == that.isNull &&
hasValidation == that.hasValidation &&
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
getUniqueItems() == that.getUniqueItems() &&
getExclusiveMinimum() == that.getExclusiveMinimum() &&
getExclusiveMaximum() == that.getExclusiveMaximum() &&
Expand Down Expand Up @@ -813,7 +825,8 @@ public int hashCode() {
hasChildren, isMap, isDeprecated, hasOnlyReadOnly, getExternalDocumentation(), getVendorExtensions(),
getAdditionalPropertiesType(), getMaxProperties(), getMinProperties(), getUniqueItems(), getMaxItems(),
getMinItems(), getMaxLength(), getMinLength(), getExclusiveMinimum(), getExclusiveMaximum(), getMinimum(),
getMaximum(), getPattern(), getMultipleOf(), getItems(), getAdditionalProperties(), getIsModel());
getMaximum(), getPattern(), getMultipleOf(), getItems(), getAdditionalProperties(), getIsModel(),
getAdditionalPropertiesIsAnyType());
}

@Override
Expand Down Expand Up @@ -899,6 +912,7 @@ public String toString() {
sb.append(", isModel='").append(isModel).append('\'');
sb.append(", isNull='").append(isNull);
sb.append(", hasValidation='").append(hasValidation);
sb.append(", getAdditionalPropertiesIsAnyType=").append(getAdditionalPropertiesIsAnyType());
sb.append('}');
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
public boolean isArray, isMap;
public boolean isFile;
public boolean isEnum;
private boolean additionalPropertiesIsAnyType;
public List<String> _enum;
public Map<String, Object> allowableValues;
public CodegenProperty items;
Expand Down Expand Up @@ -149,6 +150,7 @@ public CodegenParameter copy() {
output.pattern = this.pattern;
output.additionalProperties = this.additionalProperties;
output.isNull = this.isNull;
output.setAdditionalPropertiesIsAnyType(this.getAdditionalPropertiesIsAnyType());

if (this._enum != null) {
output._enum = new ArrayList<String>(this._enum);
Expand Down Expand Up @@ -203,7 +205,7 @@ public CodegenParameter copy() {

@Override
public int hashCode() {
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style, isDeepObject, example, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, _enum, allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull);
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style, isDeepObject, example, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, _enum, allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull, getAdditionalPropertiesIsAnyType());
}

@Override
Expand Down Expand Up @@ -248,6 +250,7 @@ public boolean equals(Object o) {
isNullable == that.isNullable &&
required == that.required &&
isNull == that.isNull &&
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
getExclusiveMaximum() == that.getExclusiveMaximum() &&
getExclusiveMinimum() == that.getExclusiveMinimum() &&
getUniqueItems() == that.getUniqueItems() &&
Expand Down Expand Up @@ -364,6 +367,7 @@ public String toString() {
sb.append(", contentType=").append(contentType);
sb.append(", multipleOf=").append(multipleOf);
sb.append(", isNull=").append(isNull);
sb.append(", getAdditionalPropertiesIsAnyType=").append(getAdditionalPropertiesIsAnyType());
sb.append('}');
return sb.toString();
}
Expand Down Expand Up @@ -591,5 +595,15 @@ public void setIsNull(boolean isNull) {

@Override
public void setHasValidation(boolean hasValidation) { this.hasValidation = hasValidation; }

@Override
public boolean getAdditionalPropertiesIsAnyType() {
return additionalPropertiesIsAnyType;
}

@Override
public void setAdditionalPropertiesIsAnyType(boolean additionalPropertiesIsAnyType) {
this.additionalPropertiesIsAnyType = additionalPropertiesIsAnyType;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
public String xmlName;
public String xmlNamespace;
public boolean isXmlWrapped = false;
private boolean additionalPropertiesIsAnyType;

public String getBaseName() {
return baseName;
Expand Down Expand Up @@ -693,6 +694,16 @@ public void setIsNull(boolean isNull) {
@Override
public void setHasValidation(boolean hasValidation) { this.hasValidation = hasValidation; }

@Override
public boolean getAdditionalPropertiesIsAnyType() {
return additionalPropertiesIsAnyType;
}

@Override
public void setAdditionalPropertiesIsAnyType(boolean additionalPropertiesIsAnyType) {
this.additionalPropertiesIsAnyType = additionalPropertiesIsAnyType;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CodegenProperty{");
Expand Down Expand Up @@ -782,6 +793,7 @@ public String toString() {
sb.append(", xmlNamespace='").append(xmlNamespace).append('\'');
sb.append(", isXmlWrapped=").append(isXmlWrapped);
sb.append(", isNull=").append(isNull);
sb.append(", getAdditionalPropertiesIsAnyType=").append(getAdditionalPropertiesIsAnyType());
sb.append('}');
return sb.toString();
}
Expand Down Expand Up @@ -831,6 +843,7 @@ public boolean equals(Object o) {
isXmlAttribute == that.isXmlAttribute &&
isXmlWrapped == that.isXmlWrapped &&
isNull == that.isNull &&
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
Objects.equals(openApiType, that.openApiType) &&
Objects.equals(baseName, that.baseName) &&
Objects.equals(complexType, that.complexType) &&
Expand Down Expand Up @@ -892,6 +905,6 @@ public int hashCode() {
items, mostInnerItems, additionalProperties, vars, requiredVars,
vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase,
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName,
xmlNamespace, isXmlWrapped, isNull);
xmlNamespace, isXmlWrapped, isNull, getAdditionalPropertiesIsAnyType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>(); // all properties (without parent's properties)
public List<CodegenProperty> requiredVars = new ArrayList<CodegenProperty>();
private boolean hasValidation;
private boolean additionalPropertiesIsAnyType;

@Override
public int hashCode() {
Expand All @@ -89,7 +90,7 @@ public int hashCode() {
vars, requiredVars, isNull, hasValidation,
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern(),
is1xx, is2xx, is3xx, is4xx, is5xx);
is1xx, is2xx, is3xx, is4xx, is5xx, getAdditionalPropertiesIsAnyType());
}

@Override
Expand Down Expand Up @@ -131,6 +132,7 @@ public boolean equals(Object o) {
is3xx == that.is3xx &&
is4xx == that.is4xx &&
is5xx == that.is5xx &&
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
Objects.equals(vars, that.vars) &&
Objects.equals(requiredVars, that.requiredVars) &&
Objects.equals(headers, that.headers) &&
Expand Down Expand Up @@ -429,6 +431,7 @@ public String toString() {
sb.append(", requiredVars='").append(requiredVars).append('\'');
sb.append(", isNull='").append(isNull);
sb.append(", hasValidation='").append(hasValidation);
sb.append(", getAdditionalPropertiesIsAnyType=").append(getAdditionalPropertiesIsAnyType());
sb.append('}');
return sb.toString();
}
Expand Down Expand Up @@ -465,4 +468,14 @@ public void setIsNull(boolean isNull) {

@Override
public void setHasValidation(boolean hasValidation) { this.hasValidation = hasValidation; }

@Override
public boolean getAdditionalPropertiesIsAnyType() {
return additionalPropertiesIsAnyType;
}

@Override
public void setAdditionalPropertiesIsAnyType(boolean additionalPropertiesIsAnyType) {
this.additionalPropertiesIsAnyType = additionalPropertiesIsAnyType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2579,27 +2579,7 @@ public int compare(CodegenProperty one, CodegenProperty another) {
}

// process 'additionalProperties'
if (schema.getAdditionalProperties() == null) {
if (disallowAdditionalPropertiesIfNotPresent) {
m.isAdditionalPropertiesTrue = false;
} else {
m.isAdditionalPropertiesTrue = true;
CodegenProperty cp = fromProperty("", new Schema());
m.setAdditionalProperties(cp);
}
} else if (schema.getAdditionalProperties() instanceof Boolean) {
if (Boolean.TRUE.equals(schema.getAdditionalProperties())) {
m.isAdditionalPropertiesTrue = true;
CodegenProperty cp = fromProperty("", new Schema());
m.setAdditionalProperties(cp);
} else {
m.isAdditionalPropertiesTrue = false;
}
} else {
m.isAdditionalPropertiesTrue = false;
CodegenProperty cp = fromProperty("", (Schema) schema.getAdditionalProperties());
m.setAdditionalProperties(cp);
}
setAddProps(schema, m);

// post process model properties
if (m.vars != null) {
Expand All @@ -2616,15 +2596,48 @@ public int compare(CodegenProperty one, CodegenProperty another) {
return m;
}

/**
* Recursively look in Schema sc for the discriminator discPropName
* and return a CodegenProperty with the dataType and required params set
* the returned CodegenProperty may not be required and it may not be of type string
*
* @param composedSchemaName The name of the sc Schema
* @param sc The Schema that may contain the discriminator
* @param discPropName The String that is the discriminator propertyName in the schema
*/
private void setAddProps(Schema schema, IJsonSchemaValidationProperties property){
CodegenModel m = null;
if (property instanceof CodegenModel) {
m = (CodegenModel) property;
}
boolean isAdditionalPropertiesTrue = false;
if (schema.getAdditionalProperties() == null) {
if (!disallowAdditionalPropertiesIfNotPresent) {
isAdditionalPropertiesTrue = true;
CodegenProperty cp = fromProperty("", new Schema());
property.setAdditionalProperties(cp);
property.setAdditionalPropertiesIsAnyType(true);
}
} else if (schema.getAdditionalProperties() instanceof Boolean) {
if (Boolean.TRUE.equals(schema.getAdditionalProperties())) {
isAdditionalPropertiesTrue = true;
CodegenProperty cp = fromProperty("", new Schema());
property.setAdditionalProperties(cp);
property.setAdditionalPropertiesIsAnyType(true);
}
} else {
CodegenProperty cp = fromProperty("", (Schema) schema.getAdditionalProperties());
property.setAdditionalProperties(cp);
if (isAnyTypeSchema((Schema) schema.getAdditionalProperties())) {
property.setAdditionalPropertiesIsAnyType(true);
}
}
if (m != null && isAdditionalPropertiesTrue) {
m.isAdditionalPropertiesTrue = true;
}
}


/**
* Recursively look in Schema sc for the discriminator discPropName
* and return a CodegenProperty with the dataType and required params set
* the returned CodegenProperty may not be required and it may not be of type string
*
* @param composedSchemaName The name of the sc Schema
* @param sc The Schema that may contain the discriminator
* @param discPropName The String that is the discriminator propertyName in the schema
*/
private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc, String discPropName, OpenAPI openAPI) {
Schema refSchema = ModelUtils.getReferencedSchema(openAPI, sc);
if (refSchema.getProperties() != null && refSchema.getProperties().get(discPropName) != null) {
Expand Down Expand Up @@ -6134,20 +6147,7 @@ private void addVarsRequiredVarsAdditionalProps(Schema schema, IJsonSchemaValida
.filter(p -> Boolean.TRUE.equals(p.required)).collect(Collectors.toList());
property.setRequiredVars(requireCpVars);
}
if (schema.getAdditionalProperties() == null) {
if (!disallowAdditionalPropertiesIfNotPresent) {
CodegenProperty cp = fromProperty("", new Schema());
property.setAdditionalProperties(cp);
}
} else if (schema.getAdditionalProperties() instanceof Boolean) {
if (Boolean.TRUE.equals(schema.getAdditionalProperties())) {
CodegenProperty cp = fromProperty("", new Schema());
property.setAdditionalProperties(cp);
}
} else {
CodegenProperty cp = fromProperty("", (Schema) schema.getAdditionalProperties());
property.setAdditionalProperties(cp);
}
setAddProps(schema, property);
}

private void addJsonSchemaForBodyRequestInCaseItsNotPresent(CodegenParameter codegenParameter, RequestBody body) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ public interface IJsonSchemaValidationProperties {
boolean getHasValidation();

void setHasValidation(boolean hasValidation);
}

boolean getAdditionalPropertiesIsAnyType();

void setAdditionalPropertiesIsAnyType(boolean additionalPropertiesIsAnyType);
}
Loading