(path string, schema map[string]json.RawMessage, value any)
| 155 | } |
| 156 | |
| 157 | func 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 | |
| 196 | func validateSchemaEnum(path string, raw json.RawMessage, value any) error { |
| 197 | if len(bytes.TrimSpace(raw)) == 0 { |
no test coverage detected