From e3e287c85f518a8a2841af1c05698a5e3182f933 Mon Sep 17 00:00:00 2001 From: Ilyar Mnazhdin Date: Mon, 19 Feb 2024 16:08:19 +0600 Subject: [PATCH] =?UTF-8?q?PORTFOLIO-26801:=20=D0=B8=D0=B2=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=B7=D0=BF=D1=82=20(#57)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * добавил модельки ивентов зпт * удалил пустые MARK-и * добавил hhMobileUUID в category в external event-е * удалил лишние модели * добавил пример зпт ивента * добавил в event edition * добавил eventEdition для event-а, чтобы отличать приложения * пофиксил генерацию edition * добавил примеры с edition в Example * добавил accessModifier для сгенерированных edition * убрал инфу о том, кто создал файл :) * удалил лишнюю строку * если edition не указан, то для внешних event-ов будет [.hh, .jtb] --------- Co-authored-by: i.mnazhdin <> --- .../paid_services/paid_service_button_click.yaml | 1 + .../zarplata/zp_authorization_success.yaml | 14 ++++++++++++++ Example/specification/specification.yaml | 8 +++++++- .../Generators/Event/DefaultEventGenerator.swift | 4 +++- .../Generators/Event/ExternalEventContext.swift | 1 + .../Generators/Event/InternalEventContext.swift | 1 + Sources/AnalyticsGen/Models/Event/Event.swift | 1 + .../AnalyticsGen/Models/Event/EventEdition.swift | 10 ++++++++++ .../Event/External/ExternalEventAction.swift | 2 -- .../Event/External/ExternalEventCategory.swift | 1 + .../Models/Event/External/ExternalEventLabel.swift | 2 -- Templates/ExternalEvent.stencil | 9 +++++++++ Templates/InternalEvent.stencil | 9 +++++++++ 13 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 Example/schemas/applicant/zarplata/zp_authorization_success.yaml create mode 100644 Sources/AnalyticsGen/Models/Event/EventEdition.swift diff --git a/Example/schemas/applicant/paid_services/paid_service_button_click.yaml b/Example/schemas/applicant/paid_services/paid_service_button_click.yaml index 4bfdb8e..1d97785 100644 --- a/Example/schemas/applicant/paid_services/paid_service_button_click.yaml +++ b/Example/schemas/applicant/paid_services/paid_service_button_click.yaml @@ -3,6 +3,7 @@ description: Пользователь нажал на платный серви category: Соискательские сервисы application: applicant platform: Android/iOS +edition: [zp, hh, jtb] external: category: anonymous/applicant diff --git a/Example/schemas/applicant/zarplata/zp_authorization_success.yaml b/Example/schemas/applicant/zarplata/zp_authorization_success.yaml new file mode 100644 index 0000000..9ef73f0 --- /dev/null +++ b/Example/schemas/applicant/zarplata/zp_authorization_success.yaml @@ -0,0 +1,14 @@ +--- +name: Событие успешной авторизации (ZP) +description: Пользователь успешно авторизовался (отправляется только для ZP) +category: Авторизация +application: applicant +platform: Android/iOS +edition: [zp] + +external: + category: hhmobile_uuid + action: eventLoginSuccessful + label: + type: string + description: hhmobile_uuid пользователя diff --git a/Example/specification/specification.yaml b/Example/specification/specification.yaml index 3558752..b41be49 100644 --- a/Example/specification/specification.yaml +++ b/Example/specification/specification.yaml @@ -9,7 +9,7 @@ definitions: # Категория события category: type: string - enum: [anonymous, applicant, anonymous/applicant, employer] + enum: [anonymous, applicant, anonymous/applicant, employer, hhmobile_uudid] # Action события action: type: string @@ -68,6 +68,12 @@ definitions: application: type: string enum: [applicant, employer] + # Приложение (hh, jtb, zp) + edition: + type: array + items: + type: string + enum: [hh, jtb, zp] # Эксперимент experiment: type: object diff --git a/Sources/AnalyticsGen/Generators/Event/DefaultEventGenerator.swift b/Sources/AnalyticsGen/Generators/Event/DefaultEventGenerator.swift index 0b0912d..abbcbba 100644 --- a/Sources/AnalyticsGen/Generators/Event/DefaultEventGenerator.swift +++ b/Sources/AnalyticsGen/Generators/Event/DefaultEventGenerator.swift @@ -59,7 +59,7 @@ final class DefaultEventGenerator: EventGenerator { private func resolveExternalEventCategory(event: ExternalEvent) -> ExternalEventContext.Category { switch event.category { - case .anonymous, .applicant, .employer: + case .anonymous, .applicant, .employer, .hhMobileUUID: return .init(value: event.category.rawValue, oneOf: nil) case .anonymousApplicant: return .init( @@ -103,6 +103,7 @@ final class DefaultEventGenerator: EventGenerator { parameters.render.internalTemplate, to: parameters.render.destination.appending(path: "\(filename)Event.swift"), context: InternalEventContext( + edition: event.edition, deprecated: event.deprecated ?? false, name: event.name, description: event.description, @@ -135,6 +136,7 @@ final class DefaultEventGenerator: EventGenerator { parameters.render.externalTemplate, to: parameters.render.destination.appending(path: "\(filename)ExternalEvent.swift"), context: ExternalEventContext( + edition: event.edition, deprecated: event.deprecated ?? false, name: event.name, description: event.description, diff --git a/Sources/AnalyticsGen/Generators/Event/ExternalEventContext.swift b/Sources/AnalyticsGen/Generators/Event/ExternalEventContext.swift index dfb96e4..2b6081f 100644 --- a/Sources/AnalyticsGen/Generators/Event/ExternalEventContext.swift +++ b/Sources/AnalyticsGen/Generators/Event/ExternalEventContext.swift @@ -44,6 +44,7 @@ struct ExternalEventContext: Encodable { // MARK: - Instance Properties + let edition: [EventEdition]? let deprecated: Bool let name: String let description: String? diff --git a/Sources/AnalyticsGen/Generators/Event/InternalEventContext.swift b/Sources/AnalyticsGen/Generators/Event/InternalEventContext.swift index 0c71549..da5b187 100644 --- a/Sources/AnalyticsGen/Generators/Event/InternalEventContext.swift +++ b/Sources/AnalyticsGen/Generators/Event/InternalEventContext.swift @@ -27,6 +27,7 @@ struct InternalEventContext: Encodable { // MARK: - Instance Properties + let edition: [EventEdition]? let deprecated: Bool let name: String let description: String? diff --git a/Sources/AnalyticsGen/Models/Event/Event.swift b/Sources/AnalyticsGen/Models/Event/Event.swift index 429f32b..c867482 100644 --- a/Sources/AnalyticsGen/Models/Event/Event.swift +++ b/Sources/AnalyticsGen/Models/Event/Event.swift @@ -5,6 +5,7 @@ struct Event: Decodable { // MARK: - Instance Properties let application: EventApplication + let edition: [EventEdition]? let deprecated: Bool? let category: String let description: String? diff --git a/Sources/AnalyticsGen/Models/Event/EventEdition.swift b/Sources/AnalyticsGen/Models/Event/EventEdition.swift new file mode 100644 index 0000000..e251478 --- /dev/null +++ b/Sources/AnalyticsGen/Models/Event/EventEdition.swift @@ -0,0 +1,10 @@ +import Foundation + +enum EventEdition: String, Codable { + + // MARK: - Enumeration Cases + + case hh + case jtb + case zp +} diff --git a/Sources/AnalyticsGen/Models/Event/External/ExternalEventAction.swift b/Sources/AnalyticsGen/Models/Event/External/ExternalEventAction.swift index 8e3de6d..a384fc1 100644 --- a/Sources/AnalyticsGen/Models/Event/External/ExternalEventAction.swift +++ b/Sources/AnalyticsGen/Models/Event/External/ExternalEventAction.swift @@ -32,8 +32,6 @@ enum ExternalEventAction: Decodable { } } -// MARK: - - extension ExternalEventAction { // MARK: - Instance Properties diff --git a/Sources/AnalyticsGen/Models/Event/External/ExternalEventCategory.swift b/Sources/AnalyticsGen/Models/Event/External/ExternalEventCategory.swift index 977f14c..d77f4c9 100644 --- a/Sources/AnalyticsGen/Models/Event/External/ExternalEventCategory.swift +++ b/Sources/AnalyticsGen/Models/Event/External/ExternalEventCategory.swift @@ -8,4 +8,5 @@ enum ExternalEventCategory: String, Decodable { case anonymousApplicant = "anonymous/applicant" case applicant case employer + case hhMobileUUID = "hhmobile_uuid" } diff --git a/Sources/AnalyticsGen/Models/Event/External/ExternalEventLabel.swift b/Sources/AnalyticsGen/Models/Event/External/ExternalEventLabel.swift index 4501e02..958f6a9 100644 --- a/Sources/AnalyticsGen/Models/Event/External/ExternalEventLabel.swift +++ b/Sources/AnalyticsGen/Models/Event/External/ExternalEventLabel.swift @@ -29,8 +29,6 @@ enum ExternalEventLabel: Decodable { } } -// MARK: - - extension ExternalEventLabel { // MARK: - Instance Properties diff --git a/Templates/ExternalEvent.stencil b/Templates/ExternalEvent.stencil index b1f6637..6d7d6c4 100644 --- a/Templates/ExternalEvent.stencil +++ b/Templates/ExternalEvent.stencil @@ -31,6 +31,15 @@ import Analytics } {% endif %} + {{ accessModifier }} var edition: [AnalyticsEventEdition] { + {% if edition %} + {% map edition into enumValueEdition %}.{{ maploop.item }}{% endmap %} + [{{ enumValueEdition|join:", " }}] + {% else %} + [.hh, .jtb] + {% endif %} + } + {% if category.oneOf %} {{ accessModifier }} enum Category: String { {% for oneOf in category.oneOf %} diff --git a/Templates/InternalEvent.stencil b/Templates/InternalEvent.stencil index 7d58b0b..3f607bc 100644 --- a/Templates/InternalEvent.stencil +++ b/Templates/InternalEvent.stencil @@ -23,6 +23,15 @@ import Analytics */ {{ accessModifier }} struct {{ structName }}: {{ protocol }} { + {{ accessModifier }} var edition: [AnalyticsEventEdition] { + {% if edition %} + {% map edition into enumValueEdition %}.{{ maploop.item }}{% endmap %} + [{{ enumValueEdition|join:", " }}] + {% else %} + .any + {% endif %} + } + {{ accessModifier }} enum CodingKeys: String, CodingKey { {% for parameter in parameters %} case {% call propertyName parameter.name %} = "{{ parameter.name }}"