MCPcopy Create free account
hub / github.com/compose-spec/compose-go / Validate

Function Validate

schema/schema.go:84–109  ·  view source on GitHub ↗

Validate uses the jsonschema to validate the configuration

(config map[string]interface{})

Source from the content-addressed store, hash-verified

82
83// Validate uses the jsonschema to validate the configuration
84func Validate(config map[string]interface{}) error {
85 schema, err := compileSchema()
86 if err != nil {
87 return err
88 }
89
90 // santhosh-tekuri doesn't allow derived types
91 // see https://github.com/santhosh-tekuri/jsonschema/pull/240
92 marshaled, err := json.Marshal(config)
93 if err != nil {
94 return err
95 }
96
97 var raw map[string]interface{}
98 err = json.Unmarshal(marshaled, &raw)
99 if err != nil {
100 return err
101 }
102
103 err = schema.Validate(raw)
104 var verr *jsonschema.ValidationError
105 if ok := errors.As(err, &verr); ok {
106 return validationError{getMostSpecificError(verr)}
107 }
108 return err
109}
110
111type validationError struct {
112 err *jsonschema.ValidationError

Calls 2

compileSchemaFunction · 0.85
getMostSpecificErrorFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…