Skip to content

Commit

Permalink
Merge pull request alexsteinerde#1 from mbarnach/Codable
Browse files Browse the repository at this point in the history
Extend types with Codable support.
  • Loading branch information
alexsteinerde authored May 7, 2021
2 parents 7c187a3 + 74b104d commit 8bbca2d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Sources/DockerClientSwift/Models/Container.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ public struct Container {
public var state: String
public var command: String
}

extension Container: Codable {}
2 changes: 2 additions & 0 deletions Sources/DockerClientSwift/Models/DockerVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ public struct DockerVersion {
public let minAPIVersion: String
public let os: String
}

extension DockerVersion: Codable {}
4 changes: 3 additions & 1 deletion Sources/DockerClientSwift/Models/Identifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ public struct Identifier<T> {
public init(_ value: String) {
self.value = value
}

public typealias StringLiteralType = String

public var value: String
Expand All @@ -15,3 +15,5 @@ extension Identifier: ExpressibleByStringLiteral {
}

extension Identifier: Equatable { }

extension Identifier: Codable {}
19 changes: 11 additions & 8 deletions Sources/DockerClientSwift/Models/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ public struct Image {

/// Local ID of the image. This can vary from instant to instant.
public var id: Identifier<Image>

/// The unique hash of the image layer that is exposed. Format: {hash algorithm}:{hash value}.
public var digest: Digest?

/// Names and tags of the image that it has in the repository.
public var repositoryTags: [RepositoryTag]

/// Date when the image was created.
public var createdAt: Date?

public struct RepositoryTag {
public var repository: String
public var tag: String?
}

internal init(id: Identifier<Image>, digest: Digest? = nil, repoTags: [String]?=nil, createdAt: Date?=nil) {
let repositoryTags = repoTags.map({ repoTags in
repoTags.compactMap { repoTag in
return RepositoryTag(repoTag)
}
}) ?? []

self.init(id: id, digest: digest, repositoryTags: repositoryTags, createdAt: createdAt)
}

internal init(id: Identifier<Image>, digest: Digest? = nil, repositoryTags: [RepositoryTag]?=nil, createdAt: Date?=nil) {
self.id = id
self.digest = digest
self.createdAt = createdAt
self.repositoryTags = repositoryTags ?? []
}

internal init(id: Identifier<Image>) {
self.id = id
self.repositoryTags = []
Expand All @@ -58,3 +58,6 @@ extension Image.RepositoryTag {
}
}
}

extension Image: Codable {}
extension Image.RepositoryTag: Codable {}
2 changes: 2 additions & 0 deletions Sources/DockerClientSwift/Models/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ public struct Service {
public var version: Int
public var image: Image
}

extension Service: Codable {}
4 changes: 3 additions & 1 deletion Sources/DockerClientSwift/Models/Utilitities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public struct MessageResponse: Codable {
/// Representation of an image digest.
public struct Digest {
public var rawValue: String

init(_ rawValue: String) {
self.rawValue = rawValue
}
Expand All @@ -23,6 +23,8 @@ extension Digest: ExpressibleByStringLiteral {
}
}

extension Digest: Codable {}

public enum DockerError: Error {
case message(String)
case unknownResponse(String)
Expand Down

0 comments on commit 8bbca2d

Please sign in to comment.