Skip to content

Commit ac244d5

Browse files
committed
repro getkin#341
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
1 parent 13a1398 commit ac244d5

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

openapi3/issue341_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package openapi3
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestIssue341(t *testing.T) {
10+
sl := NewSwaggerLoader()
11+
sl.IsExternalRefsAllowed = true
12+
doc, err := sl.LoadSwaggerFromFile("testdata/main.yaml")
13+
require.NoError(t, err)
14+
15+
err = doc.Validate(sl.Context)
16+
require.NoError(t, err)
17+
18+
err = sl.ResolveRefsIn(doc, nil)
19+
require.NoError(t, err)
20+
21+
bs, err := doc.MarshalJSON()
22+
require.NoError(t, err)
23+
t.Logf("serialized: %s", bs)
24+
25+
require.Equal(t, "string", doc.Paths["/testpath"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type)
26+
}

openapi3/testdata/main.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
openapi: "3.0.0"
2+
info:
3+
title: "test file"
4+
version: "n/a"
5+
paths:
6+
/testpath:
7+
$ref: "testpath.yaml#/paths/~1testpath"

openapi3/testdata/testpath.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
paths:
2+
/testpath:
3+
get:
4+
responses:
5+
"200":
6+
$ref: "#/components/responses/testpath_200_response"
7+
8+
components:
9+
responses:
10+
testpath_200_response:
11+
description: a custom response
12+
content:
13+
application/json:
14+
schema:
15+
type: string

0 commit comments

Comments
 (0)