diff --git a/Sources/ContainerizationOCI/Index.swift b/Sources/ContainerizationOCI/Index.swift index 3aee6eb4..7de9fba2 100644 --- a/Sources/ContainerizationOCI/Index.swift +++ b/Sources/ContainerizationOCI/Index.swift @@ -25,6 +25,7 @@ public struct Index: Codable, Sendable { public let schemaVersion: Int /// mediaType specifies the type of this document data structure e.g. `application/vnd.oci.image.index.v1+json` + /// This field is optional per the OCI Image Index Specification (omitempty) public let mediaType: String /// manifests references platform specific manifests. @@ -42,4 +43,12 @@ public struct Index: Codable, Sendable { self.manifests = manifests self.annotations = annotations } + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.schemaVersion = try container.decode(Int.self, forKey: .schemaVersion) + self.mediaType = try container.decodeIfPresent(String.self, forKey: .mediaType) ?? "" + self.manifests = try container.decode([Descriptor].self, forKey: .manifests) + self.annotations = try container.decodeIfPresent([String: String].self, forKey: .annotations) + } }