Skip to content

Commit a925c76

Browse files
authored
Adds hasRequired to all Java schema classes (#8962)
* Adds getHasRequiredVars + setHasRequiredVars to IJsonSchemaValidationProperties * CHanges to getHasRequired and setHasRequired and implements in CodegenModel * Updates CodegenProperty * Updates codegenparameter * Updates codegenresponse * Uses setHasRequired in model/prop/parameter/response * Adds issue spec 8906 * Adds testHasRequiredInModel * Adds testHasRequiredInProperties * Fixes issue spec errors * Adds sample endpoint with schemas in patch parameter * Adds testHasRequiredInParameters * Adds response schemas in issue spec * Samples and docs regenerated
1 parent 2367460 commit a925c76

File tree

9 files changed

+853
-6
lines changed

9 files changed

+853
-6
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
154154
private CodegenProperty items;
155155
private CodegenProperty additionalProperties;
156156
private boolean isModel;
157+
private boolean hasRequiredVars;
157158

158159
public String getAdditionalPropertiesType() {
159160
return additionalPropertiesType;
@@ -733,6 +734,16 @@ public void setHasVars(boolean hasVars) {
733734
this.hasVars = hasVars;
734735
}
735736

737+
@Override
738+
public boolean getHasRequired() {
739+
return this.hasRequired;
740+
}
741+
742+
@Override
743+
public void setHasRequired(boolean hasRequired) {
744+
this.hasRequired = hasRequired;
745+
}
746+
736747
@Override
737748
public boolean equals(Object o) {
738749
if (this == o) return true;

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
104104
private Integer maxProperties;
105105
private Integer minProperties;
106106
public boolean isNull;
107+
private boolean hasRequired;
107108

108109
public CodegenParameter copy() {
109110
CodegenParameter output = new CodegenParameter();
@@ -153,6 +154,7 @@ public CodegenParameter copy() {
153154
output.isNull = this.isNull;
154155
output.setAdditionalPropertiesIsAnyType(this.getAdditionalPropertiesIsAnyType());
155156
output.setHasVars(this.hasVars);
157+
output.setHasRequired(this.hasRequired);
156158

157159
if (this._enum != null) {
158160
output._enum = new ArrayList<String>(this._enum);
@@ -207,7 +209,7 @@ public CodegenParameter copy() {
207209

208210
@Override
209211
public int hashCode() {
210-
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);
212+
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);
211213
}
212214

213215
@Override
@@ -254,6 +256,7 @@ public boolean equals(Object o) {
254256
isNull == that.isNull &&
255257
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
256258
getHasVars() == that.getHasVars() &&
259+
getHasRequired() == that.getHasRequired() &&
257260
getExclusiveMaximum() == that.getExclusiveMaximum() &&
258261
getExclusiveMinimum() == that.getExclusiveMinimum() &&
259262
getUniqueItems() == that.getUniqueItems() &&
@@ -372,6 +375,7 @@ public String toString() {
372375
sb.append(", isNull=").append(isNull);
373376
sb.append(", getAdditionalPropertiesIsAnyType=").append(additionalPropertiesIsAnyType);
374377
sb.append(", getHasVars=").append(hasVars);
378+
sb.append(", getHasRequired=").append(hasRequired);
375379
sb.append('}');
376380
return sb.toString();
377381
}
@@ -619,5 +623,15 @@ public boolean getHasVars() {
619623
public void setHasVars(boolean hasVars) {
620624
this.hasVars = hasVars;
621625
}
626+
627+
@Override
628+
public boolean getHasRequired() {
629+
return this.hasRequired;
630+
}
631+
632+
@Override
633+
public void setHasRequired(boolean hasRequired) {
634+
this.hasRequired = hasRequired;
635+
}
622636
}
623637

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
187187
public boolean isXmlWrapped = false;
188188
private boolean additionalPropertiesIsAnyType;
189189
private boolean hasVars;
190+
private boolean hasRequired;
190191

191192
public String getBaseName() {
192193
return baseName;
@@ -715,6 +716,16 @@ public void setHasVars(boolean hasVars) {
715716
this.hasVars = hasVars;
716717
}
717718

719+
@Override
720+
public boolean getHasRequired() {
721+
return this.hasRequired;
722+
}
723+
724+
@Override
725+
public void setHasRequired(boolean hasRequired) {
726+
this.hasRequired = hasRequired;
727+
}
728+
718729
@Override
719730
public String toString() {
720731
final StringBuilder sb = new StringBuilder("CodegenProperty{");
@@ -806,6 +817,7 @@ public String toString() {
806817
sb.append(", isNull=").append(isNull);
807818
sb.append(", getAdditionalPropertiesIsAnyType=").append(getAdditionalPropertiesIsAnyType());
808819
sb.append(", getHasVars=").append(getHasVars());
820+
sb.append(", getHasRequired=").append(getHasRequired());
809821
sb.append('}');
810822
return sb.toString();
811823
}
@@ -857,6 +869,7 @@ public boolean equals(Object o) {
857869
isNull == that.isNull &&
858870
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
859871
getHasVars() == that.getHasVars() &&
872+
getHasRequired() ==that.getHasRequired() &&
860873
Objects.equals(openApiType, that.openApiType) &&
861874
Objects.equals(baseName, that.baseName) &&
862875
Objects.equals(complexType, that.complexType) &&
@@ -918,6 +931,6 @@ public int hashCode() {
918931
items, mostInnerItems, additionalProperties, vars, requiredVars,
919932
vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase,
920933
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName,
921-
xmlNamespace, isXmlWrapped, isNull, additionalPropertiesIsAnyType, hasVars);
934+
xmlNamespace, isXmlWrapped, isNull, additionalPropertiesIsAnyType, hasVars, hasRequired);
922935
}
923936
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenResponse.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
8181
private boolean hasValidation;
8282
private boolean additionalPropertiesIsAnyType;
8383
private boolean hasVars;
84+
private boolean hasRequired;
8485

8586
@Override
8687
public int hashCode() {
@@ -91,7 +92,7 @@ public int hashCode() {
9192
vars, requiredVars, isNull, hasValidation,
9293
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
9394
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern(),
94-
is1xx, is2xx, is3xx, is4xx, is5xx, additionalPropertiesIsAnyType, hasVars);
95+
is1xx, is2xx, is3xx, is4xx, is5xx, additionalPropertiesIsAnyType, hasVars, hasRequired);
9596
}
9697

9798
@Override
@@ -135,6 +136,7 @@ public boolean equals(Object o) {
135136
is5xx == that.is5xx &&
136137
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
137138
getHasVars() == that.getHasVars() &&
139+
getHasRequired() == that.getHasRequired() &&
138140
Objects.equals(vars, that.vars) &&
139141
Objects.equals(requiredVars, that.requiredVars) &&
140142
Objects.equals(headers, that.headers) &&
@@ -371,6 +373,16 @@ public void setRequiredVars(List<CodegenProperty> requiredVars) {
371373
this.requiredVars = requiredVars;
372374
}
373375

376+
@Override
377+
public boolean getHasRequired() {
378+
return this.hasRequired;
379+
}
380+
381+
@Override
382+
public void setHasRequired(boolean hasRequired) {
383+
this.hasRequired = hasRequired;
384+
}
385+
374386
@Override
375387
public String toString() {
376388
final StringBuilder sb = new StringBuilder("CodegenResponse{");
@@ -435,6 +447,7 @@ public String toString() {
435447
sb.append(", hasValidation='").append(hasValidation);
436448
sb.append(", getAdditionalPropertiesIsAnyType=").append(additionalPropertiesIsAnyType);
437449
sb.append(", getHasVars=").append(hasVars);
450+
sb.append(", getHasRequired=").append(hasRequired);
438451
sb.append('}');
439452
return sb.toString();
440453
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,6 +2579,10 @@ public CodegenModel fromModel(String name, Schema schema) {
25792579
}
25802580
}
25812581

2582+
if (m.requiredVars != null && m.requiredVars.size() > 0){
2583+
m.setHasRequired(true);
2584+
}
2585+
25822586
if (sortModelPropertiesByRequiredFlag) {
25832587
Comparator<CodegenProperty> comparator = new Comparator<CodegenProperty>() {
25842588
@Override
@@ -6170,6 +6174,9 @@ private void addVarsRequiredVarsAdditionalProps(Schema schema, IJsonSchemaValida
61706174
.stream()
61716175
.filter(p -> Boolean.TRUE.equals(p.required)).collect(Collectors.toList());
61726176
property.setRequiredVars(requireCpVars);
6177+
if (property.getRequiredVars() != null && property.getRequiredVars().size() > 0) {
6178+
property.setHasRequired(true);
6179+
}
61736180
}
61746181
setAddProps(schema, property);
61756182
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/IJsonSchemaValidationProperties.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,9 @@ public interface IJsonSchemaValidationProperties {
105105

106106
boolean getHasVars();
107107

108-
void setHasVars(boolean hasVars);
108+
void setHasVars(boolean hasRequiredVars);
109+
110+
boolean getHasRequired();
111+
112+
void setHasRequired(boolean hasRequired);
109113
}

0 commit comments

Comments
 (0)