Skip to content

Commit fd52f34

Browse files
author
Reuven Harrison
authored
fix crash on load (#795)
1 parent b8c06e7 commit fd52f34

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

openapi3/issue794_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package openapi3
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestCrashOnLoad(t *testing.T) {
10+
loader := NewLoader()
11+
doc, err := loader.LoadFromFile("testdata/issue794.yml")
12+
require.NoError(t, err)
13+
err = doc.Validate(loader.Context)
14+
require.NoError(t, err)
15+
}

openapi3/loader.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ func (loader *Loader) resolveRequestBodyRef(doc *T, component *RequestBodyRef, d
615615
}
616616

617617
for _, contentType := range value.Content {
618+
if contentType == nil {
619+
continue
620+
}
618621
examples := make([]string, 0, len(contentType.Examples))
619622
for name := range contentType.Examples {
620623
examples = append(examples, name)

openapi3/testdata/issue794.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Swagger API
4+
version: v1
5+
paths:
6+
/test:
7+
post:
8+
requestBody:
9+
content:
10+
application/json:
11+
responses:
12+
"200":
13+
description: description

0 commit comments

Comments
 (0)