File: issue652_test.go

package info (click to toggle)
golang-github-getkin-kin-openapi 0.124.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,288 kB
  • sloc: sh: 344; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 862 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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, &openapi3.Types{"string"})
	})
}