Skip to content

Commit

Permalink
fix(specs): built-in ops accept also int (#3450)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
kai687 and millotp committed Jul 31, 2024
1 parent dfb2aa7 commit e982ddf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private Map<String, Object> traverseParams(
handleEnum(param, testOutput);
} else if (spec.getIsModel() || isCodegenModel) {
// recursive object
handleModel(paramName, param, testOutput, spec, baseType, parent, depth, isParentFreeFormObject);
handleModel(paramName, param, testOutput, spec, baseType, parent, depth, isParentFreeFormObject, isRequired != null && isRequired);
} else if (baseType.equals("Object")) {
// not var, no item, pure free form
handleObject(paramName, param, testOutput, true, depth);
Expand Down Expand Up @@ -259,7 +259,8 @@ private void handleModel(
String baseType,
String parent,
int depth,
boolean isParentFreeFormObject
boolean isParentFreeFormObject,
boolean parentIsRequired
) throws CTSException {
if (!spec.getHasVars()) {
// In this case we might have a complex `allOf`, we will first check if it exists
Expand Down Expand Up @@ -326,6 +327,8 @@ private void handleModel(
oneOfModel.put("x-one-of-explicit-name", useExplicitName);
oneOfModel.put("hasWrapper", isList || isString(current) || current.getIsNumber() || current.getIsBoolean());
testOutput.put("oneOfModel", oneOfModel);
// use required from the parent since oneOf don't have that property
testOutput.put("required", parentIsRequired);
return;
}

Expand Down
10 changes: 8 additions & 2 deletions specs/search/paths/objects/common/schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ builtInOperationType:
- IncrementSet
description: How to change the attribute.

builtInOperationValue:
oneOf:
- type: string
description: A string to append or remove for the `Add`, `Remove`, and `AddUnique` operations.
- type: integer
description: A number to add, remove, or append, depending on the operation.

attribute:
type: string
description: Value of the attribute to update.
Expand All @@ -22,8 +29,7 @@ builtInOperation:
_operation:
$ref: '#/builtInOperationType'
value:
type: string
description: Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value.
$ref: '#/builtInOperationValue'
required:
- _operation
- value
Expand Down
24 changes: 24 additions & 0 deletions tests/CTS/requests/search/partialUpdateObject.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
{
"testName": "Partial update with string value",
"parameters": {
"indexName": "theIndexName",
"objectID": "uniqueID",
Expand All @@ -26,5 +27,28 @@
"createIfNotExists": "true"
}
}
},
{
"testName": "Partial update with integer value",
"parameters": {
"indexName": "theIndexName",
"objectID": "uniqueID",
"attributesToUpdate": {
"attributeId": {
"_operation": "Increment",
"value": 2
}
}
},
"request": {
"path": "/1/indexes/theIndexName/uniqueID/partial",
"method": "POST",
"body": {
"attributeId": {
"_operation": "Increment",
"value": 2
}
}
}
}
]

0 comments on commit e982ddf

Please sign in to comment.