MCPcopy Create free account
hub / github.com/compozy/agh / validateSchemaObjectNode

Function validateSchemaObjectNode

internal/tools/schema.go:157–194  ·  view source on GitHub ↗
(path string, schema map[string]json.RawMessage, value any)

Source from the content-addressed store, hash-verified

155}
156
157func validateSchemaObjectNode(path string, schema map[string]json.RawMessage, value any) error {
158 objectValue, ok := value.(map[string]any)
159 if !ok {
160 return nil
161 }
162 required, err := schemaStringArray(schema["required"])
163 if err != nil {
164 return fmt.Errorf("%s.required: %w", path, err)
165 }
166 for _, field := range required {
167 if _, ok := objectValue[field]; !ok {
168 return fmt.Errorf("%s.%s: required field missing", path, field)
169 }
170 }
171 properties, err := schemaProperties(schema["properties"])
172 if err != nil {
173 return fmt.Errorf("%s.properties: %w", path, err)
174 }
175 if len(properties) > 0 {
176 for key, childSchema := range properties {
177 childValue, ok := objectValue[key]
178 if !ok {
179 continue
180 }
181 if err := validateSchemaNode(path+"."+key, childSchema, childValue); err != nil {
182 return err
183 }
184 }
185 }
186 if additionalPropertiesFalse(schema["additionalProperties"]) {
187 for key := range objectValue {
188 if _, ok := properties[key]; !ok {
189 return fmt.Errorf("%s.%s: additional property is not allowed", path, key)
190 }
191 }
192 }
193 return nil
194}
195
196func validateSchemaEnum(path string, raw json.RawMessage, value any) error {
197 if len(bytes.TrimSpace(raw)) == 0 {

Callers 1

validateSchemaNodeFunction · 0.85

Calls 4

schemaStringArrayFunction · 0.85
schemaPropertiesFunction · 0.85
validateSchemaNodeFunction · 0.85

Tested by

no test coverage detected