mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 04:20:11 +00:00
Reworked logic to check extensions were not caught either.
Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
@@ -96,6 +96,29 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
|
||||
// https://github.com/pb33f/libopenapi/issues/76
|
||||
mapOfSchemaContainingNodes := []string{"properties", "patternProperties"}
|
||||
if i%2 == 0 && slices.Contains(mapOfSchemaContainingNodes, n.Value) && !utils.IsNodeArray(node) && (i+1 < len(node.Content)) {
|
||||
|
||||
// if 'examples' or 'example' exists in the seenPath, skip this 'properties' node.
|
||||
// https://github.com/pb33f/libopenapi/issues/160
|
||||
if len(seenPath) > 0 {
|
||||
skip := false
|
||||
|
||||
// iterate through the path and look for an item named 'examples' or 'example'
|
||||
for _, p := range seenPath {
|
||||
if p == "examples" || p == "example" {
|
||||
skip = true
|
||||
break
|
||||
}
|
||||
// look for any extension in the path that begins with 'x-'
|
||||
if strings.HasPrefix(p, "x-") {
|
||||
skip = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if skip {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// for each property add it to our schema definitions
|
||||
label := ""
|
||||
for h, prop := range node.Content[i+1].Content {
|
||||
|
||||
@@ -1650,3 +1650,54 @@ components:
|
||||
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)
|
||||
}
|
||||
|
||||
func TestSpecIndex_CheckPropertiesFromExamplesIgnored(t *testing.T) {
|
||||
yml := `paths:
|
||||
/test:
|
||||
get:
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
x-properties:
|
||||
properties:
|
||||
name: not a schema
|
||||
x-example:
|
||||
properties:
|
||||
name: not a schema
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Object"
|
||||
examples:
|
||||
Example1:
|
||||
value:
|
||||
properties:
|
||||
name: not a schema
|
||||
Example2:
|
||||
value:
|
||||
properties:
|
||||
name: another one
|
||||
components:
|
||||
schemas:
|
||||
Object:
|
||||
type: object
|
||||
x-properties:
|
||||
properties:
|
||||
name: not a schema
|
||||
properties:
|
||||
properties:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
example:
|
||||
properties:
|
||||
name: not a schema`
|
||||
|
||||
var rootNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(yml), &rootNode)
|
||||
|
||||
index := NewSpecIndexWithConfig(&rootNode, CreateOpenAPIIndexConfig())
|
||||
schemas := index.GetAllSchemas()
|
||||
assert.Equal(t, 6, len(schemas))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user