Merge pull request #646 from beckn/fix/context-type-check

fix(schemav2validator): conditionally strip @context/@type based on s…
This commit is contained in:
Mayuresh A Nirhali
2026-04-07 14:10:24 +05:30
committed by GitHub

View File

@@ -383,12 +383,22 @@ func (c *schemaCache) validateReferencedObject(
return fmt.Errorf("at %s: %w", obj.Path, err)
}
// Strip JSON-LD metadata before validation
domainData := make(map[string]interface{}, len(obj.Data)-2)
// Strip @context and @type only if the schema does not declare them as properties.
// Some schemas explicitly require these fields; stripping them in that case
// would cause a "missing required field" validation error.
schemaProps := schema.Value.Properties
_, contextInSchema := schemaProps["@context"]
_, typeInSchema := schemaProps["@type"]
domainData := make(map[string]interface{}, len(obj.Data))
for k, v := range obj.Data {
if k != "@context" && k != "@type" {
domainData[k] = v
if k == "@context" && !contextInSchema {
continue
}
if k == "@type" && !typeInSchema {
continue
}
domainData[k] = v
}
// Validate domain-specific data against schema