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 hasRequired to all Java schema classes #8962

Merged
merged 14 commits into from
Mar 19, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
private CodegenProperty items;
private CodegenProperty additionalProperties;
private boolean isModel;
private boolean hasRequiredVars;

public String getAdditionalPropertiesType() {
return additionalPropertiesType;
Expand Down Expand Up @@ -733,6 +734,16 @@ public void setHasVars(boolean hasVars) {
this.hasVars = hasVars;
}

@Override
public boolean getHasRequired() {
return this.hasRequired;
}

@Override
public void setHasRequired(boolean hasRequired) {
this.hasRequired = hasRequired;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
private Integer maxProperties;
private Integer minProperties;
public boolean isNull;
private boolean hasRequired;

public CodegenParameter copy() {
CodegenParameter output = new CodegenParameter();
Expand Down Expand Up @@ -153,6 +154,7 @@ public CodegenParameter copy() {
output.isNull = this.isNull;
output.setAdditionalPropertiesIsAnyType(this.getAdditionalPropertiesIsAnyType());
output.setHasVars(this.hasVars);
output.setHasRequired(this.hasRequired);

if (this._enum != null) {
output._enum = new ArrayList<String>(this._enum);
Expand Down Expand Up @@ -207,7 +209,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, additionalPropertiesIsAnyType, hasVars);
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, additionalPropertiesIsAnyType, hasVars, hasRequired);
}

@Override
Expand Down Expand Up @@ -254,6 +256,7 @@ public boolean equals(Object o) {
isNull == that.isNull &&
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
getHasVars() == that.getHasVars() &&
getHasRequired() == that.getHasRequired() &&
getExclusiveMaximum() == that.getExclusiveMaximum() &&
getExclusiveMinimum() == that.getExclusiveMinimum() &&
getUniqueItems() == that.getUniqueItems() &&
Expand Down Expand Up @@ -372,6 +375,7 @@ public String toString() {
sb.append(", isNull=").append(isNull);
sb.append(", getAdditionalPropertiesIsAnyType=").append(additionalPropertiesIsAnyType);
sb.append(", getHasVars=").append(hasVars);
sb.append(", getHasRequired=").append(hasRequired);
sb.append('}');
return sb.toString();
}
Expand Down Expand Up @@ -619,5 +623,15 @@ public boolean getHasVars() {
public void setHasVars(boolean hasVars) {
this.hasVars = hasVars;
}

@Override
public boolean getHasRequired() {
return this.hasRequired;
}

@Override
public void setHasRequired(boolean hasRequired) {
this.hasRequired = hasRequired;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
public boolean isXmlWrapped = false;
private boolean additionalPropertiesIsAnyType;
private boolean hasVars;
private boolean hasRequired;

public String getBaseName() {
return baseName;
Expand Down Expand Up @@ -715,6 +716,16 @@ public void setHasVars(boolean hasVars) {
this.hasVars = hasVars;
}

@Override
public boolean getHasRequired() {
return this.hasRequired;
}

@Override
public void setHasRequired(boolean hasRequired) {
this.hasRequired = hasRequired;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CodegenProperty{");
Expand Down Expand Up @@ -806,6 +817,7 @@ public String toString() {
sb.append(", isNull=").append(isNull);
sb.append(", getAdditionalPropertiesIsAnyType=").append(getAdditionalPropertiesIsAnyType());
sb.append(", getHasVars=").append(getHasVars());
sb.append(", getHasRequired=").append(getHasRequired());
sb.append('}');
return sb.toString();
}
Expand Down Expand Up @@ -857,6 +869,7 @@ public boolean equals(Object o) {
isNull == that.isNull &&
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
getHasVars() == that.getHasVars() &&
getHasRequired() ==that.getHasRequired() &&
Objects.equals(openApiType, that.openApiType) &&
Objects.equals(baseName, that.baseName) &&
Objects.equals(complexType, that.complexType) &&
Expand Down Expand Up @@ -918,6 +931,6 @@ public int hashCode() {
items, mostInnerItems, additionalProperties, vars, requiredVars,
vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase,
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName,
xmlNamespace, isXmlWrapped, isNull, additionalPropertiesIsAnyType, hasVars);
xmlNamespace, isXmlWrapped, isNull, additionalPropertiesIsAnyType, hasVars, hasRequired);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
private boolean hasValidation;
private boolean additionalPropertiesIsAnyType;
private boolean hasVars;
private boolean hasRequired;

@Override
public int hashCode() {
Expand All @@ -91,7 +92,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, additionalPropertiesIsAnyType, hasVars);
is1xx, is2xx, is3xx, is4xx, is5xx, additionalPropertiesIsAnyType, hasVars, hasRequired);
}

@Override
Expand Down Expand Up @@ -135,6 +136,7 @@ public boolean equals(Object o) {
is5xx == that.is5xx &&
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
getHasVars() == that.getHasVars() &&
getHasRequired() == that.getHasRequired() &&
Objects.equals(vars, that.vars) &&
Objects.equals(requiredVars, that.requiredVars) &&
Objects.equals(headers, that.headers) &&
Expand Down Expand Up @@ -371,6 +373,16 @@ public void setRequiredVars(List<CodegenProperty> requiredVars) {
this.requiredVars = requiredVars;
}

@Override
public boolean getHasRequired() {
return this.hasRequired;
}

@Override
public void setHasRequired(boolean hasRequired) {
this.hasRequired = hasRequired;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CodegenResponse{");
Expand Down Expand Up @@ -435,6 +447,7 @@ public String toString() {
sb.append(", hasValidation='").append(hasValidation);
sb.append(", getAdditionalPropertiesIsAnyType=").append(additionalPropertiesIsAnyType);
sb.append(", getHasVars=").append(hasVars);
sb.append(", getHasRequired=").append(hasRequired);
sb.append('}');
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2565,6 +2565,10 @@ public CodegenModel fromModel(String name, Schema schema) {
}
}

if (m.requiredVars != null && m.requiredVars.size() > 0){
m.setHasRequired(true);
}

if (sortModelPropertiesByRequiredFlag) {
Comparator<CodegenProperty> comparator = new Comparator<CodegenProperty>() {
@Override
Expand Down Expand Up @@ -6149,6 +6153,9 @@ private void addVarsRequiredVarsAdditionalProps(Schema schema, IJsonSchemaValida
.stream()
.filter(p -> Boolean.TRUE.equals(p.required)).collect(Collectors.toList());
property.setRequiredVars(requireCpVars);
if (property.getRequiredVars() != null && property.getRequiredVars().size() > 0) {
property.setHasRequired(true);
}
}
setAddProps(schema, property);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,9 @@ public interface IJsonSchemaValidationProperties {

boolean getHasVars();

void setHasVars(boolean hasVars);
void setHasVars(boolean hasRequiredVars);

boolean getHasRequired();

void setHasRequired(boolean hasRequired);
}
Loading