MCPcopy Create free account
hub / github.com/docker/cli / Validate

Function Validate

cli/compose/schema/schema.go:78–98  ·  view source on GitHub ↗

Validate uses the jsonschema to validate the configuration

(config map[string]any, version string)

Source from the content-addressed store, hash-verified

76
77// Validate uses the jsonschema to validate the configuration
78func Validate(config map[string]any, version string) error {
79 version = normalizeVersion(version)
80 schemaData, err := schemas.ReadFile("data/config_schema_v" + version + ".json")
81 if err != nil {
82 return fmt.Errorf("unsupported Compose file version: %s", version)
83 }
84
85 schemaLoader := gojsonschema.NewStringLoader(string(schemaData))
86 dataLoader := gojsonschema.NewGoLoader(config)
87
88 result, err := gojsonschema.Validate(schemaLoader, dataLoader)
89 if err != nil {
90 return err
91 }
92
93 if !result.Valid() {
94 return toError(result)
95 }
96
97 return nil
98}
99
100func toError(result *gojsonschema.Result) error {
101 err := getMostSpecificError(result.Errors())

Calls 2

normalizeVersionFunction · 0.85
toErrorFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…