Skip to content

Commit

Permalink
Add class static APIVersion property
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab committed Oct 5, 2020
1 parent 176e954 commit 6cac76b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Sources/SwiftkubeModelGen/Stencil+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ extension Extension {
return protocols.joined(separator: ", ")
}

registerFilter("R.staticAPIVersion") { input in
guard let schema = input as? Resource else {
throw ModelGenError.RuntimeError(message: "Input must be a definition Schema")
}

guard let gv = schema.gvk?.makeGroupVersion() else {
return ""
}

guard schema.isAPIResource else {
return ""
}

let apiVersion = gv.renderedCase
return """
///
/// APIVersion of this Kubernetes API Resource.
///
public static let apiVersion: APIVersion = .\(apiVersion)
"""
}

registerFilter("P.renderDescription") { input in
guard let property = input as? Property else {
throw ModelGenError.RuntimeError(message: "Input must be a Property: \(String(describing: input))")
Expand Down
2 changes: 2 additions & 0 deletions templates/model/Resource.swift.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public extension {{ type.group }}.{{ type.version }} {
public typealias Resource = {{ type.group }}.{{ type.version }}.{{ type.listItemKind }}
{% endif %}

{{ resource|R.staticAPIVersion }}

{% for property in resource.properties %}
{{ property|P.renderDescription }}
{{ property|P.render}}{% endfor %}
Expand Down

0 comments on commit 6cac76b

Please sign in to comment.