From abd997bf3d7b513ddec3a8ff37327cc1e175f2a5 Mon Sep 17 00:00:00 2001 From: booster Date: Sat, 14 Mar 2026 22:48:04 +0300 Subject: [PATCH] Enabled expressions for playerSettingsPayload commit_hash:a4ed6e0a2df2ae78420a3828da105b083649b129 --- .../generators/kotlin/kotlin_entities.py | 2 +- .../generators/swift/swift_entities.py | 6 ++-- .../api_generator/schema/modeling/entities.py | 4 +-- .../dart/entity_with_json_property.dart | 8 ++--- .../kotlin/EntityWithJsonProperty.kt | 14 ++++---- .../kotlin/EntityWithJsonPropertyTemplate.kt | 12 +++---- .../EntityWithJsonProperty.kt | 14 ++++---- .../EntityWithJsonProperty.swift | 35 ++++++++++++------- .../EntityWithJsonProperty.kt | 10 +++--- .../EntityWithJsonPropertyJsonParser.kt | 14 ++++---- .../EntityWithJsonPropertyTemplate.kt | 6 ++-- .../EntityWithJsonProperty.kt | 10 +++--- .../EntityWithJsonProperty.swift | 21 ++++++++--- .../swift/EntityWithJsonProperty.swift | 35 ++++++++++++------- .../EntityWithJsonPropertyTemplate.swift | 8 ++--- .../type_script/EntityWithJsonProperty.ts | 4 +-- .../div/internal/parser/JsonParser.java | 6 ++-- .../internal/parser/JsonTemplateParser.java | 8 ++--- .../div/core/view2/divs/DivVideoBinder.kt | 2 +- .../Extensions/DivVideoExtensions.swift | 2 +- .../DivKit/generated_sources/DivVideo.swift | 12 ++++--- .../generated_sources/DivVideoTemplate.swift | 8 ++--- .../EntityWithJsonProperty.swift | 35 ++++++++++++------- .../EntityWithJsonPropertyTemplate.swift | 8 ++--- schema/div-action-base.json | 1 + schema/div-custom.json | 1 + schema/div-extension.json | 1 + shared_data/phone-masks.json | 1 + 28 files changed, 169 insertions(+), 119 deletions(-) diff --git a/api_generator/api_generator/generators/kotlin/kotlin_entities.py b/api_generator/api_generator/generators/kotlin/kotlin_entities.py index a627782ac..e54dcac48 100644 --- a/api_generator/api_generator/generators/kotlin/kotlin_entities.py +++ b/api_generator/api_generator/generators/kotlin/kotlin_entities.py @@ -1518,7 +1518,7 @@ class KotlinPropertyType(PropertyType): return f'{prefix}INT' elif isinstance(self, Double): return f'{prefix}DOUBLE' - elif isinstance(self, Dictionary): + elif isinstance(self, (Dictionary, RawObject)): return f'{prefix}DICT' elif isinstance(self, RawArray): return f'{prefix}JSON_ARRAY' diff --git a/api_generator/api_generator/generators/swift/swift_entities.py b/api_generator/api_generator/generators/swift/swift_entities.py index b2dd672db..484c4e5aa 100644 --- a/api_generator/api_generator/generators/swift/swift_entities.py +++ b/api_generator/api_generator/generators/swift/swift_entities.py @@ -474,7 +474,7 @@ class SwiftProperty(Property): return 'resolveNumeric' elif isinstance(property_type, Object) and isinstance(property_type.object, StringEnumeration): return 'resolveEnum' - elif isinstance(property_type, Dictionary): + elif isinstance(property_type, Dictionary) or isinstance(property_type, RawObject): return 'resolveDict' elif isinstance(property_type, RawArray): return 'resolveArray' @@ -851,9 +851,7 @@ class SwiftPropertyType(PropertyType): return True def serialization_suffix(self, use_expressions: bool) -> str: - if isinstance(self, RawObject): - return '' - elif isinstance(self, (String, Int, Double, Bool, BoolInt, Dictionary, RawArray)): + if isinstance(self, (String, Int, Double, Bool, BoolInt, Dictionary, RawArray, RawObject)): return '.toValidSerializationValue()' if use_expressions else '' elif isinstance(self, Object): if isinstance(self.object, StringEnumeration): diff --git a/api_generator/api_generator/schema/modeling/entities.py b/api_generator/api_generator/schema/modeling/entities.py index 07e31f56f..d35ebb43d 100644 --- a/api_generator/api_generator/schema/modeling/entities.py +++ b/api_generator/api_generator/schema/modeling/entities.py @@ -797,9 +797,9 @@ def default_value(lang: GeneratedLanguage, class PropertyType(ABC): @property def supports_expressions(self) -> bool: - if isinstance(self, (Int, Double, Bool, BoolInt, String, Color, Url, RawArray, Dictionary)): + if isinstance(self, (Int, Double, Bool, BoolInt, String, Color, Url, RawArray, Dictionary, RawObject)): return True - elif isinstance(self, (RawObject, StaticString)): + elif isinstance(self, (StaticString)): return False elif isinstance(self, Array): if isinstance(self.property_type, Object) and \ diff --git a/api_generator/tests/references/dart/entity_with_json_property.dart b/api_generator/tests/references/dart/entity_with_json_property.dart index 8d927f749..c50b8c4a8 100644 --- a/api_generator/tests/references/dart/entity_with_json_property.dart +++ b/api_generator/tests/references/dart/entity_with_json_property.dart @@ -7,12 +7,12 @@ import 'package:divkit/src/utils/parsing.dart'; class EntityWithJsonProperty with EquatableMixin { const EntityWithJsonProperty({ - this.jsonProperty = None, + this.jsonProperty = const ValueExpression(None), }); static const type = "entity_with_json_property"; // default value: None - final Obj jsonProperty; + final Expression jsonProperty; @override List get props => [ @@ -20,7 +20,7 @@ class EntityWithJsonProperty with EquatableMixin { ]; EntityWithJsonProperty copyWith({ - Obj? jsonProperty, + Expression? jsonProperty, }) => EntityWithJsonProperty( jsonProperty: jsonProperty ?? this.jsonProperty, ); @@ -31,7 +31,7 @@ class EntityWithJsonProperty with EquatableMixin { } try { return EntityWithJsonProperty( - jsonProperty: reqProp(safeParseMap(json['json_property'], fallback: None,), name: 'json_property',), + jsonProperty: reqVProp(safeParseMapExpr(json['json_property'], fallback: None,), name: 'json_property',), ); } catch (e, st) { logger.warning("Parsing error", error: e, stackTrace: st); diff --git a/api_generator/tests/references/kotlin/EntityWithJsonProperty.kt b/api_generator/tests/references/kotlin/EntityWithJsonProperty.kt index e7f4d199c..7825cc6c7 100644 --- a/api_generator/tests/references/kotlin/EntityWithJsonProperty.kt +++ b/api_generator/tests/references/kotlin/EntityWithJsonProperty.kt @@ -14,7 +14,7 @@ import org.json.JSONArray import org.json.JSONObject class EntityWithJsonProperty( - @JvmField val jsonProperty: JSONObject = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] } + @JvmField val jsonProperty: Expression = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] } ) : JSONSerializable, Hashable { private var _hash: Int? = null @@ -32,18 +32,18 @@ class EntityWithJsonProperty( fun equals(other: EntityWithJsonProperty?, resolver: ExpressionResolver, otherResolver: ExpressionResolver): Boolean { other ?: return false - return jsonProperty == other.jsonProperty + return jsonProperty.evaluate(resolver) == other.jsonProperty.evaluate(otherResolver) } fun copy( - jsonProperty: JSONObject = this.jsonProperty, + jsonProperty: Expression = this.jsonProperty, ) = EntityWithJsonProperty( jsonProperty = jsonProperty, ) override fun writeToJSON(): JSONObject { val json = JSONObject() - json.write(key = "json_property", value = jsonProperty) + json.writeExpression(key = "json_property", value = jsonProperty) json.write(key = "type", value = TYPE) return json } @@ -51,21 +51,21 @@ class EntityWithJsonProperty( companion object { const val TYPE = "entity_with_json_property" - private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject(""" + private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject(""" { "key": "value", "items": [ "value" ] } - """) + """)) @JvmStatic @JvmName("fromJson") operator fun invoke(env: ParsingEnvironment, json: JSONObject): EntityWithJsonProperty { val logger = env.logger return EntityWithJsonProperty( - jsonProperty = JsonParser.readOptional(json, "json_property", logger, env) ?: JSON_PROPERTY_DEFAULT_VALUE + jsonProperty = JsonParser.readOptionalExpression(json, "json_property", logger, env, JSON_PROPERTY_DEFAULT_VALUE, TYPE_HELPER_DICT) ?: JSON_PROPERTY_DEFAULT_VALUE ) } diff --git a/api_generator/tests/references/kotlin/EntityWithJsonPropertyTemplate.kt b/api_generator/tests/references/kotlin/EntityWithJsonPropertyTemplate.kt index 3270c5c7b..779f7e4a2 100644 --- a/api_generator/tests/references/kotlin/EntityWithJsonPropertyTemplate.kt +++ b/api_generator/tests/references/kotlin/EntityWithJsonPropertyTemplate.kt @@ -14,7 +14,7 @@ import org.json.JSONArray import org.json.JSONObject class EntityWithJsonPropertyTemplate( - @JvmField val jsonProperty: Field, + @JvmField val jsonProperty: Field>, ) : JSONSerializable, JsonTemplate { constructor( @@ -23,7 +23,7 @@ class EntityWithJsonPropertyTemplate( topLevel: Boolean = false, json: JSONObject ) : this( - jsonProperty = JsonTemplateParser.readOptionalField(json, "json_property", topLevel, parent?.jsonProperty, env.logger, env) + jsonProperty = JsonTemplateParser.readOptionalFieldWithExpression(json, "json_property", topLevel, parent?.jsonProperty, env.logger, env, TYPE_HELPER_DICT) ) override fun resolve(env: ParsingEnvironment, data: JSONObject): EntityWithJsonProperty { @@ -34,7 +34,7 @@ class EntityWithJsonPropertyTemplate( override fun writeToJSON(): JSONObject { val json = JSONObject() - json.writeField(key = "json_property", field = jsonProperty) + json.writeFieldWithExpression(key = "json_property", field = jsonProperty) json.write(key = "type", value = TYPE) return json } @@ -42,16 +42,16 @@ class EntityWithJsonPropertyTemplate( companion object { const val TYPE = "entity_with_json_property" - private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject(""" + private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject(""" { "key": "value", "items": [ "value" ] } - """) + """)) - val JSON_PROPERTY_READER: Reader = { key, json, env -> JsonParser.readOptional(json, key, env.logger, env) ?: JSON_PROPERTY_DEFAULT_VALUE } + val JSON_PROPERTY_READER: Reader> = { key, json, env -> JsonParser.readOptionalExpression(json, key, env.logger, env, JSON_PROPERTY_DEFAULT_VALUE, TYPE_HELPER_DICT) ?: JSON_PROPERTY_DEFAULT_VALUE } val TYPE_READER: Reader = { key, json, env -> JsonParser.read(json, key, env.logger, env) } val CREATOR = { env: ParsingEnvironment, it: JSONObject -> EntityWithJsonPropertyTemplate(env, json = it) } diff --git a/api_generator/tests/references/not_templates_kotlin/EntityWithJsonProperty.kt b/api_generator/tests/references/not_templates_kotlin/EntityWithJsonProperty.kt index e7f4d199c..7825cc6c7 100644 --- a/api_generator/tests/references/not_templates_kotlin/EntityWithJsonProperty.kt +++ b/api_generator/tests/references/not_templates_kotlin/EntityWithJsonProperty.kt @@ -14,7 +14,7 @@ import org.json.JSONArray import org.json.JSONObject class EntityWithJsonProperty( - @JvmField val jsonProperty: JSONObject = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] } + @JvmField val jsonProperty: Expression = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] } ) : JSONSerializable, Hashable { private var _hash: Int? = null @@ -32,18 +32,18 @@ class EntityWithJsonProperty( fun equals(other: EntityWithJsonProperty?, resolver: ExpressionResolver, otherResolver: ExpressionResolver): Boolean { other ?: return false - return jsonProperty == other.jsonProperty + return jsonProperty.evaluate(resolver) == other.jsonProperty.evaluate(otherResolver) } fun copy( - jsonProperty: JSONObject = this.jsonProperty, + jsonProperty: Expression = this.jsonProperty, ) = EntityWithJsonProperty( jsonProperty = jsonProperty, ) override fun writeToJSON(): JSONObject { val json = JSONObject() - json.write(key = "json_property", value = jsonProperty) + json.writeExpression(key = "json_property", value = jsonProperty) json.write(key = "type", value = TYPE) return json } @@ -51,21 +51,21 @@ class EntityWithJsonProperty( companion object { const val TYPE = "entity_with_json_property" - private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject(""" + private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject(""" { "key": "value", "items": [ "value" ] } - """) + """)) @JvmStatic @JvmName("fromJson") operator fun invoke(env: ParsingEnvironment, json: JSONObject): EntityWithJsonProperty { val logger = env.logger return EntityWithJsonProperty( - jsonProperty = JsonParser.readOptional(json, "json_property", logger, env) ?: JSON_PROPERTY_DEFAULT_VALUE + jsonProperty = JsonParser.readOptionalExpression(json, "json_property", logger, env, JSON_PROPERTY_DEFAULT_VALUE, TYPE_HELPER_DICT) ?: JSON_PROPERTY_DEFAULT_VALUE ) } diff --git a/api_generator/tests/references/not_templates_swift/EntityWithJsonProperty.swift b/api_generator/tests/references/not_templates_swift/EntityWithJsonProperty.swift index baf97523d..f8b078134 100644 --- a/api_generator/tests/references/not_templates_swift/EntityWithJsonProperty.swift +++ b/api_generator/tests/references/not_templates_swift/EntityWithJsonProperty.swift @@ -6,18 +6,10 @@ import Serialization public final class EntityWithJsonProperty: @unchecked Sendable { public static let type: String = "entity_with_json_property" - public let jsonProperty: [String: Any] // default value: { "key": "value", "items": [ "value" ] } + public let jsonProperty: Expression<[String: Any]> // default value: { "key": "value", "items": [ "value" ] } - public convenience init(dictionary: [String: Any], context: ParsingContext) throws { - self.init( - jsonProperty: try dictionary.getOptionalField("json_property", context: context) - ) - } - - init( - jsonProperty: [String: Any]? = nil - ) { - self.jsonProperty = jsonProperty ?? (try! JSONSerialization.jsonObject(jsonString: """ + public func resolveJsonProperty(_ resolver: ExpressionResolver) -> [String: Any] { + resolver.resolveDict(jsonProperty) ?? (try! JSONSerialization.jsonObject(jsonString: """ { "key": "value", "items": [ @@ -26,6 +18,25 @@ public final class EntityWithJsonProperty: @unchecked Sendable { } """) as! [String: Any]) } + + public convenience init(dictionary: [String: Any], context: ParsingContext) throws { + self.init( + jsonProperty: try dictionary.getOptionalExpressionField("json_property", context: context) + ) + } + + init( + jsonProperty: Expression<[String: Any]>? = nil + ) { + self.jsonProperty = jsonProperty ?? .value((try! JSONSerialization.jsonObject(jsonString: """ + { + "key": "value", + "items": [ + "value" + ] + } + """) as! [String: Any])) + } } #if DEBUG @@ -42,7 +53,7 @@ extension EntityWithJsonProperty: Serializable { public func toDictionary() -> [String: ValidSerializationValue] { var result: [String: ValidSerializationValue] = [:] result["type"] = Self.type - result["json_property"] = jsonProperty + result["json_property"] = jsonProperty.toValidSerializationValue() return result } } diff --git a/api_generator/tests/references/serializers_kotlin/EntityWithJsonProperty.kt b/api_generator/tests/references/serializers_kotlin/EntityWithJsonProperty.kt index 1c378dd4d..313e56ccc 100644 --- a/api_generator/tests/references/serializers_kotlin/EntityWithJsonProperty.kt +++ b/api_generator/tests/references/serializers_kotlin/EntityWithJsonProperty.kt @@ -14,7 +14,7 @@ import org.json.JSONArray import org.json.JSONObject class EntityWithJsonProperty( - @JvmField val jsonProperty: JSONObject = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] } + @JvmField val jsonProperty: Expression = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] } ) : JSONSerializable, Hashable { private var _hash: Int? = null @@ -32,11 +32,11 @@ class EntityWithJsonProperty( fun equals(other: EntityWithJsonProperty?, resolver: ExpressionResolver, otherResolver: ExpressionResolver): Boolean { other ?: return false - return jsonProperty == other.jsonProperty + return jsonProperty.evaluate(resolver) == other.jsonProperty.evaluate(otherResolver) } fun copy( - jsonProperty: JSONObject = this.jsonProperty, + jsonProperty: Expression = this.jsonProperty, ) = EntityWithJsonProperty( jsonProperty = jsonProperty, ) @@ -50,14 +50,14 @@ class EntityWithJsonProperty( companion object { const val TYPE = "entity_with_json_property" - private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject(""" + private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject(""" { "key": "value", "items": [ "value" ] } - """) + """)) @JvmStatic @JvmName("fromJson") diff --git a/api_generator/tests/references/serializers_kotlin/EntityWithJsonPropertyJsonParser.kt b/api_generator/tests/references/serializers_kotlin/EntityWithJsonPropertyJsonParser.kt index 16be43350..dec4f75ec 100644 --- a/api_generator/tests/references/serializers_kotlin/EntityWithJsonPropertyJsonParser.kt +++ b/api_generator/tests/references/serializers_kotlin/EntityWithJsonPropertyJsonParser.kt @@ -24,14 +24,14 @@ internal class EntityWithJsonPropertyJsonParser( @Throws(ParsingException::class) override fun deserialize(context: ParsingContext, data: JSONObject): EntityWithJsonProperty { return EntityWithJsonProperty( - jsonProperty = JsonPropertyParser.readOptional(context, data, "json_property") ?: JSON_PROPERTY_DEFAULT_VALUE, + jsonProperty = JsonExpressionParser.readOptionalExpression(context, data, "json_property", TYPE_HELPER_DICT, JSON_PROPERTY_DEFAULT_VALUE) ?: JSON_PROPERTY_DEFAULT_VALUE, ) } @Throws(ParsingException::class) override fun serialize(context: ParsingContext, value: EntityWithJsonProperty): JSONObject { val data = JSONObject() - JsonPropertyParser.write(context, data, "json_property", value.jsonProperty) + JsonExpressionParser.writeExpression(context, data, "json_property", value.jsonProperty) JsonPropertyParser.write(context, data, "type", EntityWithJsonProperty.TYPE) return data } @@ -46,14 +46,14 @@ internal class EntityWithJsonPropertyJsonParser( val allowOverride = context.allowPropertyOverride @Suppress("NAME_SHADOWING") val context = context.restrictPropertyOverride() return EntityWithJsonPropertyTemplate( - jsonProperty = JsonFieldParser.readOptionalField(context, data, "json_property", allowOverride, parent?.jsonProperty), + jsonProperty = JsonFieldParser.readOptionalFieldWithExpression(context, data, "json_property", TYPE_HELPER_DICT, allowOverride, parent?.jsonProperty), ) } @Throws(ParsingException::class) override fun serialize(context: ParsingContext, value: EntityWithJsonPropertyTemplate): JSONObject { val data = JSONObject() - JsonFieldParser.writeField(context, data, "json_property", value.jsonProperty) + JsonFieldParser.writeFieldWithExpression(context, data, "json_property", value.jsonProperty) JsonPropertyParser.write(context, data, "type", EntityWithJsonProperty.TYPE) return data } @@ -66,20 +66,20 @@ internal class EntityWithJsonPropertyJsonParser( @Throws(ParsingException::class) override fun resolve(context: ParsingContext, template: EntityWithJsonPropertyTemplate, data: JSONObject): EntityWithJsonProperty { return EntityWithJsonProperty( - jsonProperty = JsonFieldResolver.resolveOptional(context, template.jsonProperty, data, "json_property") ?: JSON_PROPERTY_DEFAULT_VALUE, + jsonProperty = JsonFieldResolver.resolveOptionalExpression(context, template.jsonProperty, data, "json_property", TYPE_HELPER_DICT) ?: JSON_PROPERTY_DEFAULT_VALUE, ) } } private companion object { - @JvmField val JSON_PROPERTY_DEFAULT_VALUE = JSONObject(""" + @JvmField val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject(""" { "key": "value", "items": [ "value" ] } - """) + """)) } } diff --git a/api_generator/tests/references/serializers_kotlin/EntityWithJsonPropertyTemplate.kt b/api_generator/tests/references/serializers_kotlin/EntityWithJsonPropertyTemplate.kt index 78ca4a890..ac650c293 100644 --- a/api_generator/tests/references/serializers_kotlin/EntityWithJsonPropertyTemplate.kt +++ b/api_generator/tests/references/serializers_kotlin/EntityWithJsonPropertyTemplate.kt @@ -14,7 +14,7 @@ import org.json.JSONArray import org.json.JSONObject class EntityWithJsonPropertyTemplate( - @JvmField val jsonProperty: Field, + @JvmField val jsonProperty: Field>, ) : JSONSerializable, JsonTemplate { constructor( @@ -43,14 +43,14 @@ class EntityWithJsonPropertyTemplate( companion object { const val TYPE = "entity_with_json_property" - private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject(""" + private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject(""" { "key": "value", "items": [ "value" ] } - """) + """)) val CREATOR = { env: ParsingEnvironment, it: JSONObject -> EntityWithJsonPropertyTemplate(env, json = it) } } diff --git a/api_generator/tests/references/shared_data_kotlin/EntityWithJsonProperty.kt b/api_generator/tests/references/shared_data_kotlin/EntityWithJsonProperty.kt index 45e401e02..0ec82476f 100644 --- a/api_generator/tests/references/shared_data_kotlin/EntityWithJsonProperty.kt +++ b/api_generator/tests/references/shared_data_kotlin/EntityWithJsonProperty.kt @@ -6,7 +6,7 @@ import org.json.JSONArray import org.json.JSONObject class EntityWithJsonProperty( - @JvmField val jsonProperty: JSONObject = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] } + @JvmField val jsonProperty: Expression = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] } ) : Hashable { private var _hash: Int? = null @@ -24,11 +24,11 @@ class EntityWithJsonProperty( fun equals(other: EntityWithJsonProperty?, resolver: ExpressionResolver, otherResolver: ExpressionResolver): Boolean { other ?: return false - return jsonProperty == other.jsonProperty + return jsonProperty.evaluate(resolver) == other.jsonProperty.evaluate(otherResolver) } fun copy( - jsonProperty: JSONObject = this.jsonProperty, + jsonProperty: Expression = this.jsonProperty, ) = EntityWithJsonProperty( jsonProperty = jsonProperty, ) @@ -36,13 +36,13 @@ class EntityWithJsonProperty( companion object { const val TYPE = "entity_with_json_property" - private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject(""" + private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject(""" { "key": "value", "items": [ "value" ] } - """) + """)) } } diff --git a/api_generator/tests/references/shared_data_swift/EntityWithJsonProperty.swift b/api_generator/tests/references/shared_data_swift/EntityWithJsonProperty.swift index a81992b52..bdcef25bd 100644 --- a/api_generator/tests/references/shared_data_swift/EntityWithJsonProperty.swift +++ b/api_generator/tests/references/shared_data_swift/EntityWithJsonProperty.swift @@ -6,12 +6,10 @@ import Serialization public final class EntityWithJsonProperty: @unchecked Sendable { public static let type: String = "entity_with_json_property" - public let jsonProperty: [String: Any] // default value: { "key": "value", "items": [ "value" ] } + public let jsonProperty: Expression<[String: Any]> // default value: { "key": "value", "items": [ "value" ] } - init( - jsonProperty: [String: Any]? = nil - ) { - self.jsonProperty = jsonProperty ?? (try! JSONSerialization.jsonObject(jsonString: """ + public func resolveJsonProperty(_ resolver: ExpressionResolver) -> [String: Any] { + resolver.resolveDict(jsonProperty) ?? (try! JSONSerialization.jsonObject(jsonString: """ { "key": "value", "items": [ @@ -20,6 +18,19 @@ public final class EntityWithJsonProperty: @unchecked Sendable { } """) as! [String: Any]) } + + init( + jsonProperty: Expression<[String: Any]>? = nil + ) { + self.jsonProperty = jsonProperty ?? .value((try! JSONSerialization.jsonObject(jsonString: """ + { + "key": "value", + "items": [ + "value" + ] + } + """) as! [String: Any])) + } } #if DEBUG diff --git a/api_generator/tests/references/swift/EntityWithJsonProperty.swift b/api_generator/tests/references/swift/EntityWithJsonProperty.swift index baf97523d..f8b078134 100644 --- a/api_generator/tests/references/swift/EntityWithJsonProperty.swift +++ b/api_generator/tests/references/swift/EntityWithJsonProperty.swift @@ -6,18 +6,10 @@ import Serialization public final class EntityWithJsonProperty: @unchecked Sendable { public static let type: String = "entity_with_json_property" - public let jsonProperty: [String: Any] // default value: { "key": "value", "items": [ "value" ] } + public let jsonProperty: Expression<[String: Any]> // default value: { "key": "value", "items": [ "value" ] } - public convenience init(dictionary: [String: Any], context: ParsingContext) throws { - self.init( - jsonProperty: try dictionary.getOptionalField("json_property", context: context) - ) - } - - init( - jsonProperty: [String: Any]? = nil - ) { - self.jsonProperty = jsonProperty ?? (try! JSONSerialization.jsonObject(jsonString: """ + public func resolveJsonProperty(_ resolver: ExpressionResolver) -> [String: Any] { + resolver.resolveDict(jsonProperty) ?? (try! JSONSerialization.jsonObject(jsonString: """ { "key": "value", "items": [ @@ -26,6 +18,25 @@ public final class EntityWithJsonProperty: @unchecked Sendable { } """) as! [String: Any]) } + + public convenience init(dictionary: [String: Any], context: ParsingContext) throws { + self.init( + jsonProperty: try dictionary.getOptionalExpressionField("json_property", context: context) + ) + } + + init( + jsonProperty: Expression<[String: Any]>? = nil + ) { + self.jsonProperty = jsonProperty ?? .value((try! JSONSerialization.jsonObject(jsonString: """ + { + "key": "value", + "items": [ + "value" + ] + } + """) as! [String: Any])) + } } #if DEBUG @@ -42,7 +53,7 @@ extension EntityWithJsonProperty: Serializable { public func toDictionary() -> [String: ValidSerializationValue] { var result: [String: ValidSerializationValue] = [:] result["type"] = Self.type - result["json_property"] = jsonProperty + result["json_property"] = jsonProperty.toValidSerializationValue() return result } } diff --git a/api_generator/tests/references/swift/EntityWithJsonPropertyTemplate.swift b/api_generator/tests/references/swift/EntityWithJsonPropertyTemplate.swift index 3a51805e3..3d2924ff9 100644 --- a/api_generator/tests/references/swift/EntityWithJsonPropertyTemplate.swift +++ b/api_generator/tests/references/swift/EntityWithJsonPropertyTemplate.swift @@ -7,18 +7,18 @@ import Serialization public final class EntityWithJsonPropertyTemplate: TemplateValue, @unchecked Sendable { public static let type: String = "entity_with_json_property" public let parent: String? - public let jsonProperty: Field<[String: Any]>? // default value: { "key": "value", "items": [ "value" ] } + public let jsonProperty: Field>? // default value: { "key": "value", "items": [ "value" ] } public convenience init(dictionary: [String: Any], templateToType: [TemplateName: String]) throws { self.init( parent: dictionary["type"] as? String, - jsonProperty: dictionary.getOptionalField("json_property") + jsonProperty: dictionary.getOptionalExpressionField("json_property") ) } init( parent: String?, - jsonProperty: Field<[String: Any]>? = nil + jsonProperty: Field>? = nil ) { self.parent = parent self.jsonProperty = jsonProperty @@ -39,7 +39,7 @@ public final class EntityWithJsonPropertyTemplate: TemplateValue, @unchecked Sen if useOnlyLinks { return resolveOnlyLinks(context: context, parent: parent) } - var jsonPropertyValue: DeserializationResult<[String: Any]> = parent?.jsonProperty?.value() ?? .noValue + var jsonPropertyValue: DeserializationResult> = parent?.jsonProperty?.value() ?? .noValue context.templateData.forEach { key, __dictValue in switch key { case "json_property": diff --git a/api_generator/tests/references/type_script/EntityWithJsonProperty.ts b/api_generator/tests/references/type_script/EntityWithJsonProperty.ts index aaccc1316..0df6cc788 100644 --- a/api_generator/tests/references/type_script/EntityWithJsonProperty.ts +++ b/api_generator/tests/references/type_script/EntityWithJsonProperty.ts @@ -8,7 +8,7 @@ export class EntityWithJsonProperty; readonly type = 'entity_with_json_property'; - json_property?: Type<{}>; + json_property?: Type<{} | DivExpression>; constructor(props?: Exact) { this.json_property = props?.json_property; @@ -16,5 +16,5 @@ export class EntityWithJsonProperty; + json_property?: Type<{} | DivExpression>; } diff --git a/client/android/div-data/src/main/java/com/yandex/div/internal/parser/JsonParser.java b/client/android/div-data/src/main/java/com/yandex/div/internal/parser/JsonParser.java index 39fc7f5ec..d1f24d001 100644 --- a/client/android/div-data/src/main/java/com/yandex/div/internal/parser/JsonParser.java +++ b/client/android/div-data/src/main/java/com/yandex/div/internal/parser/JsonParser.java @@ -71,13 +71,13 @@ public class JsonParser { } @Nullable - public static Expression readOptionalExpression( + public static Expression readOptionalExpression( @NonNull final JSONObject jsonObject, @NonNull final String key, @NonNull final ParsingErrorLogger logger, @NonNull final ParsingEnvironment env, - @NonNull final TypeHelper typeHelper) { - return readOptionalExpression(jsonObject, key, doNotConvert(), ALWAYS_VALID_STRING, logger, env, typeHelper); + @NonNull final TypeHelper typeHelper) { + return readOptionalExpression(jsonObject, key, doNotConvert(), alwaysValid(), logger, env, typeHelper); } @Nullable diff --git a/client/android/div-data/src/main/java/com/yandex/div/internal/parser/JsonTemplateParser.java b/client/android/div-data/src/main/java/com/yandex/div/internal/parser/JsonTemplateParser.java index a1f8d5674..6c989db25 100644 --- a/client/android/div-data/src/main/java/com/yandex/div/internal/parser/JsonTemplateParser.java +++ b/client/android/div-data/src/main/java/com/yandex/div/internal/parser/JsonTemplateParser.java @@ -252,16 +252,16 @@ public class JsonTemplateParser { } @NonNull - public static Field> readOptionalFieldWithExpression( + public static Field> readOptionalFieldWithExpression( @NonNull JSONObject json, @NonNull String key, boolean overridable, - @Nullable Field> fallback, + @Nullable Field> fallback, @NonNull ParsingErrorLogger logger, @NonNull ParsingEnvironment env, - @NonNull TypeHelper typeHelper) { + @NonNull TypeHelper typeHelper) { return readOptionalFieldWithExpression( - json, key, overridable, fallback, doNotConvert(), alwaysValidString(), logger, env, typeHelper); + json, key, overridable, fallback, doNotConvert(), alwaysValid(), logger, env, typeHelper); } @NonNull diff --git a/client/android/div/src/main/java/com/yandex/div/core/view2/divs/DivVideoBinder.kt b/client/android/div/src/main/java/com/yandex/div/core/view2/divs/DivVideoBinder.kt index 796526175..4e8a39abf 100644 --- a/client/android/div/src/main/java/com/yandex/div/core/view2/divs/DivVideoBinder.kt +++ b/client/android/div/src/main/java/com/yandex/div/core/view2/divs/DivVideoBinder.kt @@ -282,7 +282,7 @@ internal class DivVideoBinder @Inject constructor( autoplay = autostart.evaluate(resolver), isMuted = muted.evaluate(resolver), repeatable = repeatable.evaluate(resolver), - payload = playerSettingsPayload, + payload = playerSettingsPayload?.evaluate(resolver), ) } diff --git a/client/ios/DivKit/Extensions/DivVideoExtensions.swift b/client/ios/DivKit/Extensions/DivVideoExtensions.swift index 3bdfc9902..d378cc8b4 100644 --- a/client/ios/DivKit/Extensions/DivVideoExtensions.swift +++ b/client/ios/DivKit/Extensions/DivVideoExtensions.swift @@ -40,7 +40,7 @@ extension DivVideo: DivBlockModeling { repeatable: repeatable, isMuted: muted, startPosition: elapsedTime.flatMap { CMTime(value: $0.value) } ?? .zero, - settingsPayload: playerSettingsPayload ?? [:] + settingsPayload: resolvePlayerSettingsPayload(resolver) ?? [:] ) let state: VideoBlockViewState = context.blockStateStorage diff --git a/client/ios/DivKit/generated_sources/DivVideo.swift b/client/ios/DivKit/generated_sources/DivVideo.swift index 10de2b0a1..214086499 100644 --- a/client/ios/DivKit/generated_sources/DivVideo.swift +++ b/client/ios/DivKit/generated_sources/DivVideo.swift @@ -31,7 +31,7 @@ public final class DivVideo: DivBase, @unchecked Sendable { public let muted: Expression // default value: false public let paddings: DivEdgeInsets? public let pauseActions: [DivAction]? - public let playerSettingsPayload: [String: Any]? + public let playerSettingsPayload: Expression<[String: Any]>? public let preloadRequired: Expression // default value: false public let preview: Expression? public let repeatable: Expression // default value: false @@ -79,6 +79,10 @@ public final class DivVideo: DivBase, @unchecked Sendable { resolver.resolveNumeric(muted) ?? false } + public func resolvePlayerSettingsPayload(_ resolver: ExpressionResolver) -> [String: Any]? { + resolver.resolveDict(playerSettingsPayload) + } + public func resolvePreloadRequired(_ resolver: ExpressionResolver) -> Bool { resolver.resolveNumeric(preloadRequired) ?? false } @@ -149,7 +153,7 @@ public final class DivVideo: DivBase, @unchecked Sendable { muted: try dictionary.getOptionalExpressionField("muted", context: context), paddings: try dictionary.getOptionalField("paddings", transform: { (dict: [String: Any]) in try DivEdgeInsets(dictionary: dict, context: context) }), pauseActions: try dictionary.getOptionalArray("pause_actions", transform: { (dict: [String: Any]) in try? DivAction(dictionary: dict, context: context) }), - playerSettingsPayload: try dictionary.getOptionalField("player_settings_payload", context: context), + playerSettingsPayload: try dictionary.getOptionalExpressionField("player_settings_payload", context: context), preloadRequired: try dictionary.getOptionalExpressionField("preload_required", context: context), preview: try dictionary.getOptionalExpressionField("preview", context: context), repeatable: try dictionary.getOptionalExpressionField("repeatable", context: context), @@ -201,7 +205,7 @@ public final class DivVideo: DivBase, @unchecked Sendable { muted: Expression? = nil, paddings: DivEdgeInsets? = nil, pauseActions: [DivAction]? = nil, - playerSettingsPayload: [String: Any]? = nil, + playerSettingsPayload: Expression<[String: Any]>? = nil, preloadRequired: Expression? = nil, preview: Expression? = nil, repeatable: Expression? = nil, @@ -426,7 +430,7 @@ extension DivVideo: Serializable { result["muted"] = muted.toValidSerializationValue() result["paddings"] = paddings?.toDictionary() result["pause_actions"] = pauseActions?.map { $0.toDictionary() } - result["player_settings_payload"] = playerSettingsPayload + result["player_settings_payload"] = playerSettingsPayload?.toValidSerializationValue() result["preload_required"] = preloadRequired.toValidSerializationValue() result["preview"] = preview?.toValidSerializationValue() result["repeatable"] = repeatable.toValidSerializationValue() diff --git a/client/ios/DivKit/generated_sources/DivVideoTemplate.swift b/client/ios/DivKit/generated_sources/DivVideoTemplate.swift index c75afdc70..88cee7cb3 100644 --- a/client/ios/DivKit/generated_sources/DivVideoTemplate.swift +++ b/client/ios/DivKit/generated_sources/DivVideoTemplate.swift @@ -32,7 +32,7 @@ public final class DivVideoTemplate: TemplateValue, @unchecked Sendable { public let muted: Field>? // default value: false public let paddings: Field? public let pauseActions: Field<[DivActionTemplate]>? - public let playerSettingsPayload: Field<[String: Any]>? + public let playerSettingsPayload: Field>? public let preloadRequired: Field>? // default value: false public let preview: Field>? public let repeatable: Field>? // default value: false @@ -84,7 +84,7 @@ public final class DivVideoTemplate: TemplateValue, @unchecked Sendable { muted: dictionary.getOptionalExpressionField("muted"), paddings: dictionary.getOptionalField("paddings", templateToType: templateToType), pauseActions: dictionary.getOptionalArray("pause_actions", templateToType: templateToType), - playerSettingsPayload: dictionary.getOptionalField("player_settings_payload"), + playerSettingsPayload: dictionary.getOptionalExpressionField("player_settings_payload"), preloadRequired: dictionary.getOptionalExpressionField("preload_required"), preview: dictionary.getOptionalExpressionField("preview"), repeatable: dictionary.getOptionalExpressionField("repeatable"), @@ -137,7 +137,7 @@ public final class DivVideoTemplate: TemplateValue, @unchecked Sendable { muted: Field>? = nil, paddings: Field? = nil, pauseActions: Field<[DivActionTemplate]>? = nil, - playerSettingsPayload: Field<[String: Any]>? = nil, + playerSettingsPayload: Field>? = nil, preloadRequired: Field>? = nil, preview: Field>? = nil, repeatable: Field>? = nil, @@ -401,7 +401,7 @@ public final class DivVideoTemplate: TemplateValue, @unchecked Sendable { var mutedValue: DeserializationResult> = parent?.muted?.value() ?? .noValue var paddingsValue: DeserializationResult = .noValue var pauseActionsValue: DeserializationResult<[DivAction]> = .noValue - var playerSettingsPayloadValue: DeserializationResult<[String: Any]> = parent?.playerSettingsPayload?.value() ?? .noValue + var playerSettingsPayloadValue: DeserializationResult> = parent?.playerSettingsPayload?.value() ?? .noValue var preloadRequiredValue: DeserializationResult> = parent?.preloadRequired?.value() ?? .noValue var previewValue: DeserializationResult> = parent?.preview?.value() ?? .noValue var repeatableValue: DeserializationResult> = parent?.repeatable?.value() ?? .noValue diff --git a/client/ios/DivKitTests/Entities/generated_sources/EntityWithJsonProperty.swift b/client/ios/DivKitTests/Entities/generated_sources/EntityWithJsonProperty.swift index 13926b78c..81af53ba8 100644 --- a/client/ios/DivKitTests/Entities/generated_sources/EntityWithJsonProperty.swift +++ b/client/ios/DivKitTests/Entities/generated_sources/EntityWithJsonProperty.swift @@ -9,18 +9,10 @@ import enum DivKit.Expression public final class EntityWithJsonProperty: @unchecked Sendable { public static let type: String = "entity_with_json_property" - public let jsonProperty: [String: Any] // default value: { "key": "value", "items": [ "value" ] } + public let jsonProperty: Expression<[String: Any]> // default value: { "key": "value", "items": [ "value" ] } - public convenience init(dictionary: [String: Any], context: ParsingContext) throws { - self.init( - jsonProperty: try dictionary.getOptionalField("json_property", context: context) - ) - } - - init( - jsonProperty: [String: Any]? = nil - ) { - self.jsonProperty = jsonProperty ?? (try! JSONSerialization.jsonObject(jsonString: """ + public func resolveJsonProperty(_ resolver: ExpressionResolver) -> [String: Any] { + resolver.resolveDict(jsonProperty) ?? (try! JSONSerialization.jsonObject(jsonString: """ { "key": "value", "items": [ @@ -29,6 +21,25 @@ public final class EntityWithJsonProperty: @unchecked Sendable { } """) as! [String: Any]) } + + public convenience init(dictionary: [String: Any], context: ParsingContext) throws { + self.init( + jsonProperty: try dictionary.getOptionalExpressionField("json_property", context: context) + ) + } + + init( + jsonProperty: Expression<[String: Any]>? = nil + ) { + self.jsonProperty = jsonProperty ?? .value((try! JSONSerialization.jsonObject(jsonString: """ + { + "key": "value", + "items": [ + "value" + ] + } + """) as! [String: Any])) + } } #if DEBUG @@ -45,7 +56,7 @@ extension EntityWithJsonProperty: Serializable { public func toDictionary() -> [String: ValidSerializationValue] { var result: [String: ValidSerializationValue] = [:] result["type"] = Self.type - result["json_property"] = jsonProperty + result["json_property"] = jsonProperty.toValidSerializationValue() return result } } diff --git a/client/ios/DivKitTests/Entities/generated_sources/EntityWithJsonPropertyTemplate.swift b/client/ios/DivKitTests/Entities/generated_sources/EntityWithJsonPropertyTemplate.swift index 2b3a454d7..b06882654 100644 --- a/client/ios/DivKitTests/Entities/generated_sources/EntityWithJsonPropertyTemplate.swift +++ b/client/ios/DivKitTests/Entities/generated_sources/EntityWithJsonPropertyTemplate.swift @@ -10,18 +10,18 @@ import enum DivKit.Expression public final class EntityWithJsonPropertyTemplate: TemplateValue, @unchecked Sendable { public static let type: String = "entity_with_json_property" public let parent: String? - public let jsonProperty: Field<[String: Any]>? // default value: { "key": "value", "items": [ "value" ] } + public let jsonProperty: Field>? // default value: { "key": "value", "items": [ "value" ] } public convenience init(dictionary: [String: Any], templateToType: [TemplateName: String]) throws { self.init( parent: dictionary["type"] as? String, - jsonProperty: dictionary.getOptionalField("json_property") + jsonProperty: dictionary.getOptionalExpressionField("json_property") ) } init( parent: String?, - jsonProperty: Field<[String: Any]>? = nil + jsonProperty: Field>? = nil ) { self.parent = parent self.jsonProperty = jsonProperty @@ -42,7 +42,7 @@ public final class EntityWithJsonPropertyTemplate: TemplateValue, @unchecked Sen if useOnlyLinks { return resolveOnlyLinks(context: context, parent: parent) } - var jsonPropertyValue: DeserializationResult<[String: Any]> = parent?.jsonProperty?.value() ?? .noValue + var jsonPropertyValue: DeserializationResult> = parent?.jsonProperty?.value() ?? .noValue context.templateData.forEach { key, __dictValue in switch key { case "json_property": diff --git a/schema/div-action-base.json b/schema/div-action-base.json index f3b5c6df5..ad0ac70a5 100644 --- a/schema/div-action-base.json +++ b/schema/div-action-base.json @@ -31,6 +31,7 @@ "payload": { "type": "object", "additionalProperties": true, + "supports_expressions": false, "$description": "translations.json#/div_action_base_payload" }, "download_callbacks": { diff --git a/schema/div-custom.json b/schema/div-custom.json index 10f615af5..151f61942 100644 --- a/schema/div-custom.json +++ b/schema/div-custom.json @@ -27,6 +27,7 @@ "custom_props": { "type": "object", "additionalProperties": true, + "supports_expressions": false, "$description": "translations.json#/div_custom_custom_props" } } diff --git a/schema/div-extension.json b/schema/div-extension.json index f4de505a8..f9e404afd 100644 --- a/schema/div-extension.json +++ b/schema/div-extension.json @@ -14,6 +14,7 @@ "params": { "type": "object", "additionalProperties": true, + "supports_expressions": false, "$description": "translations.json#/div_extension_params" } }, diff --git a/shared_data/phone-masks.json b/shared_data/phone-masks.json index 5ebba8983..1965653a6 100644 --- a/shared_data/phone-masks.json +++ b/shared_data/phone-masks.json @@ -77,6 +77,7 @@ }, "value": { "type": "object", + "supports_expressions": false, "additionalProperties": true, "default_value": { "1": { "$ref": "#/constants/short" },