diff --git a/index/spec_index.go b/index/spec_index.go index c6f697f..24826fa 100644 --- a/index/spec_index.go +++ b/index/spec_index.go @@ -1050,6 +1050,14 @@ func (index *SpecIndex) GetOperationsParameterCount() int { pathPropertyNode = index.pathsNode.Content[x+1] } + // is the path a ref? + if isRef, _, ref := utils.IsNodeRefValue(pathPropertyNode); isRef { + pNode := seekRefEnd(index, ref) + if pNode != nil { + pathPropertyNode = pNode.Node + } + } + // extract methods for later use. for y, prop := range pathPropertyNode.Content { if y%2 == 0 { diff --git a/index/spec_index_test.go b/index/spec_index_test.go index 1764fc7..2ceae38 100644 --- a/index/spec_index_test.go +++ b/index/spec_index_test.go @@ -1614,3 +1614,39 @@ paths: assert.Equal(t, "$.paths['/test'].get.parameters.schema.properties.message", schemas[2].Path) } + +func TestSpecIndex_TestPathsAsRef(t *testing.T) { + yml := `paths: + /test: + $ref: '#/paths/~1test-2' + /test-2: + parameters: + - $ref: '#/components/parameters/test-2' + get: + parameters: + - $ref: '#/components/parameters/test-3' +components: + parameters: + test-2: + name: test-2 + in: query + description: bing bong + schema: + type: string + test-3: + name: test-3 + in: query + description: ding a ling + schema: + type: string` + + var rootNode yaml.Node + _ = yaml.Unmarshal([]byte(yml), &rootNode) + + index := NewSpecIndexWithConfig(&rootNode, CreateOpenAPIIndexConfig()) + params := index.GetOperationParameterReferences() + assert.Equal(t, "$.components.parameters.test-2", params["/test"]["top"]["#/components/parameters/test-2"][0].Path) + assert.Equal(t, "$.components.parameters.test-3", params["/test-2"]["get"]["#/components/parameters/test-3"][0].Path) + assert.Equal(t, "bing bong", params["/test"]["top"]["#/components/parameters/test-2"][0].Node.Content[5].Value) + assert.Equal(t, "ding a ling", params["/test"]["get"]["#/components/parameters/test-3"][0].Node.Content[5].Value) +}