ClawdisKit: accept jpg for canvas.snapshot
This commit is contained in:
@@ -19,6 +19,24 @@ public struct ClawdisCanvasEvalParams: Codable, Sendable, Equatable {
|
||||
public enum ClawdisCanvasSnapshotFormat: String, Codable, Sendable {
|
||||
case png
|
||||
case jpeg
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let c = try decoder.singleValueContainer()
|
||||
let raw = try c.decode(String.self).trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
|
||||
switch raw {
|
||||
case "png":
|
||||
self = .png
|
||||
case "jpeg", "jpg":
|
||||
self = .jpeg
|
||||
default:
|
||||
throw DecodingError.dataCorruptedError(in: c, debugDescription: "Invalid snapshot format: \(raw)")
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var c = encoder.singleValueContainer()
|
||||
try c.encode(self.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
public struct ClawdisCanvasSnapshotParams: Codable, Sendable, Equatable {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import ClawdisKit
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
@Suite struct CanvasSnapshotFormatTests {
|
||||
@Test func acceptsJpgAlias() throws {
|
||||
struct Wrapper: Codable {
|
||||
var format: ClawdisCanvasSnapshotFormat
|
||||
}
|
||||
|
||||
let data = try #require("{\"format\":\"jpg\"}".data(using: .utf8))
|
||||
let decoded = try JSONDecoder().decode(Wrapper.self, from: data)
|
||||
#expect(decoded.format == .jpeg)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user