diff --git a/Sources/Container-Compose/Codable Structs/Service.swift b/Sources/Container-Compose/Codable Structs/Service.swift index 82bfa36..d2327e0 100644 --- a/Sources/Container-Compose/Codable Structs/Service.swift +++ b/Sources/Container-Compose/Codable Structs/Service.swift @@ -192,8 +192,14 @@ public struct Service: Codable, Hashable { if let dependsOnString = try? container.decodeIfPresent(String.self, forKey: .depends_on) { depends_on = [dependsOnString] + } else if let dependsOnArray = try? container.decodeIfPresent([String].self, forKey: .depends_on) { + depends_on = dependsOnArray + } else if let dependsOnMap = try? container.decodeIfPresent([String: [String: String]].self, forKey: .depends_on) { + // Map form: depends_on: { db: { condition: service_healthy } } + // Preserve dependency order; conditions are not applicable to Apple Container. + depends_on = dependsOnMap.keys.sorted() } else { - depends_on = try container.decodeIfPresent([String].self, forKey: .depends_on) + depends_on = nil } user = try container.decodeIfPresent(String.self, forKey: .user) diff --git a/Tests/Container-Compose-StaticTests/DockerComposeParsingTests.swift b/Tests/Container-Compose-StaticTests/DockerComposeParsingTests.swift index 2749fe7..1418a21 100644 --- a/Tests/Container-Compose-StaticTests/DockerComposeParsingTests.swift +++ b/Tests/Container-Compose-StaticTests/DockerComposeParsingTests.swift @@ -180,6 +180,32 @@ struct DockerComposeParsingTests { #expect(compose.services["web"]??.depends_on?.contains("db") == true) } + @Test("Parse compose with depends_on map form (condition syntax)") + func parseComposeWithDependenciesMapForm() throws { + let yaml = """ + version: '3.8' + services: + web: + image: nginx:latest + depends_on: + db: + condition: service_healthy + cache: + condition: service_started + db: + image: postgres:14 + cache: + image: redis:7 + """ + + let decoder = YAMLDecoder() + let compose = try decoder.decode(DockerCompose.self, from: yaml) + + #expect(compose.services["web"]??.depends_on?.contains("db") == true) + #expect(compose.services["web"]??.depends_on?.contains("cache") == true) + #expect(compose.services["web"]??.depends_on?.count == 2) + } + @Test("Parse compose with build context") func parseComposeWithBuild() throws { let yaml = """