Skip to content
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.DS_Store
/.claude/settings.local.json
/.vscode
/.build
/Packages
/*.xcodeproj
Expand Down
51 changes: 51 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

SwiftkubeModel is a zero-dependency Swift package providing Codable, Hashable, Sendable model structs for all Kubernetes API objects. Currently tracks Kubernetes v1.33.3.

## Build & Test Commands

```bash
swift build # Build the package
swift test # Run all tests
swift test --filter SwiftkubeModelTests.GroupVersionKindTests # Run a single test class
swift format -i Sources/ Tests/ # Format code
```

## Architecture

### Code Generation

Most files under `Sources/Model/` are **generated** by an external tool called `Swiftkube:ModelGen` (not in this repo). Generated files have this header comment:
```
// Generated by Swiftkube:ModelGen
// Kubernetes v1.33.3
```
Do not manually edit generated files unless you understand they will be overwritten on the next generation run.

### Source Layout

- **`Sources/Model/<group>/<version>/`** — Generated Kubernetes API structs, one file per type. Files follow the naming convention `TypeName+group.version.swift` (e.g., `Pod+core.v1.swift`). Each API group is a Swift namespace enum (e.g., `core.v1`, `apps.v1`, `networking.v1beta1`).

- **`Sources/Model/`** (top-level files) — Core infrastructure:
- `KubernetesResource.swift` — Protocol hierarchy: `KubernetesResource` → `MetadataHavingResource` → `KubernetesAPIResource`, plus capability marker protocols (`NamespacedResource`, `ClusterScopedResource`, `ReadableResource`, `ListableResource`, `CreatableResource`, `DeletableResource`, etc.)
- `GroupVersionKind.swift` / `GroupVersionResource.swift` — GVK/GVR types and their lookup tables (`+DefaultResources`, `+KubernetesAPIResource`, `+Meta`, `+ResourceName`)
- `UnstructuredResource.swift` — Type-erased resource for unknown/CRD types
- `IntOrString.swift`, `Quantity.swift`, `JSONObject.swift` — Special Kubernetes types

- **`Sources/Builders/`** — Closure-based builder functions under the `sk` namespace enum. Only covers common types (core/v1, apps/v1, meta/v1).

- **`Sources/Codable/`** — Custom encoding/decoding support (`Any+Codable.swift`, `NullWrapper.swift`).

- **`Sources/Extensions/`** — Convenience extensions on model types and `Hashes.swift` for Hashable conformance.

### Key Patterns

- All resources are `Codable`, `Hashable`, and `Sendable` structs.
- API resources use `var` properties (not `let`) for mutability.
- `apiVersion` and `kind` are `let` constants with default values on each API resource struct.
- Resources with `JSONObject` fields (dictionary-backed) store values as `Dictionary<String, any Sendable>`.
- The `sk` enum provides builder functions that use `inout` closure patterns via the internal `build(_:with:)` helper.
4 changes: 4 additions & 0 deletions Sources/Builders/Builders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// MARK: - sk

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/apps/v1/appsV1+Deployment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/core/v1/coreV1+ConfigMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/core/v1/coreV1+Container.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/core/v1/coreV1+Namespace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/core/v1/coreV1+Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/core/v1/coreV1+ObjectReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/core/v1/coreV1+Pod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/core/v1/coreV1+Secret.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/core/v1/coreV1+Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/core/v1/coreV1+ServiceAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/core/v1/coreV1+Volume.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/meta/v1/metaV1+Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/meta/v1/metaV1+Selector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Builders/meta/v1/metaV1+Status.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension sk {

Expand Down
4 changes: 4 additions & 0 deletions Sources/Codable/Any+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// MARK: - JSONCodingKeys

Expand Down
4 changes: 4 additions & 0 deletions Sources/Extensions/CronJobExtensions+batch.v1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public extension batch.v1.CronJob {
func generateJob(withName name: String = "manual") throws -> batch.v1.Job {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Extensions/Hashes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

/// GenerateRandomHash returns a three character. I
func GenerateRandomHash(length: Int) -> String {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Model/GroupVersionKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// MARK: - GroupVersionKind

Expand Down
4 changes: 4 additions & 0 deletions Sources/Model/GroupVersionResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// MARK: - GroupVersionResource

Expand Down
4 changes: 4 additions & 0 deletions Sources/Model/IntOrString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// MARK: - IntOrString

Expand Down
4 changes: 4 additions & 0 deletions Sources/Model/JSONObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// MARK: - JSONObject

Expand Down
4 changes: 4 additions & 0 deletions Sources/Model/KubernetesResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// limitations under the License.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// MARK: - KubernetesResource

Expand Down
Loading
Loading