{%- for e in outline.enums() %} {%- if e.members().len() > 0 %} /// ## {{ e.title() }} /// /// {{ e.desc }} public enum {{ e.name() }}: String, Codable { {%- for m in e.members() %} /// ### {{ m.title() }} /// /// {{ m.desc() }} case {{ m.name()|escape_swift }} = "{{ m.name() }}" {%- endfor %} } {%- endif %} {%- endfor %} {%- for path_argument in outline.path_arguments() %} public class {{ path_argument.name() }}: Codable { {%- for item in path_argument.items() %} public let {{ item|escape_swift }}: String {%- endfor %} public init( {%- for item in path_argument.items() %} {{ item|escape_swift }}: String{% if !loop.last %},{% endif %} {%- endfor %} ) { {%- for item in path_argument.items() %} self.{{ item }} = {{ item|escape_swift }}, {%- endfor %} } } {%- endfor %} {%- for interface in outline.interfaces() %} {%- if interface.fields_optional_at_last().len() > 0 %} {%- if interface.name().ends_with("AtomicUpdateOperationInput") %} public enum {{ interface.name() }} : Codable where T: Codable { {%- for field in interface.fields_optional_at_last() %} case {{ field.name()|escape_swift }}({{ lookup.call(field.type().unwrap_optional()).unwrap() }}) {%- endfor %} enum CodingKeys: CodingKey { {%- for field in interface.fields_optional_at_last() %} case {{ field.name()|escape_swift }} {%- endfor %} } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: {{ interface.name() }}.CodingKeys.self) switch self { {%- for field in interface.fields_optional_at_last() %} case .{{ field.name()|escape_swift }}(let a0): try container.encode(a0, forKey: .{{ field.name() }}) {%- endfor %} } } public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) for key in container.allKeys { switch key { {%- for field in interface.fields_optional_at_last() %} case .{{ field.name()|escape_swift }}: self = Self.{{ field.name()|escape_swift }}(try container.decode({{ lookup.call(field.type().unwrap_optional()).unwrap() }}.self, forKey: key)) return {%- endfor %} } } fatalError("invalid input for enum value decoder") } } {%- else if interface.name().ends_with("OrderByInput") %} public enum {{ interface.name() }}: Codable { {%- for field in interface.fields_optional_at_last() %} case {{ field.name()|escape_swift }}({{ lookup.call(field.type().unwrap_optional()).unwrap() }}) {%- endfor %} enum CodingKeys: CodingKey { {%- for field in interface.fields_optional_at_last() %} case {{ field.name()|escape_swift }} {%- endfor %} } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) switch self { {%- for field in interface.fields_optional_at_last() %} case .{{ field.name()|escape_swift }}(let a0): try! container.encode(a0, forKey: .{{ field.name() }}) {%- endfor %} } } public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) for key in container.allKeys { switch key { {%- for field in interface.fields_optional_at_last() %} case .{{ field.name()|escape_swift }}: self = Self.{{ field.name()|escape_swift }}(try container.decode({{ lookup.call(field.type().unwrap_optional()).unwrap() }}.self, forKey: key)) return {%- endfor %} } } fatalError("invalid input for enum value decoder") } } {%- else %} /** * **{{ interface.title() }}** * * {{ interface.desc() }} */ public class {{ interface.name() }}{{ interface.generics_declaration() }} : Codable{{ where_codable(interface) }} { {%- for field in interface.fields_optional_at_last() %} public let {{ field.name()|escape_swift }}: {{ lookup.call(field.type().unwrap_optional()).unwrap() }}{%- if field.type().is_optional() || interface.is_output_result() %}?{%- endif %} {%- endfor %} public init( {%- for field in interface.fields_optional_at_last() %} {%- if lookup.call(field.type().unwrap_optional()).unwrap().as_str() == "AnyCodable" %} {{ field.name()|escape_swift }}: Codable{% if field.type().is_optional() || interface.is_output_result() %}? = nil{% endif %}{%- if !loop.last %},{% endif %} {%- else %} {{ field.name()|escape_swift }}: {{ lookup.call(field.type().unwrap_optional()).unwrap() }}{% if field.type().is_optional() || interface.is_output_result() %}? = nil{% endif %}{%- if !loop.last %},{% endif %} {%- endif %} {%- endfor %} ) { {%- for field in interface.fields_optional_at_last() %} {%- if lookup.call(field.type().unwrap_optional()).unwrap().as_str() == "AnyCodable" %} self.{{ field.name() }} = AnyCodable.fromValue({{ field.name()|escape_swift }})! {%- else %} self.{{ field.name() }} = {{ field.name()|escape_swift }} {%- endif %} {%- endfor %} } } {%- endif %} {%- endif %} {%- endfor %} {%- for delegate in outline.delegates() %} public class {{ delegate.name_with_conf(conf.class_name().to_string()) }} { public let _headers: Dictionary? {%- for namespace_item in delegate.namespace_items() %} {%- if !namespace_item.is_std() %} lazy var {{ namespace_item.property_name() }}: {{ namespace_item.path().join(".") }} = { {{ namespace_item.path().join(".") }}(_headers) }(); {%- endif %} {%- endfor %} {%- for group_item in delegate.group_items() %} lazy var {{ group_item.property_name() }}: {{ group_item.path().join(".") }} = { {{ group_item.path().join(".") }}(_headers) }(); {%- endfor %} public init(_ headers: Dictionary? = nil) { self._headers = headers } {%- for request_item in delegate.request_items() %} public func {{ request_item.name() }}({% if request_item.has_custom_url_args() %}pathArgs: Dictionary, {% endif %}{% if request_item.has_body_input() %}input: {{ lookup.call(request_item.input_type()).unwrap() }}{% endif %}, headers: Dictionary? = nil{% if !request_item.is_builtin() %}, query: String? = nil{% endif %}) async -> {{ lookup.call(request_item.output_type()).unwrap() }} { return await jsonRequest("{{ request_item.method() }}", {% if request_item.has_custom_url_args() %}replacePathArguments({% endif %}"{{ request_item.path() }}"{% if request_item.has_custom_url_args() %}, pathArgs){% endif %}, {% if request_item.has_body_input() %}input{% else %}nil{% endif %}, headers ?? _headers{% if !request_item.is_builtin() %}, query{% else %}, nil{% endif %}) } {%- endfor %} } {% endfor %} {%- for namespace in namespace.namespaces().values() %} {{ render_namespace(namespace, conf, main_namespace) }} {%- endfor %}