-
-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent infinite loop while loading openapi spec with recursive refer…
…ences (#310)
- Loading branch information
1 parent
bdba5d1
commit 89012b7
Showing
6 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package openapi3 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLoaderSupportsRecursiveReference(t *testing.T) { | ||
loader := NewSwaggerLoader() | ||
loader.IsExternalRefsAllowed = true | ||
doc, err := loader.LoadSwaggerFromFile("testdata/recursiveRef/openapi.yml") | ||
require.NoError(t, err) | ||
require.NotNil(t, doc) | ||
require.NoError(t, doc.Validate(loader.Context)) | ||
require.Equal(t, "bar", doc.Paths["/foo"].Get.Responses.Get(200).Value.Content.Get("application/json").Schema.Value.Properties["foo"].Value.Properties["bar"].Value.Items.Value.Example) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
type: string | ||
example: bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type: object | ||
properties: | ||
bar: | ||
type: array | ||
items: | ||
$ref: ../openapi.yml#/components/schemas/Bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
openapi: "3.0.3" | ||
info: | ||
title: Recursive refs example | ||
version: "1.0" | ||
paths: | ||
/foo: | ||
$ref: ./paths/foo.yml | ||
components: | ||
schemas: | ||
Foo: | ||
$ref: ./components/Foo.yml | ||
Bar: | ||
$ref: ./components/Bar.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
get: | ||
responses: | ||
"200": | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
foo: | ||
$ref: ../openapi.yml#/components/schemas/Foo |