@@ -6135,3 +6135,51 @@ components:
61356135 assert .True (t , result .Valid )
61366136 assert .Empty (t , result .UndeclaredValues )
61376137}
6138+
6139+ func TestStrictValidator_ValidateVariantWithParent_VariantNilGoLow (t * testing.T ) {
6140+ // Covers polymorphic.go:233-234 - fallback to parent when variant.GoLow() is nil
6141+ // This tests the defensive code path for programmatically created schemas
6142+
6143+ // Build a real parent schema from YAML (has GoLow())
6144+ yml := `openapi: "3.1.0"
6145+ info:
6146+ title: Test
6147+ version: "1.0"
6148+ paths: {}
6149+ components:
6150+ schemas:
6151+ ParentSchema:
6152+ type: object
6153+ properties:
6154+ parentProp:
6155+ type: string
6156+ `
6157+ model := buildSchemaFromYAML (t , yml )
6158+ parent := getSchema (t , model , "ParentSchema" )
6159+ require .NotNil (t , parent .GoLow ())
6160+
6161+ // Create a variant schema programmatically (no GoLow())
6162+ variant := & base.Schema {
6163+ Type : []string {"object" },
6164+ }
6165+ require .Nil (t , variant .GoLow ())
6166+
6167+ opts := config .NewValidationOptions (config .WithStrictMode ())
6168+ v := NewValidator (opts , 3.1 )
6169+
6170+ ctx := newTraversalContext (DirectionRequest , nil , "$.body" )
6171+
6172+ // Data with undeclared property - triggers line 230-237
6173+ data := map [string ]any {
6174+ "parentProp" : "value" ,
6175+ "undeclared" : "triggers undeclared path" ,
6176+ }
6177+
6178+ result := v .validateVariantWithParent (ctx , parent , variant , data )
6179+
6180+ // Should detect undeclared property and use parent's location (since variant has no GoLow)
6181+ assert .Len (t , result , 1 )
6182+ assert .Equal (t , "undeclared" , result [0 ].Name )
6183+ // Location should come from parent (not crash due to nil variant.GoLow())
6184+ assert .Greater (t , result [0 ].SpecLine , 0 )
6185+ }
0 commit comments