Skip to content

Commit

Permalink
fix crash on load (getkin#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven Harrison authored and wrong-user committed Jun 9, 2023
1 parent 344be16 commit a20abe5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions openapi3/issue794_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package openapi3

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestCrashOnLoad(t *testing.T) {
loader := NewLoader()
doc, err := loader.LoadFromFile("testdata/issue794.yml")
require.NoError(t, err)
err = doc.Validate(loader.Context)
require.NoError(t, err)
}
3 changes: 3 additions & 0 deletions openapi3/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ func (loader *Loader) resolveRequestBodyRef(doc *T, component *RequestBodyRef, d
}

for _, contentType := range value.Content {
if contentType == nil {
continue
}
examples := make([]string, 0, len(contentType.Examples))
for name := range contentType.Examples {
examples = append(examples, name)
Expand Down
13 changes: 13 additions & 0 deletions openapi3/testdata/issue794.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
openapi: 3.0.1
info:
title: Swagger API
version: v1
paths:
/test:
post:
requestBody:
content:
application/json:
responses:
"200":
description: description

0 comments on commit a20abe5

Please sign in to comment.