Skip to content

Commit

Permalink
Add KubernetesAPIResource protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab committed Oct 4, 2020
1 parent c44b04a commit 176e954
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/SwiftkubeModelGen/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ struct Resource: Decodable {
var requiresCodableExtension: Bool
var hasMetadata: Bool
var listResource: Bool
var isAPIResource: Bool

enum CodingKeys: String, CodingKey {
case type
Expand All @@ -396,6 +397,7 @@ struct Resource: Decodable {
self.requiresCodableExtension = false
self.hasMetadata = false
self.listResource = false
self.isAPIResource = false
return
}

Expand All @@ -410,6 +412,7 @@ struct Resource: Decodable {
self.requiresCodableExtension = false
self.hasMetadata = false
self.listResource = false
self.isAPIResource = false

guard container.allKeys.contains(.properties) else {
return
Expand Down Expand Up @@ -440,6 +443,10 @@ struct Resource: Decodable {
self.requiresCodableExtension = properties.contains { $0.type.requiresCodableExtension }
self.hasMetadata = properties.contains { $0.type.isMetadata && $0.isOptional }
self.listResource = properties.contains(where: { $0.name == "items" }) && gvk?.kind.hasSuffix("List") ?? false
self.isAPIResource =
!self.listResource &&
properties.contains(where: { $0.name == "apiVersion" && $0.isContant }) &&
properties.contains(where: { $0.name == "kind" && $0.isContant })
}
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftkubeModelGen/Stencil+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ extension Extension {
if schema.hasMetadata {
protocols.append("ResourceWithMetadata")
}
if schema.isAPIResource {
protocols.append("KubernetesAPIResource")
}

return protocols.joined(separator: ", ")
}
Expand Down

0 comments on commit 176e954

Please sign in to comment.