Skip to content

Commit 16cd936

Browse files
committed
bump that coverage!
1 parent 4e2dfcf commit 16cd936

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

schema_validation/validate_document_test.go

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

0 commit comments

Comments
 (0)