Skip to content

Commit

Permalink
reproduce issue getkin#652
Browse files Browse the repository at this point in the history
  • Loading branch information
nk2ge5k committed Nov 7, 2022
1 parent d5c7ac5 commit 2ce0b5a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
29 changes: 29 additions & 0 deletions openapi3/issue652_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package openapi3_test

import (
"testing"

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

"github.com/getkin/kin-openapi/openapi3"
)

func TestIssue652(t *testing.T) {
loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true

// Test checks that no slice bounds out of range error occurs while loading
// from file that contains reference to file in the parent directory.
require.NotPanics(t, func() {
const schemaName = "ReferenceToParentDirectory"

spec, err := loader.LoadFromFile("testdata/issue652/nested/schema.yml")
require.NoError(t, err)
require.Contains(t, spec.Components.Schemas, schemaName)

schema := spec.Components.Schemas[schemaName]
assert.Equal(t, schema.Ref, "../definitions.yml#/components/schemas/TestSchema")
assert.Equal(t, schema.Value.Type, "string")
})
}
4 changes: 4 additions & 0 deletions openapi3/testdata/issue652/definitions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
components:
schemas:
TestSchema:
type: string
4 changes: 4 additions & 0 deletions openapi3/testdata/issue652/nested/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
components:
schemas:
ReferenceToParentDirectory:
$ref: "../definitions.yml#/components/schemas/TestSchema"

0 comments on commit 2ce0b5a

Please sign in to comment.