diff --git a/cli/compose/schema/schema.go b/cli/compose/schema/schema.go index 3d26d1fbc..f8a1abaf6 100644 --- a/cli/compose/schema/schema.go +++ b/cli/compose/schema/schema.go @@ -50,6 +50,8 @@ func Version(config map[string]interface{}) string { func normalizeVersion(version string) string { switch version { + case "": + return defaultVersion case "3": return "3.0" default: @@ -62,6 +64,7 @@ var schemas embed.FS // Validate uses the jsonschema to validate the configuration func Validate(config map[string]interface{}, version string) error { + version = normalizeVersion(version) schemaData, err := schemas.ReadFile("data/config_schema_v" + version + ".json") if err != nil { return errors.Errorf("unsupported Compose file version: %s", version) diff --git a/cli/compose/schema/schema_test.go b/cli/compose/schema/schema_test.go index 1c36294c0..d90e45f95 100644 --- a/cli/compose/schema/schema_test.go +++ b/cli/compose/schema/schema_test.go @@ -20,6 +20,9 @@ func TestValidate(t *testing.T) { } assert.NilError(t, Validate(config, "3.0")) + assert.NilError(t, Validate(config, "3")) + assert.ErrorContains(t, Validate(config, ""), "unsupported Compose file version: 1.0") + assert.ErrorContains(t, Validate(config, "12345"), "unsupported Compose file version: 12345") } func TestValidateUndefinedTopLevelOption(t *testing.T) { @@ -84,6 +87,7 @@ func TestValidateCredentialSpecs(t *testing.T) { version string expectedErr string }{ + {version: "3", expectedErr: "credential_spec"}, {version: "3.0", expectedErr: "credential_spec"}, {version: "3.1", expectedErr: "credential_spec"}, {version: "3.2", expectedErr: "credential_spec"},