Skip to content

Commit 4e2dfcf

Browse files
committed
bump coverage
1 parent bec5cfe commit 4e2dfcf

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

schema_validation/validate_document_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
267286
func TestValidateDocument_SpecJSONBytesPath_Invalid(t *testing.T) {
268287
petstore, _ := os.ReadFile("../test_specs/invalid_31.yaml")
269288
doc, _ := libopenapi.NewDocument(petstore)

0 commit comments

Comments
 (0)