From b47d064fe9008d306d13b54fcaf1c6bec7dd136a Mon Sep 17 00:00:00 2001 From: Victor Shabanov Date: Thu, 17 Oct 2019 15:19:04 +0300 Subject: [PATCH] Add public visibility for swift module --- Swift/ApiDateFormattingService.swift.twig | 14 +++++++------- Swift/ApiNumberFormattingService.swift.twig | 16 ++++++++-------- Swift/Class.swift.twig | 14 +++++++------- Swift/Enum.swift.twig | 2 +- Swift/NetworkService.swift.twig | 20 ++++++++++---------- Swift/blocks/class/copy-declaration.twig | 4 ++-- Swift/blocks/class/fields.twig | 2 +- Swift/blocks/method/method-declaration.twig | 2 +- Swift/blocks/method/method-func.twig | 2 +- 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Swift/ApiDateFormattingService.swift.twig b/Swift/ApiDateFormattingService.swift.twig index 772efe0..380b98f 100644 --- a/Swift/ApiDateFormattingService.swift.twig +++ b/Swift/ApiDateFormattingService.swift.twig @@ -6,28 +6,28 @@ import LeadKit import SwiftDate -enum ApiDateFormat: String, DateFormat { +public enum ApiDateFormat: String, DateFormat { {% for format in dateFormats -%} case {{ format.name }} = "{{ format.format }}" {% endfor %} - var dateToStringFormat: DateToStringStyles { + public var dateToStringFormat: DateToStringStyles { return .custom(rawValue) } - var stringToDateFormat: StringToDateStyles { + public var stringToDateFormat: StringToDateStyles { return .custom(rawValue) } } -final class ApiDateFormattingService: DateFormattingService, Singleton { +public final class ApiDateFormattingService: DateFormattingService, Singleton { - typealias DateFormatType = ApiDateFormat + public typealias DateFormatType = ApiDateFormat - var currentRegion: Region = .local + public static let shared = ApiDateFormattingService() - static let shared = ApiDateFormattingService() + public var currentRegion: Region = .local private init() {} diff --git a/Swift/ApiNumberFormattingService.swift.twig b/Swift/ApiNumberFormattingService.swift.twig index b7598b5..690f4df 100644 --- a/Swift/ApiNumberFormattingService.swift.twig +++ b/Swift/ApiNumberFormattingService.swift.twig @@ -3,11 +3,11 @@ import LeadKit import Foundation -enum ApiNumberFormat: NumberFormat { +public enum ApiNumberFormat: NumberFormat { case decimal - var numberFormatter: NumberFormatter { + public var numberFormatter: NumberFormatter { let numberFormatter = NumberFormatter() numberFormatter.decimalSeparator = "." numberFormatter.minimumIntegerDigits = 1 @@ -17,17 +17,17 @@ enum ApiNumberFormat: NumberFormat { } } -final class ApiNumberFormattingService: NumberFormattingService, Singleton { +public final class ApiNumberFormattingService: NumberFormattingService, Singleton { - typealias NumberFormatType = ApiNumberFormat + public typealias NumberFormatType = ApiNumberFormat - let formatters = computedFormatters + public static let shared = ApiNumberFormattingService() - static let shared = ApiNumberFormattingService() + public let formatters = computedFormatters private init() {} - func decimalNumber(from string: String, format: ApiNumberFormat) -> NSDecimalNumber? { + public func decimalNumber(from string: String, format: ApiNumberFormat) -> NSDecimalNumber? { guard let number = number(from: string, format: format) else { return nil } @@ -37,7 +37,7 @@ final class ApiNumberFormattingService: NumberFormattingService, Singleton { extension ApiNumberFormattingService { - static func decimalNumber(from string: String, format: ApiNumberFormat) -> NSDecimalNumber? { + public static func decimalNumber(from string: String, format: ApiNumberFormat) -> NSDecimalNumber? { return shared.decimalNumber(from: string, format: format) } } diff --git a/Swift/Class.swift.twig b/Swift/Class.swift.twig index 07ceec1..09dab07 100644 --- a/Swift/Class.swift.twig +++ b/Swift/Class.swift.twig @@ -14,12 +14,12 @@ import SwiftDate import LeadKit /// {{ description }} -{% if (not hasChilds) -%}final {% endif %}class {{ classType }}: {{ parentClassType }} { +public {% if (not hasChilds) -%}final {% endif %}class {{ classType }}: {{ parentClassType }} { {% include 'blocks/class/coding-keys.twig' with { fields: fields } %} {% include 'blocks/class/fields.twig' with { fields: fields } %} // MARK: - Initializers - {% if (hasParent and (fields is empty)) %} override {% endif %}init({%- include 'blocks/class/init-parameters-fields.twig' with { fields: allFieldsOrdered } -%}) { + public {% if (hasParent and (fields is empty)) %} override {% endif %}init({%- include 'blocks/class/init-parameters-fields.twig' with { fields: allFieldsOrdered } -%}) { {%- include 'blocks/class/fields-initialization.twig' with { fields: fields } -%} {% if hasParent %} super.init({%- include 'blocks/class/fields-super-initialization.twig' with { fields: superclassesFields } -%}) @@ -27,7 +27,7 @@ import LeadKit } {% if hasParent or fields is not empty %} - required init(from decoder: Decoder) throws { + public required init(from decoder: Decoder) throws { {%- if fields is not empty %} {% include 'blocks/class/fields-initialization-from-decoder.twig' with { fields: fields} %} {%- endif -%} @@ -37,7 +37,7 @@ import LeadKit } {% endif %} - {% if hasParent -%}override {% endif %}func encode(to encoder: Encoder) throws { + public {% if hasParent -%}override {% endif %}func encode(to encoder: Encoder) throws { {%- if fields is not empty %} {% include 'blocks/class/fields-encode-to-encoder.twig' with { fields: fields} %} {%- endif -%} @@ -47,7 +47,7 @@ import LeadKit } {% if classAndFieldsHaveNotGenericsOrNonEqutableCollections -%} - func isEqual(to other: {{ classType }}?) -> Bool { + public func isEqual(to other: {{ classType }}?) -> Bool { {% if (fields is empty) and (not hasParent) %} return false {% else %} @@ -64,7 +64,7 @@ import LeadKit {%- if (not hasChilds) and classAndFieldsHaveNotGenericsOrNonEqutableCollections -%} extension {{ type.baseTypeName }}: Equatable { - static func ==(lhs: {{ classType }}, rhs: {{ classType }}) -> Bool { + public static func ==(lhs: {{ classType }}, rhs: {{ classType }}) -> Bool { return lhs.isEqual(to: rhs) } } @@ -74,7 +74,7 @@ extension {{ type.baseTypeName }}: Equatable { {%- if classAndFieldsHaveNotGenericsOrNonEqutableCollections -%} extension {{ type.baseTypeName }} { - static let new{{ type.baseTypeName }} = {{ type.baseTypeName }}({%- include 'blocks/class/fields-initialization-default-values.twig' with { fields: allFieldsOrdered } -%}) + public static let new{{ type.baseTypeName }} = {{ type.baseTypeName }}({%- include 'blocks/class/fields-initialization-default-values.twig' with { fields: allFieldsOrdered } -%}) {% include 'blocks/class/copy-declaration.twig' with { hasChilds: hasChilds, type: type, fields: allFieldsOrdered } %} } diff --git a/Swift/Enum.swift.twig b/Swift/Enum.swift.twig index dd5a123..6f65c94 100644 --- a/Swift/Enum.swift.twig +++ b/Swift/Enum.swift.twig @@ -6,7 +6,7 @@ {% for value in values -%} /// - {{ utils.decapitalize(value.name) }}: {{ value.description }} {% endfor -%} -enum {{ name }}: {{ enumutils.enumType(valuesTypes) }}, Codable, RawRepresentable, CaseIterable { +public enum {{ name }}: {{ enumutils.enumType(valuesTypes) }}, Codable, RawRepresentable, CaseIterable { {% include 'blocks/enum/cases.twig' with { values: values } %} } {{ "\n" }} \ No newline at end of file diff --git a/Swift/NetworkService.swift.twig b/Swift/NetworkService.swift.twig index 909dfef..ebd5b59 100644 --- a/Swift/NetworkService.swift.twig +++ b/Swift/NetworkService.swift.twig @@ -5,7 +5,7 @@ import Alamofire {% set serviceName = concat(networkServiceName, "NetworkService") -%} {% set protocolName = concat(networkServiceName, "NetworkProtocol") -%} -protocol {{ protocolName }} { +public protocol {{ protocolName }} { func apiRequest(with parametersSingle: Single, additionalValidStatusCodes: Set, decoder: JSONDecoder) -> Single func deferredApiRequestParameters(relativeUrl: String, @@ -19,25 +19,25 @@ protocol {{ protocolName }} { {% endfor %} } -class {{ serviceName }}: NetworkService, {{ protocolName }} { +open class {{ serviceName }}: NetworkService, {{ protocolName }} { - static let apiBaseUrl = "{{ apiUrl }}" + public static let apiBaseUrl = "{{ apiUrl }}" - convenience init() { + public convenience init() { self.init(configuration: NetworkServiceConfiguration(baseUrl: {{ serviceName }}.apiBaseUrl)) } - func apiRequest(with parametersSingle: Single, additionalValidStatusCodes: Set = [], decoder: JSONDecoder = JSONDecoder()) -> Single { + open func apiRequest(with parametersSingle: Single, additionalValidStatusCodes: Set = [], decoder: JSONDecoder = JSONDecoder()) -> Single { return parametersSingle.flatMap { self.rxRequest(with: $0, additionalValidStatusCodes: additionalValidStatusCodes, decoder: decoder).map { $0.model }.asSingle() } } - func deferredApiRequestParameters(relativeUrl: String, - method: HTTPMethod = .get, - parameters: Parameters? = nil, - requestEncoding: ParameterEncoding? = nil, - requestHeaders: HTTPHeaders? = nil) -> Single { + open func deferredApiRequestParameters(relativeUrl: String, + method: HTTPMethod = .get, + parameters: Parameters? = nil, + requestEncoding: ParameterEncoding? = nil, + requestHeaders: HTTPHeaders? = nil) -> Single { return .deferredJust { self.configuration.apiRequestParameters(relativeUrl: relativeUrl, method: method, diff --git a/Swift/blocks/class/copy-declaration.twig b/Swift/blocks/class/copy-declaration.twig index d05d1b4..e501e6a 100644 --- a/Swift/blocks/class/copy-declaration.twig +++ b/Swift/blocks/class/copy-declaration.twig @@ -1,6 +1,6 @@ {%- import '../../macroses/common.utils.twig' as utils -%} - func copy{%- if hasChilds -%}{{ type.baseTypeName }}{%- endif -%}With({%- include '../class/nullable-parameters-fields.twig' with { fields: allFieldsOrdered } -%}) -> {{ type.baseTypeName }} { + public func copy{%- if hasChilds -%}{{ type.baseTypeName }}{%- endif -%}With({%- include '../class/nullable-parameters-fields.twig' with { fields: allFieldsOrdered } -%}) -> {{ type.baseTypeName }} { return {{ type.baseTypeName }}({% include '../class/fields-optional-initialization.twig' with { fields: allFieldsOrdered } %}) } @@ -14,7 +14,7 @@ {% if containsOptionalFields %} - func copy{%- if hasChilds -%}{{ type.baseTypeName }}{%- endif -%}Without({%- include '../class/bool-parameters-fields.twig' with { fields: allFieldsOrdered } -%}) -> {{ type.baseTypeName }} { + public func copy{%- if hasChilds -%}{{ type.baseTypeName }}{%- endif -%}Without({%- include '../class/bool-parameters-fields.twig' with { fields: allFieldsOrdered } -%}) -> {{ type.baseTypeName }} { return {{ type.baseTypeName }}({%- include '../class/fields-without-initialization.twig' with { fields: allFieldsOrdered } -%}) } {% endif %} \ No newline at end of file diff --git a/Swift/blocks/class/fields.twig b/Swift/blocks/class/fields.twig index 65f95d9..8a5455b 100644 --- a/Swift/blocks/class/fields.twig +++ b/Swift/blocks/class/fields.twig @@ -4,6 +4,6 @@ // MARK: - Fields {% for field in fields %} /// {{ field.description }} - let {{ field.name }}: {{ utils.formatNullableOrOptional(utils.formatValueType(field.type.type), field.nullable, field.optional) }} + public let {{ field.name }}: {{ utils.formatNullableOrOptional(utils.formatValueType(field.type.type), field.nullable, field.optional) }} {% endfor -%} {% endif %} \ No newline at end of file diff --git a/Swift/blocks/method/method-declaration.twig b/Swift/blocks/method/method-declaration.twig index 2bb2448..529094e 100644 --- a/Swift/blocks/method/method-declaration.twig +++ b/Swift/blocks/method/method-declaration.twig @@ -9,4 +9,4 @@ {%- set funcName = utils.decapitalize(method.name) -%} -{{ isStatic ? "static " : "" }}func {{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyTypeName }},{{ " " }}{%- endif -%}requestEncoding: ParameterEncoding?, requestHeaders: HTTPHeaders?, additionalValidStatusCodes: Set) -> Single<{{ method.responseType.type.typeName }}> +public {{ isStatic ? "static " : "" }}func {{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyTypeName }},{{ " " }}{%- endif -%}requestEncoding: ParameterEncoding?, requestHeaders: HTTPHeaders?, additionalValidStatusCodes: Set) -> Single<{{ method.responseType.type.typeName }}> diff --git a/Swift/blocks/method/method-func.twig b/Swift/blocks/method/method-func.twig index 2a08c0c..f9df44d 100644 --- a/Swift/blocks/method/method-func.twig +++ b/Swift/blocks/method/method-func.twig @@ -11,7 +11,7 @@ {%- set funcName = utils.decapitalize(method.name) -%} /// {{ method.description }} - {{ isStatic ? "static " : "" }}func {{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyTypeName }},{{ "\n " }}{%- endif -%} + public {{ isStatic ? "static " : "" }}func {{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyTypeName }},{{ "\n " }}{%- endif -%} requestEncoding: ParameterEncoding? = nil, requestHeaders: HTTPHeaders? = nil, additionalValidStatusCodes: Set = []) -> Single<{{ method.responseType.type.typeName }}> {