diff --git a/loader/loader.go b/loader/loader.go index 25d2d0c6..db415a3d 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -675,6 +675,7 @@ func NormalizeProjectName(s string) string { var userDefinedKeys = []tree.Path{ "services", + "services.*.depends_on", "volumes", "networks", "secrets", @@ -687,7 +688,7 @@ func processExtensions(dict map[string]any, p tree.Path, extensions map[string]a for key, value := range dict { skip := false for _, uk := range userDefinedKeys { - if uk.Matches(p) { + if p.Matches(uk) { skip = true break } @@ -770,14 +771,14 @@ func secretConfigDecoderHook(from, to reflect.Type, data interface{}) (interface // Check if the input is a map and we're decoding into a SecretConfig if from.Kind() == reflect.Map && to == reflect.TypeOf(types.SecretConfig{}) { if v, ok := data.(map[string]interface{}); ok { - if ext, ok := v["#extensions"].(map[string]interface{}); ok { + if ext, ok := v[consts.Extensions].(map[string]interface{}); ok { if val, ok := ext[types.SecretConfigXValue].(string); ok { // Return a map with the Content field populated v["Content"] = val delete(ext, types.SecretConfigXValue) if len(ext) == 0 { - delete(v, "#extensions") + delete(v, consts.Extensions) } } } diff --git a/loader/loader_test.go b/loader/loader_test.go index cba477f6..7b9e1677 100644 --- a/loader/loader_test.go +++ b/loader/loader_test.go @@ -3409,3 +3409,24 @@ services: "myhost": []string{"0.0.0.1", "0.0.0.2"}, }) } + +func TestLoadDependsOnX(t *testing.T) { + p, err := loadYAML(` +name: load-depends-on-x +services: + test: + image: test + depends_on: + - x-foo + x-foo: + image: foo +`) + assert.NilError(t, err) + test := p.Services["test"] + assert.DeepEqual(t, test.DependsOn, types.DependsOnConfig{ + "x-foo": types.ServiceDependency{ + Condition: types.ServiceConditionStarted, + Required: true, + }, + }) +} diff --git a/schema/schema_test.go b/schema/schema_test.go index 902805b9..766f4dd1 100644 --- a/schema/schema_test.go +++ b/schema/schema_test.go @@ -66,6 +66,13 @@ func TestValidateAllowsXFields(t *testing.T) { "bar": dict{ "x-extra-stuff": dict{}, }, + "foo": dict{ + "depends_on": dict{ + "x-dependency": dict{ + "condition": "service_started", + }, + }, + }, }, "volumes": dict{ "bar": dict{