From e982ddf0a654db3ea84c908afe7ba35289d9ab2c Mon Sep 17 00:00:00 2001 From: Kai Welke Date: Wed, 31 Jul 2024 11:34:43 +0200 Subject: [PATCH] fix(specs): built-in ops accept also int (#3450) Co-authored-by: Pierre Millot --- .../cts/tests/ParametersWithDataType.java | 7 ++++-- specs/search/paths/objects/common/schemas.yml | 10 ++++++-- .../requests/search/partialUpdateObject.json | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java b/generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java index 03d4a1a5b4..9e98e839a7 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java @@ -146,7 +146,7 @@ private Map 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); @@ -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 @@ -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; } diff --git a/specs/search/paths/objects/common/schemas.yml b/specs/search/paths/objects/common/schemas.yml index 63c849da6a..f6a8513769 100644 --- a/specs/search/paths/objects/common/schemas.yml +++ b/specs/search/paths/objects/common/schemas.yml @@ -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. @@ -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 diff --git a/tests/CTS/requests/search/partialUpdateObject.json b/tests/CTS/requests/search/partialUpdateObject.json index f6da434e97..7ec765361c 100644 --- a/tests/CTS/requests/search/partialUpdateObject.json +++ b/tests/CTS/requests/search/partialUpdateObject.json @@ -1,5 +1,6 @@ [ { + "testName": "Partial update with string value", "parameters": { "indexName": "theIndexName", "objectID": "uniqueID", @@ -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 + } + } + } } ]