Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift test mocking enchancements #315

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stone/backends/swift_rsrc/SwiftRoutes.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import Foundation

/// Routes for the {{ class_name(namespace.name) }} namespace
/// For Objective-C compatible routes see DB{{ fmt_class(namespace.name) }}Routes
public class {{ fmt_class(class_name(namespace.name)) }}Routes {
public class {{ fmt_class(class_name(namespace.name)) }}Routes: DropboxTransportClientOwning {
public let client: {{ transport_client_name }}
init(client: {{ transport_client_name }}) {
required init(client: {{ transport_client_name }}) {
self.client = client
}

Expand Down
19 changes: 15 additions & 4 deletions stone/backends/swift_rsrc/SwiftTypes.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class {{ fmt_class(namespace.name) }} {
{% for data_type in namespace.linearize_data_types() %}
{{ data_type_doc(data_type) }}
{% if is_struct_type(data_type) %}
public class {{ fmt_class(data_type.name) }}: {{ 'CustomStringConvertible' if not data_type.parent_type else fmt_type(data_type.parent_type) }} {
public class {{ fmt_class(data_type.name) }}: {{ 'CustomStringConvertible, JSONRepresentable' if not data_type.parent_type else fmt_type(data_type.parent_type) }} {
{% for field in data_type.fields %}
{{ struct_field_doc(field) }}
public let {{ fmt_var(field.name) }}: {{ fmt_type(field.data_type) }}
Expand All @@ -29,11 +29,18 @@ public class {{ fmt_class(namespace.name) }} {
{% endif %}
}
{% endif %}

{% if not data_type.parent_type %}
func json() throws -> JSON {
try {{ fmt_class(data_type.name) }}Serializer().serialize(self)
}
{% endif %}

{{ 'public var' if not data_type.parent_type else 'public override var' }} description: String {
do {
return "\(SerializeUtil.prepareJSONForSerialization(try {{ fmt_class(data_type.name) }}Serializer().serialize(self)))"
} catch {
return "\(self)"
return "Failed to generate description for {{ fmt_class(data_type.name) }}: \(error)"
}
}
}
Expand Down Expand Up @@ -96,17 +103,21 @@ public class {{ fmt_class(namespace.name) }} {
}
}
{% elif is_union_type(data_type) %}
public enum {{ fmt_class(data_type.name) }}: CustomStringConvertible {
public enum {{ fmt_class(data_type.name) }}: CustomStringConvertible, JSONRepresentable {
{% for field in data_type.all_fields %}
{{ union_field_doc(field) }}
case {{ fmt_var(field.name) }}{{ format_tag_type(field.data_type) }}
{% endfor %}

func json() throws -> JSON {
try {{ fmt_class(data_type.name) }}Serializer().serialize(self)
}

public var description: String {
do {
return "\(SerializeUtil.prepareJSONForSerialization(try {{ fmt_class(data_type.name) }}Serializer().serialize(self)))"
} catch {
return "\(self)"
return "Failed to generate description for {{ fmt_class(data_type.name) }}: \(error)"
}
}
}
Expand Down
Loading