File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -264,6 +264,25 @@ func TestValidateDocument_SpecJSONBytesPath(t *testing.T) {
264264 assert .Len (t , errs , 0 )
265265}
266266
267+ func TestValidateDocument_SpecJSONBytesCorrupt_NilSpecJSON (t * testing.T ) {
268+ petstore , _ := os .ReadFile ("../test_specs/petstorev3.json" )
269+ doc , _ := libopenapi .NewDocument (petstore )
270+
271+ info := doc .GetSpecInfo ()
272+
273+ // Put corrupt bytes in SpecJSONBytes so UnmarshalJSON fails,
274+ // and nil out SpecJSON so the fallback normalizeJSON path is skipped.
275+ // This exercises the nil guard on SpecJSON inside the error branch.
276+ corrupt := []byte (`{not valid json!!!}` )
277+ info .SpecJSONBytes = & corrupt
278+ info .SpecJSON = nil
279+
280+ // Validation should still run (against nil normalized value) and report errors
281+ valid , errs := ValidateOpenAPIDocument (doc )
282+ assert .False (t , valid )
283+ assert .NotEmpty (t , errs )
284+ }
285+
267286func TestValidateDocument_SpecJSONBytesPath_Invalid (t * testing.T ) {
268287 petstore , _ := os .ReadFile ("../test_specs/invalid_31.yaml" )
269288 doc , _ := libopenapi .NewDocument (petstore )
You can’t perform that action at this time.
0 commit comments