quobix
2024-02-06 13:58:55 -05:00
parent e3659a4bbe
commit 103f2dfb0b
2 changed files with 44 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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)
}