Skip to content

Commit e982ddf

Browse files
kai687millotp
andauthored
fix(specs): built-in ops accept also int (#3450)
Co-authored-by: Pierre Millot <[email protected]>
1 parent dfb2aa7 commit e982ddf

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private Map<String, Object> traverseParams(
146146
handleEnum(param, testOutput);
147147
} else if (spec.getIsModel() || isCodegenModel) {
148148
// recursive object
149-
handleModel(paramName, param, testOutput, spec, baseType, parent, depth, isParentFreeFormObject);
149+
handleModel(paramName, param, testOutput, spec, baseType, parent, depth, isParentFreeFormObject, isRequired != null && isRequired);
150150
} else if (baseType.equals("Object")) {
151151
// not var, no item, pure free form
152152
handleObject(paramName, param, testOutput, true, depth);
@@ -259,7 +259,8 @@ private void handleModel(
259259
String baseType,
260260
String parent,
261261
int depth,
262-
boolean isParentFreeFormObject
262+
boolean isParentFreeFormObject,
263+
boolean parentIsRequired
263264
) throws CTSException {
264265
if (!spec.getHasVars()) {
265266
// In this case we might have a complex `allOf`, we will first check if it exists
@@ -326,6 +327,8 @@ private void handleModel(
326327
oneOfModel.put("x-one-of-explicit-name", useExplicitName);
327328
oneOfModel.put("hasWrapper", isList || isString(current) || current.getIsNumber() || current.getIsBoolean());
328329
testOutput.put("oneOfModel", oneOfModel);
330+
// use required from the parent since oneOf don't have that property
331+
testOutput.put("required", parentIsRequired);
329332
return;
330333
}
331334

specs/search/paths/objects/common/schemas.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ builtInOperationType:
1010
- IncrementSet
1111
description: How to change the attribute.
1212

13+
builtInOperationValue:
14+
oneOf:
15+
- type: string
16+
description: A string to append or remove for the `Add`, `Remove`, and `AddUnique` operations.
17+
- type: integer
18+
description: A number to add, remove, or append, depending on the operation.
19+
1320
attribute:
1421
type: string
1522
description: Value of the attribute to update.
@@ -22,8 +29,7 @@ builtInOperation:
2229
_operation:
2330
$ref: '#/builtInOperationType'
2431
value:
25-
type: string
26-
description: Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value.
32+
$ref: '#/builtInOperationValue'
2733
required:
2834
- _operation
2935
- value

tests/CTS/requests/search/partialUpdateObject.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[
22
{
3+
"testName": "Partial update with string value",
34
"parameters": {
45
"indexName": "theIndexName",
56
"objectID": "uniqueID",
@@ -26,5 +27,28 @@
2627
"createIfNotExists": "true"
2728
}
2829
}
30+
},
31+
{
32+
"testName": "Partial update with integer value",
33+
"parameters": {
34+
"indexName": "theIndexName",
35+
"objectID": "uniqueID",
36+
"attributesToUpdate": {
37+
"attributeId": {
38+
"_operation": "Increment",
39+
"value": 2
40+
}
41+
}
42+
},
43+
"request": {
44+
"path": "/1/indexes/theIndexName/uniqueID/partial",
45+
"method": "POST",
46+
"body": {
47+
"attributeId": {
48+
"_operation": "Increment",
49+
"value": 2
50+
}
51+
}
52+
}
2953
}
3054
]

0 commit comments

Comments
 (0)