From 2f1bfa23a7aecba2e7f80fbc0deabd26ff1f4362 Mon Sep 17 00:00:00 2001 From: Mayuresh Date: Tue, 7 Apr 2026 12:29:15 +0530 Subject: [PATCH] fix(schemav2validator): conditionally strip @context/@type based on schema properties Previously, @context and @type were always stripped from domain data before validation. This caused failures when a schema explicitly declares these as required properties, resulting in "missing required field" errors. The fix checks whether each field is declared in the schema's properties before deciding to strip it. --- .../schemav2validator/extended_schema.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/plugin/implementation/schemav2validator/extended_schema.go b/pkg/plugin/implementation/schemav2validator/extended_schema.go index 92c5ed0..f5f8747 100644 --- a/pkg/plugin/implementation/schemav2validator/extended_schema.go +++ b/pkg/plugin/implementation/schemav2validator/extended_schema.go @@ -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