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

Change/remove seperate unique items wrapper boolean type #18564

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {

private Integer maxProperties;
private Integer minProperties;
private boolean uniqueItems;
private Boolean uniqueItemsBoolean;
private Boolean uniqueItems;
private Integer maxItems;
private Integer minItems;
private Integer maxLength;
Expand Down Expand Up @@ -642,25 +641,15 @@ public void setMaxItems(Integer maxItems) {
}

@Override
public boolean getUniqueItems() {
public Boolean getUniqueItems() {
return uniqueItems;
}

@Override
public void setUniqueItems(boolean uniqueItems) {
public void setUniqueItems(Boolean uniqueItems) {
this.uniqueItems = uniqueItems;
}

@Override
public Boolean getUniqueItemsBoolean() {
return uniqueItemsBoolean;
}

@Override
public void setUniqueItemsBoolean(Boolean uniqueItemsBoolean) {
this.uniqueItemsBoolean = uniqueItemsBoolean;
}

@Override
public Integer getMinProperties() {
return minProperties;
Expand Down Expand Up @@ -1143,13 +1132,12 @@ public boolean equals(Object o) {
getSchemaIsFromAdditionalProperties() == that.getSchemaIsFromAdditionalProperties() &&
getIsAnyType() == that.getIsAnyType() &&
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
getUniqueItems() == that.getUniqueItems() &&
Objects.equals(getUniqueItems(), that.getUniqueItems()) &&
getExclusiveMinimum() == that.getExclusiveMinimum() &&
getExclusiveMaximum() == that.getExclusiveMaximum() &&
Objects.equals(contains, that.getContains()) &&
Objects.equals(dependentRequired, that.getDependentRequired()) &&
Objects.equals(format, that.getFormat()) &&
Objects.equals(uniqueItemsBoolean, that.getUniqueItemsBoolean()) &&
Objects.equals(ref, that.getRef()) &&
Objects.equals(requiredVarsMap, that.getRequiredVarsMap()) &&
Objects.equals(composedSchemas, that.composedSchemas) &&
Expand Down Expand Up @@ -1227,7 +1215,7 @@ hasChildren, isMap, isDeprecated, hasReadOnly, hasOnlyReadOnly, getExternalDocum
getMaximum(), getPattern(), getMultipleOf(), getItems(), getAdditionalProperties(), getIsModel(),
getAdditionalPropertiesIsAnyType(), hasDiscriminatorWithNonEmptyMapping,
isAnyType, getComposedSchemas(), hasMultipleTypes, isDecimal, isUuid, isUri, requiredVarsMap, ref,
uniqueItemsBoolean, schemaIsFromAdditionalProperties, isBooleanSchemaTrue, isBooleanSchemaFalse,
schemaIsFromAdditionalProperties, isBooleanSchemaTrue, isBooleanSchemaFalse,
format, dependentRequired, contains);
}

Expand Down Expand Up @@ -1306,7 +1294,6 @@ public String toString() {
sb.append(", maxProperties=").append(maxProperties);
sb.append(", minProperties=").append(minProperties);
sb.append(", uniqueItems=").append(uniqueItems);
sb.append(", uniqueItemsBoolean=").append(uniqueItemsBoolean);
sb.append(", maxItems=").append(maxItems);
sb.append(", minItems=").append(minItems);
sb.append(", maxLength=").append(maxLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
/**
* See http://json-schema.org/latest/json-schema-validation.html#anchor49
*/
public boolean uniqueItems;
private Boolean uniqueItemsBoolean;
public Boolean uniqueItems;
/**
* See http://json-schema.org/latest/json-schema-validation.html#anchor14
*/
Expand Down Expand Up @@ -170,7 +169,6 @@ public CodegenParameter copy() {
output.maxItems = this.maxItems;
output.minItems = this.minItems;
output.uniqueItems = this.uniqueItems;
output.setUniqueItemsBoolean(this.uniqueItemsBoolean);
output.multipleOf = this.multipleOf;
output.jsonSchema = this.jsonSchema;
output.defaultValue = this.defaultValue;
Expand Down Expand Up @@ -287,7 +285,7 @@ public int hashCode() {
getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull,isVoid,
additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger,
hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, schema, content,
requiredVarsMap, ref, uniqueItemsBoolean, schemaIsFromAdditionalProperties,
requiredVarsMap, ref, schemaIsFromAdditionalProperties,
nameInPascalCase, nameInCamelCase, nameInLowerCase, nameInSnakeCase);
}

Expand Down Expand Up @@ -347,8 +345,7 @@ public boolean equals(Object o) {
getHasRequired() == that.getHasRequired() &&
getExclusiveMaximum() == that.getExclusiveMaximum() &&
getExclusiveMinimum() == that.getExclusiveMinimum() &&
getUniqueItems() == that.getUniqueItems() &&
Objects.equals(uniqueItemsBoolean, that.getUniqueItemsBoolean()) &&
Objects.equals(getUniqueItems(), that.getUniqueItems()) &&
Objects.equals(ref, that.getRef()) &&
Objects.equals(requiredVarsMap, that.getRequiredVarsMap()) &&
Objects.equals(content, that.getContent()) &&
Expand Down Expand Up @@ -490,7 +487,6 @@ public String toString() {
sb.append(", maxItems=").append(maxItems);
sb.append(", minItems=").append(minItems);
sb.append(", uniqueItems=").append(uniqueItems);
sb.append(", uniqueItemsBoolean=").append(uniqueItemsBoolean);
sb.append(", contentType=").append(contentType);
sb.append(", multipleOf=").append(multipleOf);
sb.append(", isNull=").append(isNull);
Expand Down Expand Up @@ -656,25 +652,15 @@ public void setMaxItems(Integer maxItems) {
}

@Override
public boolean getUniqueItems() {
public Boolean getUniqueItems() {
return uniqueItems;
}

@Override
public void setUniqueItems(boolean uniqueItems) {
public void setUniqueItems(Boolean uniqueItems) {
this.uniqueItems = uniqueItems;
}

@Override
public Boolean getUniqueItemsBoolean() {
return uniqueItemsBoolean;
}

@Override
public void setUniqueItemsBoolean(Boolean uniqueItemsBoolean) {
this.uniqueItemsBoolean = uniqueItemsBoolean;
}

@Override
public Integer getMinProperties() {
return minProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti

private Integer maxProperties;
private Integer minProperties;
private boolean uniqueItems;
private Boolean uniqueItemsBoolean;
private Boolean uniqueItems;

// XML
public boolean isXmlAttribute = false;
Expand Down Expand Up @@ -837,25 +836,15 @@ public CodegenProperty clone() {
}

@Override
public boolean getUniqueItems() {
public Boolean getUniqueItems() {
return uniqueItems;
}

@Override
public void setUniqueItems(boolean uniqueItems) {
public void setUniqueItems(Boolean uniqueItems) {
this.uniqueItems = uniqueItems;
}

@Override
public Boolean getUniqueItemsBoolean() {
return uniqueItemsBoolean;
}

@Override
public void setUniqueItemsBoolean(Boolean uniqueItemsBoolean) {
this.uniqueItemsBoolean = uniqueItemsBoolean;
}

@Override
public Integer getMinProperties() {
return minProperties;
Expand Down Expand Up @@ -1232,7 +1221,6 @@ public String toString() {
sb.append(", maxProperties=").append(maxProperties);
sb.append(", minProperties=").append(minProperties);
sb.append(", uniqueItems=").append(uniqueItems);
sb.append(", uniqueItemsBoolean=").append(uniqueItemsBoolean);
sb.append(", multipleOf=").append(multipleOf);
sb.append(", isXmlAttribute=").append(isXmlAttribute);
sb.append(", xmlPrefix='").append(xmlPrefix).append('\'');
Expand Down Expand Up @@ -1324,7 +1312,6 @@ public boolean equals(Object o) {
Objects.equals(contains, that.getContains()) &&
Objects.equals(dependentRequired, that.getDependentRequired()) &&
Objects.equals(format, that.getFormat()) &&
Objects.equals(uniqueItemsBoolean, that.getUniqueItemsBoolean()) &&
Objects.equals(ref, that.getRef()) &&
Objects.equals(requiredVarsMap, that.getRequiredVarsMap()) &&
Objects.equals(composedSchemas, that.composedSchemas) &&
Expand Down Expand Up @@ -1393,7 +1380,7 @@ public int hashCode() {
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName,
xmlNamespace, isXmlWrapped, isNull, isVoid, additionalPropertiesIsAnyType, hasVars, hasRequired,
hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, requiredVarsMap,
ref, uniqueItemsBoolean, schemaIsFromAdditionalProperties, isBooleanSchemaTrue, isBooleanSchemaFalse,
ref, schemaIsFromAdditionalProperties, isBooleanSchemaTrue, isBooleanSchemaFalse,
format, dependentRequired, contains);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
private Integer maxProperties;
private Integer minProperties;
private boolean uniqueItems;
private Boolean uniqueItemsBoolean;
private Boolean uniqueItems;
private Integer maxItems;
private Integer minItems;
private Integer maxLength;
Expand Down Expand Up @@ -109,7 +108,7 @@ public int hashCode() {
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern(),
is1xx, is2xx, is3xx, is4xx, is5xx, additionalPropertiesIsAnyType, hasVars, hasRequired,
hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, responseHeaders, content,
requiredVarsMap, ref, uniqueItemsBoolean, schemaIsFromAdditionalProperties);
requiredVarsMap, ref, schemaIsFromAdditionalProperties);
}

@Override
Expand Down Expand Up @@ -161,7 +160,6 @@ public boolean equals(Object o) {
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
getHasVars() == that.getHasVars() &&
getHasRequired() == that.getHasRequired() &&
Objects.equals(uniqueItemsBoolean, that.getUniqueItemsBoolean()) &&
Objects.equals(ref, that.getRef()) &&
Objects.equals(requiredVarsMap, that.getRequiredVarsMap()) &&
Objects.equals(content, that.getContent()) &&
Expand Down Expand Up @@ -353,26 +351,15 @@ public void setMaxItems(Integer maxItems) {
}

@Override
public boolean getUniqueItems() {
public Boolean getUniqueItems() {
return uniqueItems;
}

@Override
public void setUniqueItems(boolean uniqueItems) {
public void setUniqueItems(Boolean uniqueItems) {
this.uniqueItems = uniqueItems;
}

@Override
public Boolean getUniqueItemsBoolean() {
return uniqueItemsBoolean;
}

@Override
public void setUniqueItemsBoolean(Boolean uniqueItemsBoolean) {
this.uniqueItemsBoolean = uniqueItemsBoolean;
}


@Override
public Integer getMinProperties() {
return minProperties;
Expand Down Expand Up @@ -603,7 +590,6 @@ public String toString() {
sb.append(", maxProperties=").append(maxProperties);
sb.append(", minProperties=").append(minProperties);
sb.append(", uniqueItems=").append(uniqueItems);
sb.append(", uniqueItemsBoolean=").append(uniqueItemsBoolean);
sb.append(", maxItems=").append(maxItems);
sb.append(", minItems=").append(minItems);
sb.append(", maxLength=").append(maxLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6102,7 +6102,7 @@ protected void addVars(IJsonSchemaValidationProperties m, List<CodegenProperty>
*/
protected void addImportsForPropertyType(CodegenModel model, CodegenProperty property) {
if (property.isArray) {
if (Boolean.TRUE.equals(property.getUniqueItemsBoolean())) { // set
if (Boolean.TRUE.equals(property.getUniqueItems())) { // set
addImport(model.imports, typeMapping.get("set"));
} else { // array
addImport(model.imports, typeMapping.get("array"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,9 @@ public interface IJsonSchemaValidationProperties {

void setMaxItems(Integer maxItems);

// TODO update this value to Boolean in 7.0.0
boolean getUniqueItems();
Boolean getUniqueItems();

// TODO update this value to Boolean in 7.0.0
void setUniqueItems(boolean uniqueItems);

// TODO remove in 7.0.0
Boolean getUniqueItemsBoolean();

// TODO remove in 7.0.0
void setUniqueItemsBoolean(Boolean uniqueItems);
void setUniqueItems(Boolean uniqueItems);

Integer getMinProperties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ private PythonType arrayType(IJsonSchemaValidationProperties cp) {
if (cp.getMinItems()!= null) {
pt.constrain("min_length", cp.getMinItems());
}
if (cp.getUniqueItems()) {
if (Boolean.TRUE.equals(cp.getUniqueItems())) {
// A unique "array" is a set
// TODO: pydantic v2: Pydantic suggest to convert this to a set, but this has some implications:
// https://github.com/pydantic/pydantic-core/issues/296
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ private String getPydanticType(CodegenParameter cp,
if (cp.minItems != null) {
constraints += String.format(Locale.ROOT, ", min_items=%d", cp.minItems);
}
if (cp.getUniqueItems()) {
if (Boolean.TRUE.equals(cp.getUniqueItems())) {
constraints += ", unique_items=True";
}
pydanticImports.add("conlist");
Expand Down Expand Up @@ -1364,7 +1364,7 @@ private String getPydanticType(CodegenProperty cp,
if (cp.minItems != null) {
constraints += String.format(Locale.ROOT, ", min_items=%d", cp.minItems);
}
if (cp.getUniqueItems()) {
if (Boolean.TRUE.equals(cp.getUniqueItems())) {
constraints += ", unique_items=True";
}
pydanticImports.add("conlist");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
if (items.getAdditionalProperties() != null) {
addBuiltValueSerializer(new BuiltValueSerializer(
items.isArray,
items.getUniqueItems(),
Boolean.TRUE.equals(items.getUniqueItems()),
items.isMap,
items.items.isNullable,
items.getAdditionalProperties().dataType
Expand Down Expand Up @@ -665,7 +665,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
if (param.isContainer && !(param.isBinary || param.isFile)) {
addBuiltValueSerializer(new BuiltValueSerializer(
param.isArray,
param.uniqueItems,
Boolean.TRUE.equals(param.uniqueItems),
param.isMap,
param.items.isNullable,
param.baseType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ private static String defaultValue(IJsonSchemaValidationProperties p, boolean re

private static String defaultValueNonOption(IJsonSchemaValidationProperties p, String fallbackDefaultValue) {
if (p.getIsArray()) {
if (p.getUniqueItems()) {
if (Boolean.TRUE.equals(p.getUniqueItems())) {
return "Set.empty";
}
return "Nil";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ protected void addVendorExtensions(CodegenParameter cp, CodegenOperation operati
String newDataType = WordUtils.capitalize(operation.operationId) + WordUtils.capitalize(cp.enumName);
cp.vendorExtensions.put("x-swift-nested-enum-type", newDataType);
if (cp.isArray) {
if (cp.uniqueItems) {
if (Boolean.TRUE.equals(cp.uniqueItems)) {
cp.dataType = "Set<" + newDataType + ">";
} else {
cp.dataType = "[" + newDataType + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,6 @@ private static void setArrayValidations(Integer minItems, Integer maxItems, Bool
if (minItems != null) target.setMinItems(minItems);
if (maxItems != null) target.setMaxItems(maxItems);
if (uniqueItems != null) target.setUniqueItems(uniqueItems);
if (uniqueItems != null) target.setUniqueItemsBoolean(uniqueItems);
}

private static void setObjectValidations(Integer minProperties, Integer maxProperties, IJsonSchemaValidationProperties target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public void complexSetPropertyTest() {
Assert.assertEquals(property.containerType, "set");
Assert.assertFalse(property.required);
Assert.assertTrue(property.isContainer);
Assert.assertTrue(property.getUniqueItemsBoolean());
Assert.assertTrue(property.getUniqueItems());
}
@Test(description = "convert a model with an array property with item name")
public void arrayModelWithItemNameTest() {
Expand Down