diff --git a/client/android/div-data/src/main/java/com/yandex/div/data/Variable.kt b/client/android/div-data/src/main/java/com/yandex/div/data/Variable.kt index 9e40aa99a..48806e18b 100644 --- a/client/android/div-data/src/main/java/com/yandex/div/data/Variable.kt +++ b/client/android/div-data/src/main/java/com/yandex/div/data/Variable.kt @@ -126,7 +126,7 @@ sealed class Variable { } } - class JsonVariable( + class DictVariable( override val name: String, val defaultValue: JSONObject, ) : Variable() { @@ -153,7 +153,7 @@ sealed class Variable { is DoubleVariable -> value is ColorVariable -> value is UrlVariable -> value - is JsonVariable -> value + is DictVariable -> value } } @@ -165,7 +165,7 @@ sealed class Variable { is DoubleVariable -> defaultValue is ColorVariable -> defaultValue is UrlVariable -> defaultValue - is JsonVariable -> defaultValue + is DictVariable -> defaultValue } } @@ -196,7 +196,7 @@ sealed class Variable { value = Color(color) } is UrlVariable -> value = newValue.parseAsUri() - is JsonVariable -> value = newValue.parseAsJson() + is DictVariable -> value = newValue.parseAsJsonObject() } } @@ -210,7 +210,7 @@ sealed class Variable { this is DoubleVariable && from is DoubleVariable -> this.value = from.value this is ColorVariable && from is ColorVariable -> this.value = from.value this is UrlVariable && from is UrlVariable -> this.value = from.value - this is JsonVariable && from is JsonVariable -> this.value = from.value + this is DictVariable && from is DictVariable -> this.value = from.value else -> throw VariableMutationException("Setting value to $this from $from not supported!") } } @@ -255,7 +255,7 @@ sealed class Variable { } } - private fun String.parseAsJson(): JSONObject { + private fun String.parseAsJsonObject(): JSONObject { return try { JSONObject(this) } catch (e: JSONException) { diff --git a/client/android/div-data/src/test/java/com/yandex/div/data/VariableTest.kt b/client/android/div-data/src/test/java/com/yandex/div/data/VariableTest.kt index 908afe18a..2d1373c8d 100644 --- a/client/android/div-data/src/test/java/com/yandex/div/data/VariableTest.kt +++ b/client/android/div-data/src/test/java/com/yandex/div/data/VariableTest.kt @@ -92,8 +92,7 @@ class VariableTest { Variable.BooleanVariable("boolean_var", Random.nextBoolean()), Variable.ColorVariable("color_var", Random.nextInt()), Variable.UrlVariable("url_var", Uri.parse(Random.nextBytes(4).toString())), - Variable.JsonVariable("json_var", JSONObject().put(Random.nextBytes(4).toString(), Random.nextLong())), + Variable.DictVariable("dict_var", JSONObject().put(Random.nextBytes(4).toString(), Random.nextLong())), ).toList() } } - diff --git a/client/android/div/src/main/java/com/yandex/div/core/expression/ExpressionsRuntimeProvider.kt b/client/android/div/src/main/java/com/yandex/div/core/expression/ExpressionsRuntimeProvider.kt index a863d3db5..d1fb8c0d4 100644 --- a/client/android/div/src/main/java/com/yandex/div/core/expression/ExpressionsRuntimeProvider.kt +++ b/client/android/div/src/main/java/com/yandex/div/core/expression/ExpressionsRuntimeProvider.kt @@ -61,7 +61,7 @@ internal class ExpressionsRuntimeProvider @Inject constructor( is DivVariable.Str -> existingVariable is Variable.StringVariable is DivVariable.Color -> existingVariable is Variable.ColorVariable is DivVariable.Url -> existingVariable is Variable.UrlVariable - is DivVariable.Json -> existingVariable is Variable.JsonVariable + is DivVariable.Dict -> existingVariable is Variable.DictVariable }.apply { /*exhaustive*/ } // This usually happens when you're using same DivDataTag for DivData @@ -133,6 +133,6 @@ private val DivVariable.name: String is DivVariable.Str -> this.value.name is DivVariable.Color -> this.value.name is DivVariable.Url -> this.value.name - is DivVariable.Json -> this.value.name + is DivVariable.Dict -> this.value.name } } diff --git a/client/android/div/src/main/java/com/yandex/div/core/expression/variables/DivVariablesParser.kt b/client/android/div/src/main/java/com/yandex/div/core/expression/variables/DivVariablesParser.kt index 778aeab3f..ab224e5b9 100644 --- a/client/android/div/src/main/java/com/yandex/div/core/expression/variables/DivVariablesParser.kt +++ b/client/android/div/src/main/java/com/yandex/div/core/expression/variables/DivVariablesParser.kt @@ -60,9 +60,9 @@ internal fun DivVariable.toVariable(): Variable { this.value.name, this.value.value ) } - is DivVariable.Json -> { - Variable.JsonVariable( - this.value.name, this.value.value + is DivVariable.Dict -> { + Variable.DictVariable( + this.value.name, this.value.value ) } } diff --git a/client/ios/DivKit/Expressions/Functions/Function.swift b/client/ios/DivKit/Expressions/Functions/Function.swift index 44a2c142e..5b6050037 100644 --- a/client/ios/DivKit/Expressions/Functions/Function.swift +++ b/client/ios/DivKit/Expressions/Functions/Function.swift @@ -234,7 +234,7 @@ struct FunctionSignature: Decodable { case datetime case color case url - case json + case dict func check(arg: Any) -> Bool { type(of: arg) == swiftType @@ -256,7 +256,7 @@ struct FunctionSignature: Decodable { return Color.self case .url: return URL.self - case .json: + case .dict: return [String: Any].self } } diff --git a/schema/div-variable.json b/schema/div-variable.json index 72a41f2c9..e86e34905 100644 --- a/schema/div-variable.json +++ b/schema/div-variable.json @@ -154,9 +154,9 @@ "value" ] }, - "json_variable": { + "dict_variable": { "type": "object", - "$description": "translations.json#/div_variable_json", + "$description": "translations.json#/div_variable_dict", "properties": { "name": { "$ref": "div-variable-name.json", @@ -165,7 +165,7 @@ "type": { "type": "string", "enum": [ - "json" + "dict" ] }, "value": { @@ -201,7 +201,7 @@ "$ref": "#/definitions/url_variable" }, { - "$ref": "#/definitions/json_variable", + "$ref": "#/definitions/dict_variable", "platforms": [] } ] diff --git a/schema/translations.json b/schema/translations.json index 9e63ea60b..35e65c924 100644 --- a/schema/translations.json +++ b/schema/translations.json @@ -1955,7 +1955,7 @@ "en": "Variable — HEX color as a string.", "ru": "Переменная — цвет в формате HEX, представленный в виде строки." }, - "div_variable_json": { + "div_variable_dict": { "en": "Variable — any json object.", "ru": "Переменная — произвольный json объект." }, diff --git a/test_data/expression_test_data/function_signatures_std.json b/test_data/expression_test_data/function_signatures_std.json index 8b8ad67fb..3a2470bd8 100644 --- a/test_data/expression_test_data/function_signatures_std.json +++ b/test_data/expression_test_data/function_signatures_std.json @@ -11,7 +11,11 @@ } ], "result_type": "boolean", - "platforms": ["android", "web", "ios"] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "toBoolean(string) boolean", @@ -24,7 +28,11 @@ } ], "result_type": "boolean", - "platforms": ["android", "web", "ios"] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "toInteger(boolean) integer", @@ -37,7 +45,11 @@ } ], "result_type": "integer", - "platforms": ["android", "web", "ios"] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "toInteger(number) integer", @@ -50,7 +62,11 @@ } ], "result_type": "integer", - "platforms": ["android", "web", "ios"] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "toInteger(string) integer", @@ -63,7 +79,11 @@ } ], "result_type": "integer", - "platforms": ["android", "web", "ios"] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "toNumber(integer) number", @@ -76,7 +96,11 @@ } ], "result_type": "number", - "platforms": ["android", "web", "ios"] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "toNumber(string) number", @@ -89,7 +113,11 @@ } ], "result_type": "number", - "platforms": ["android", "web", "ios"] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "toString(boolean) string", @@ -102,7 +130,11 @@ } ], "result_type": "string", - "platforms": ["android", "web", "ios"] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "toString(integer) string", @@ -115,7 +147,11 @@ } ], "result_type": "string", - "platforms": ["android", "web", "ios"] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "toString(number) string", @@ -128,432 +164,477 @@ } ], "result_type": "string", - "platforms": ["android", "web", "ios"] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "toString(color) string", "function_name": "toString", "doc": "Converts argument value to string type. Returns string value.", "arguments": [ - { - "type": "color", - "doc": "Color value to convert." - } + { + "type": "color", + "doc": "Color value to convert." + } ], "result_type": "string", - "platforms": ["android", "ios", "web"] + "platforms": [ + "android", + "ios", + "web" + ] }, { "name": "toString(url) string", "function_name": "toString", "doc": "Converts argument value to string type. Returns string value.", "arguments": [ - { - "type": "url", - "doc": "Url value to convert." - } + { + "type": "url", + "doc": "Url value to convert." + } ], "result_type": "string", - "platforms": ["ios", "web"] + "platforms": [ + "ios", + "web" + ] }, { "name": "toColor(str) color", "function_name": "toColor", "doc": "Converts argument value to color type. Returns color value.", "arguments": [ - { - "type": "string", - "doc": "String value to convert." - } + { + "type": "string", + "doc": "String value to convert." + } ], "result_type": "color", - "platforms": ["web"] + "platforms": [ + "web" + ] }, { "name": "toUrl(str) url", "function_name": "toUrl", "doc": "Converts argument value to url type. Returns url value.", "arguments": [ - { - "type": "string", - "doc": "String value to convert." - } + { + "type": "string", + "doc": "String value to convert." + } ], "result_type": "url", - "platforms": ["web"] + "platforms": [ + "web" + ] }, { "name": "getIntegerValue(string, integer) integer", "function_name": "getIntegerValue", "doc": "Returns the value of a variable by its name. If the variable doesn't exist or has incorrect type, the default value would be returned.", "arguments": [ - { - "type": "string", - "doc": "Variable name." - }, - { - "type": "integer", - "doc": "Fallback value." - } + { + "type": "string", + "doc": "Variable name." + }, + { + "type": "integer", + "doc": "Fallback value." + } ], "result_type": "integer", - "platforms": [ "android", "web", "ios" ] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "getNumberValue(string, number) number", "function_name": "getNumberValue", "doc": "Returns the value of a variable by its name. If the variable doesn't exist or has incorrect type, the default value would be returned.", "arguments": [ - { - "type": "string", - "doc": "Variable name." - }, - { - "type": "number", - "doc": "Fallback value." - } + { + "type": "string", + "doc": "Variable name." + }, + { + "type": "number", + "doc": "Fallback value." + } ], "result_type": "number", - "platforms": [ "android", "web", "ios" ] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "getStringValue(string, string) string", "function_name": "getStringValue", "doc": "Returns the value of a variable by its name. If the variable doesn't exist or has incorrect type, the default value would be returned.", "arguments": [ - { - "type": "string", - "doc": "Variable name." - }, - { - "type": "string", - "doc": "Fallback value." - } + { + "type": "string", + "doc": "Variable name." + }, + { + "type": "string", + "doc": "Fallback value." + } ], "result_type": "string", - "platforms": [ "android", "web", "ios" ] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "getUrlValue(string, url) url", "function_name": "getUrlValue", "doc": "Returns the value of a variable by its name. If the variable doesn't exist or has incorrect type, the default value would be returned.", "arguments": [ - { - "type": "string", - "doc": "Variable name." - }, - { - "type": "url", - "doc": "Fallback value." - } + { + "type": "string", + "doc": "Variable name." + }, + { + "type": "url", + "doc": "Fallback value." + } ], "result_type": "url", - "platforms": ["web", "ios"] + "platforms": [ + "web", + "ios" + ] }, { "name": "getUrlValue(string, string) url", "function_name": "getUrlValue", "doc": "Returns the value of a variable by its name. If the variable doesn't exist or has incorrect type, the default value would be returned.", "arguments": [ - { - "type": "string", - "doc": "Variable name." - }, - { - "type": "string", - "doc": "Fallback value." - } + { + "type": "string", + "doc": "Variable name." + }, + { + "type": "string", + "doc": "Fallback value." + } ], "result_type": "url", - "platforms": ["web", "ios"] + "platforms": [ + "web", + "ios" + ] }, { "name": "getColorValue(string, color) color", "function_name": "getColorValue", "doc": "Returns the value of a variable by its name. If the variable doesn't exist or has incorrect type, the default value would be returned.", "arguments": [ - { - "type": "string", - "doc": "Variable name." - }, - { - "type": "color", - "doc": "Fallback value." - } + { + "type": "string", + "doc": "Variable name." + }, + { + "type": "color", + "doc": "Fallback value." + } ], "result_type": "color", - "platforms": [ "android", "web", "ios" ] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "getColorValue(string, string) color", "function_name": "getColorValue", "doc": "Returns the value of a variable by its name. If the variable doesn't exist or has incorrect type, the default value would be returned.", "arguments": [ - { - "type": "string", - "doc": "Variable name." - }, - { - "type": "string", - "doc": "Fallback value." - } + { + "type": "string", + "doc": "Variable name." + }, + { + "type": "string", + "doc": "Fallback value." + } ], "result_type": "color", - "platforms": [ "android", "web", "ios" ] + "platforms": [ + "android", + "web", + "ios" + ] }, { "name": "getBooleanValue(string, boolean) boolean", "function_name": "getBooleanValue", "doc": "Returns the value of a variable by its name. If the variable doesn't exist or has incorrect type, the default value would be returned.", "arguments": [ - { - "type": "string", - "doc": "Variable name." - }, - { - "type": "boolean", - "doc": "Fallback value." - } + { + "type": "string", + "doc": "Variable name." + }, + { + "type": "boolean", + "doc": "Fallback value." + } ], "result_type": "boolean", - "platforms": [ "android", "web", "ios" ] + "platforms": [ + "android", + "web", + "ios" + ] }, { - "name": "getJsonString(json, vararg string) string", - "function_name": "getJsonString", - "doc": "Returns a property from a json object.", + "name": "getDictString(dict, vararg string) string", + "function_name": "getDictString", + "doc": "Returns a string value from dictionary.", "arguments": [ - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "string", "platforms": [] }, { - "name": "getJsonNumber(json, vararg string) number", - "function_name": "getJsonNumber", - "doc": "Returns a property from a json object.", + "name": "getDictNumber(dict, vararg string) number", + "function_name": "getDictNumber", + "doc": "Returns a number value from dictionary.", "arguments": [ - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "number", "platforms": [] }, { - "name": "getJsonInteger(json, vararg string) integer", - "function_name": "getJsonInteger", - "doc": "Returns a property from a json object.", + "name": "getDictInteger(dict, vararg string) integer", + "function_name": "getDictInteger", + "doc": "Returns an integer value from dictionary.", "arguments": [ - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "integer", "platforms": [] }, { - "name": "getJsonBoolean(json, vararg string) boolean", - "function_name": "getJsonBoolean", - "doc": "Returns a property from a json object.", + "name": "getDictBoolean(dict, vararg string) boolean", + "function_name": "getDictBoolean", + "doc": "Returns a boolean property from dictionary.", "arguments": [ - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "boolean", "platforms": [] }, { - "name": "getJsonColor(json, vararg string) color", - "function_name": "getJsonColor", - "doc": "Returns a property from a json object.", + "name": "getDictColor(dict, vararg string) color", + "function_name": "getDictColor", + "doc": "Returns a color property from dictionary.", "arguments": [ - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "color", "platforms": [] }, { - "name": "getJsonUrl(json, vararg string) url", - "function_name": "getJsonUrl", - "doc": "Returns a property from a json object.", + "name": "getDictUrl(dict, vararg string) url", + "function_name": "getDictUrl", + "doc": "Returns an url property from dictionary.", "arguments": [ - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "url", "platforms": [] }, { - "name": "getJsonOptString(string, json, vararg string) string", - "function_name": "getJsonOptString", - "doc": "Returns a property from a json object with fallback.", + "name": "getDictOptString(string, dict, vararg string) string", + "function_name": "getDictOptString", + "doc": "Returns an optional string property from dictionary.", "arguments": [ - { - "type": "string", - "doc": "Fallback if property does not exist or a property value is not a string." - }, - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "string", + "doc": "Fallback value if property does not exist or a property value is not a string." + }, + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "string", "platforms": [] }, { - "name": "getJsonOptNumber(number, json, vararg string) number", - "function_name": "getJsonOptNumber", - "doc": "Returns a property from a json object with fallback.", + "name": "getDictOptNumber(number, dict, vararg string) number", + "function_name": "getDictOptNumber", + "doc": "Returns an optional number property from dictionary.", "arguments": [ - { - "type": "number", - "doc": "Fallback if property does not exist or a property value is not a number." - }, - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "number", + "doc": "Fallback value if property does not exist or a property value is not a number." + }, + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "number", "platforms": [] }, { - "name": "getJsonOptInteger(integer, json, vararg string) integer", - "function_name": "getJsonOptInteger", - "doc": "Returns a property from a json object with fallback.", + "name": "getDictOptInteger(integer, dict, vararg string) integer", + "function_name": "getDictOptInteger", + "doc": "Returns an optional integer property from dictionary.", "arguments": [ - { - "type": "integer", - "doc": "Fallback if property does not exist or a property value is not an integer." - }, - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "integer", + "doc": "Fallback value if property does not exist or a property value is not an integer." + }, + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "integer", "platforms": [] }, { - "name": "getJsonOptBoolean(boolean, json, vararg string) boolean", - "function_name": "getJsonOptBoolean", - "doc": "Returns a property from a json object with fallback.", + "name": "getDictOptBoolean(boolean, dict, vararg string) boolean", + "function_name": "getDictOptBoolean", + "doc": "Returns an optional boolean property from dictionary.", "arguments": [ - { - "type": "boolean", - "doc": "Fallback if property does not exist or a property value is not a boolean." - }, - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "boolean", + "doc": "Fallback value if property does not exist or a property value is not a boolean." + }, + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "boolean", "platforms": [] }, { - "name": "getJsonOptColor(color, json, vararg string) color", - "function_name": "getJsonOptColor", - "doc": "Returns a property from a json object with fallback.", + "name": "getDictOptColor(color, dict, vararg string) color", + "function_name": "getDictOptColor", + "doc": "Returns an optional color property from dictionary.", "arguments": [ - { - "type": "color", - "doc": "Fallback if property does not exist or a property value is not a color." - }, - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "color", + "doc": "Fallback value if property does not exist or a property value is not a color." + }, + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "color", "platforms": [] }, { - "name": "getJsonOptUrl(url, json, vararg string) url", - "function_name": "getJsonOptUrl", - "doc": "Returns a property from a json object with fallback.", + "name": "getDictOptUrl(url, dict, vararg string) url", + "function_name": "getDictOptUrl", + "doc": "Returns an optional url property from dictionary.", "arguments": [ - { - "type": "url", - "doc": "Fallback if property does not exist or a property value is not an url." - }, - { - "type": "json", - "doc": "A json object." - }, - { - "type": "string", - "vararg": true, - "doc": "Json path." - } + { + "type": "url", + "doc": "Fallback value if property does not exist or a property value is not an url." + }, + { + "type": "dict", + "doc": "Dictionary." + }, + { + "type": "string", + "vararg": true, + "doc": "Path in dictionary." + } ], "result_type": "url", "platforms": []