Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsc committed Apr 16, 2024
1 parent 3412283 commit 2732cad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/SwaggerSwiftCore/Models/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ let container = try decoder.container(keyedBy: StringCodingKey.self)
"""

return """
\(accessControl.rawValue) init(from decoder: Decoder) throws {
\(accessControl.rawValue) init(from decoder: Decoder) throws {
\(functionBody.indentLines(1))
}
"""
Expand Down
19 changes: 17 additions & 2 deletions Tests/SwaggerSwiftCoreTests/SwaggerSwiftCoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ public struct Test: Codable, Sendable {
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let container = try decoder.container(keyedBy: StringCodingKey.self)
// Allows the backend to return badly formatted urls
if let urlString = try container.decodeIfPresent(String.self, forKey: .url) {
if let urlString = try container.decodeIfPresent(String.self, forKey: "url") {
self.url = URL(string: urlString)
} else {
self.url = nil
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: StringCodingKey.self)
try container.encodeIfPresent(url, forKey: "url")
}
}
""")
}
Expand All @@ -52,6 +57,16 @@ public struct Test: Codable, Sendable {
public init(url: URL) {
self.url = url
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
self.url = try container.decode(URL.self, forKey: "url")
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: StringCodingKey.self)
try container.encode(url, forKey: "url")
}
}
""")
}
Expand Down

0 comments on commit 2732cad

Please sign in to comment.