File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -283,6 +283,23 @@ func TestValidateDocument_SpecJSONBytesCorrupt_NilSpecJSON(t *testing.T) {
283283 assert .NotEmpty (t , errs )
284284}
285285
286+ func TestValidateDocument_SpecJSONBytesCorrupt_FallbackToSpecJSON (t * testing.T ) {
287+ petstore , _ := os .ReadFile ("../test_specs/petstorev3.json" )
288+ doc , _ := libopenapi .NewDocument (petstore )
289+
290+ info := doc .GetSpecInfo ()
291+
292+ // Put corrupt bytes in SpecJSONBytes so UnmarshalJSON fails,
293+ // but leave SpecJSON intact so the fallback to normalizeJSON executes.
294+ corrupt := []byte (`{not valid json!!!}` )
295+ info .SpecJSONBytes = & corrupt
296+
297+ // Should still validate successfully via the SpecJSON fallback
298+ valid , errs := ValidateOpenAPIDocument (doc )
299+ assert .True (t , valid )
300+ assert .Len (t , errs , 0 )
301+ }
302+
286303func TestValidateDocument_SpecJSONBytesPath_Invalid (t * testing.T ) {
287304 petstore , _ := os .ReadFile ("../test_specs/invalid_31.yaml" )
288305 doc , _ := libopenapi .NewDocument (petstore )
You can’t perform that action at this time.
0 commit comments