Files
divkit/client/ios/DivKitTests/Entities/generated_sources/EntityWithJsonPropertyTemplate.swift
T
feldspar ce9af20a5b Revert parsing logic update
commit_hash:c9419f063b7f8c5df41675acc9ed49d862850a2c
2026-01-16 23:06:00 +03:00

81 lines
3.1 KiB
Swift

// Generated code. Do not modify.
@testable import DivKit
import Foundation
import Serialization
import VGSL
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 convenience init(dictionary: [String: Any], templateToType: [TemplateName: String]) throws {
self.init(
parent: dictionary["type"] as? String,
jsonProperty: dictionary.getOptionalField("json_property")
)
}
init(
parent: String?,
jsonProperty: Field<[String: Any]>? = nil
) {
self.parent = parent
self.jsonProperty = jsonProperty
}
private static func resolveOnlyLinks(context: TemplatesContext, parent: EntityWithJsonPropertyTemplate?) -> DeserializationResult<EntityWithJsonProperty> {
let jsonPropertyValue = parent?.jsonProperty?.resolveOptionalValue(context: context) ?? .noValue
let errors = mergeErrors(
jsonPropertyValue.errorsOrWarnings?.map { .nestedObjectError(field: "json_property", error: $0) }
)
let result = EntityWithJsonProperty(
jsonProperty: jsonPropertyValue.value
)
return errors.isEmpty ? .success(result) : .partialSuccess(result, warnings: NonEmptyArray(errors)!)
}
public static func resolveValue(context: TemplatesContext, parent: EntityWithJsonPropertyTemplate?, useOnlyLinks: Bool) -> DeserializationResult<EntityWithJsonProperty> {
if useOnlyLinks {
return resolveOnlyLinks(context: context, parent: parent)
}
var jsonPropertyValue: DeserializationResult<[String: Any]> = parent?.jsonProperty?.value() ?? .noValue
context.templateData.forEach { key, __dictValue in
switch key {
case "json_property":
jsonPropertyValue = deserialize(__dictValue).merged(with: jsonPropertyValue)
case parent?.jsonProperty?.link:
jsonPropertyValue = jsonPropertyValue.merged(with: { deserialize(__dictValue) })
default: break
}
}
let errors = mergeErrors(
jsonPropertyValue.errorsOrWarnings?.map { .nestedObjectError(field: "json_property", error: $0) }
)
let result = EntityWithJsonProperty(
jsonProperty: jsonPropertyValue.value
)
return errors.isEmpty ? .success(result) : .partialSuccess(result, warnings: NonEmptyArray(errors)!)
}
private func mergedWithParent(templates: [TemplateName: Any]) throws -> EntityWithJsonPropertyTemplate {
guard let parent = parent, parent != Self.type else { return self }
guard let parentTemplate = templates[parent] as? EntityWithJsonPropertyTemplate else {
throw DeserializationError.unknownType(type: parent)
}
let mergedParent = try parentTemplate.mergedWithParent(templates: templates)
return EntityWithJsonPropertyTemplate(
parent: nil,
jsonProperty: jsonProperty ?? mergedParent.jsonProperty
)
}
public func resolveParent(templates: [TemplateName: Any]) throws -> EntityWithJsonPropertyTemplate {
return try mergedWithParent(templates: templates)
}
}