Skip to content
Closed
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
1 change: 0 additions & 1 deletion Sources/FigmaAPI/Endpoint/BaseEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ extension BaseEndpoint {
extension JSONDecoder {
static let `default`: JSONDecoder = {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
return decoder
}()
}
14 changes: 14 additions & 0 deletions Sources/FigmaAPI/Endpoint/ComponentsEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public struct Component: Codable, Sendable {
public let name: String
public let description: String?
public let containingFrame: ContainingFrame

enum CodingKeys: String, CodingKey {
case key
case nodeId = "node_id"
case name
case description
case containingFrame = "containing_frame"
}
}

// MARK: - ContainingFrame
Expand All @@ -49,4 +57,10 @@ public struct ContainingFrame: Codable, Sendable {
public let nodeID: String?
public let name: String?
public let pageName: String

enum CodingKeys: String, CodingKey {
case nodeID = "node_id"
case name
case pageName = "page_name"
}
}
48 changes: 48 additions & 0 deletions Sources/FigmaAPI/Model/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public struct TypeStyle: Decodable, Sendable {
public var letterSpacing: Double
public var lineHeightUnit: LineHeightUnit
public var textCase: TextCase?

enum CodingKeys: String, CodingKey {
case fontFamily = "font_family"
case fontPostScriptName = "font_post_script_name"
case fontWeight = "font_weight"
case fontSize = "font_size"
case lineHeightPx = "line_height_px"
case letterSpacing = "letter_spacing"
case lineHeightUnit = "line_height_unit"
case textCase = "text_case"
}
}

public enum TextCase: String, Decodable, Sendable {
Expand Down Expand Up @@ -59,6 +70,25 @@ public struct Document: Decodable, Sendable {
public let rotation: Double?
public let children: [Document]?
public let style: TypeStyle?

enum CodingKeys: String, CodingKey {
case id
case name
case type
case fills
case strokes
case strokeWeight = "stroke_weight"
case strokeAlign = "stroke_align"
case strokeJoin = "stroke_join"
case strokeCap = "stroke_cap"
case effects
case opacity
case blendMode = "blend_mode"
case clipsContent = "clips_content"
case rotation
case children
case style
}
}

// MARK: - Stroke Enums
Expand Down Expand Up @@ -93,6 +123,16 @@ public struct Effect: Decodable, Sendable {
public let offset: Vector?
public let spread: Double?
public let blendMode: BlendMode?

enum CodingKeys: String, CodingKey {
case type
case visible
case radius
case color
case offset
case spread
case blendMode = "blend_mode"
}
}

public enum EffectType: String, Decodable, Sendable {
Expand Down Expand Up @@ -141,6 +181,14 @@ public struct Paint: Decodable, Sendable {
public let color: PaintColor?
public let gradientStops: [GradientStop]?

enum CodingKeys: String, CodingKey {
case type
case blendMode = "blend_mode"
case opacity
case color
case gradientStops = "gradient_stops"
}

public var asSolid: SolidPaint? {
SolidPaint(self)
}
Expand Down
7 changes: 7 additions & 0 deletions Sources/FigmaAPI/Model/Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ public struct Style: Decodable, Sendable {
public let name: String
public let description: String

enum CodingKeys: String, CodingKey {
case styleType = "style_type"
case nodeId = "node_id"
case name
case description
}

public init(styleType: StyleType, nodeId: String, name: String, description: String) {
self.styleType = styleType
self.nodeId = nodeId
Expand Down
26 changes: 26 additions & 0 deletions Sources/FigmaAPI/Model/Variables.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
public struct Mode: Codable, Sendable {
public var modeId: String
public var name: String

enum CodingKeys: String, CodingKey {
case modeId = "mode_id"
case name
}
}

public struct VariableCollectionValue: Codable, Sendable {
Expand All @@ -9,6 +14,14 @@ public struct VariableCollectionValue: Codable, Sendable {
public var name: String
public var modes: [Mode]
public var variableIds: [String]

enum CodingKeys: String, CodingKey {
case defaultModeId = "default_mode_id"
case id
case name
case modes
case variableIds = "variable_ids"
}
}

public struct VariableAlias: Codable, Sendable {
Expand Down Expand Up @@ -65,6 +78,14 @@ public struct VariableValue: Codable, Sendable {
public var variableCollectionId: String
public var valuesByMode: [String: ValuesByMode]
public var description: String

enum CodingKeys: String, CodingKey {
case id
case name
case variableCollectionId = "variable_collection_id"
case valuesByMode = "values_by_mode"
case description
}
}

public typealias VariableId = String
Expand All @@ -73,6 +94,11 @@ public typealias VariableCollectionId = String
public struct VariablesMeta: Codable, Sendable {
public var variableCollections: [VariableCollectionId: VariableCollectionValue]
public var variables: [VariableId: VariableValue]

enum CodingKeys: String, CodingKey {
case variableCollections = "variable_collections"
case variables
}
}

public struct VariablesResponse: Codable, Sendable {
Expand Down
2 changes: 0 additions & 2 deletions Tests/ExFigTests/Helpers/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ extension Component {
json += "}"

let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
// swiftlint:disable:next force_try
return try! decoder.decode(Component.self, from: Data(json.utf8))
}
Expand Down Expand Up @@ -350,7 +349,6 @@ extension VariablesMeta {
"""

let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
// swiftlint:disable:next force_try
return try! decoder.decode(VariablesMeta.self, from: Data(json.utf8))
}
Expand Down
22 changes: 11 additions & 11 deletions Tests/FigmaAPITests/DocumentHashConversionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ final class DocumentHashConversionTests: XCTestCase {
"type": "COMPONENT",
"fills": [{"type": "SOLID", "color": {"r": 1.0, "g": 0.5, "b": 0.0, "a": 1.0}}],
"strokes": [{"type": "SOLID", "color": {"r": 0.0, "g": 0.0, "b": 0.0, "a": 1.0}}],
"strokeWeight": 2.0,
"strokeAlign": "CENTER",
"strokeJoin": "ROUND",
"strokeCap": "ROUND",
"stroke_weight": 2.0,
"stroke_align": "CENTER",
"stroke_join": "ROUND",
"stroke_cap": "ROUND",
"effects": [{"type": "DROP_SHADOW", "radius": 4.0, "visible": true}],
"opacity": 0.9,
"blendMode": "NORMAL",
"clipsContent": true
"blend_mode": "NORMAL",
"clips_content": true
}
"""

Expand Down Expand Up @@ -52,7 +52,7 @@ final class DocumentHashConversionTests: XCTestCase {
"name": "icon",
"type": "VECTOR",
"fills": [{"type": "SOLID", "color": {"r": 0.33333334, "g": 0.66666667, "b": 0.5, "a": 1.0}}],
"strokeWeight": 1.0000001,
"stroke_weight": 1.0000001,
"opacity": 0.9999999
}
"""
Expand Down Expand Up @@ -106,7 +106,7 @@ final class DocumentHashConversionTests: XCTestCase {
"type": "VECTOR",
"fills": [{
"type": "GRADIENT_LINEAR",
"gradientStops": [
"gradient_stops": [
{"position": 0.0, "color": {"r": 1.0, "g": 0.0, "b": 0.0, "a": 1.0}},
{"position": 1.0, "color": {"r": 0.0, "g": 0.0, "b": 1.0, "a": 1.0}}
]
Expand Down Expand Up @@ -299,7 +299,7 @@ final class DocumentHashConversionTests: XCTestCase {
"type": "VECTOR",
"fills": [{
"type": "SOLID",
"blendMode": "MULTIPLY",
"blend_mode": "MULTIPLY",
"color": {"r": 1.0, "g": 0.0, "b": 0.0, "a": 1.0}
}]
}
Expand All @@ -317,7 +317,7 @@ final class DocumentHashConversionTests: XCTestCase {
"id": "1:2",
"name": "icon",
"type": "VECTOR",
"fills": [{"type": "SOLID", "blendMode": "NORMAL", "color": {"r": 1.0, "g": 0.0, "b": 0.0, "a": 1.0}}]
"fills": [{"type": "SOLID", "blend_mode": "NORMAL", "color": {"r": 1.0, "g": 0.0, "b": 0.0, "a": 1.0}}]
}
"""

Expand All @@ -326,7 +326,7 @@ final class DocumentHashConversionTests: XCTestCase {
"id": "1:2",
"name": "icon",
"type": "VECTOR",
"fills": [{"type": "SOLID", "blendMode": "MULTIPLY", "color": {"r": 1.0, "g": 0.0, "b": 0.0, "a": 1.0}}]
"fills": [{"type": "SOLID", "blend_mode": "MULTIPLY", "color": {"r": 1.0, "g": 0.0, "b": 0.0, "a": 1.0}}]
}
"""

Expand Down
1 change: 0 additions & 1 deletion Tests/FigmaAPITests/Helpers/FixtureLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ enum FixtureLoader {
static func load<T: Decodable>(_ name: String) throws -> T {
let data = try loadData(name)
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
return try decoder.decode(T.self, from: data)
}
}
Expand Down
Loading