diff --git a/index/extract_refs.go b/index/extract_refs.go index ec1ab19..e5f6bf7 100644 --- a/index/extract_refs.go +++ b/index/extract_refs.go @@ -23,7 +23,6 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string, if len(node.Content) > 0 { var prev, polyName string for i, n := range node.Content { - if utils.IsNodeMap(n) || utils.IsNodeArray(n) { level++ // check if we're using polymorphic values. These tend to create rabbit warrens of circular @@ -332,9 +331,12 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string, if len(seenPath) > 0 { lastItem := seenPath[len(seenPath)-1] if lastItem == "properties" { + seenPath = append(seenPath, n.Value) + prev = n.Value continue } } + // all enums need to have a type, extract the type from the node where the enum was found. _, enumKeyValueNode := utils.FindKeyNodeTop("type", node.Content) diff --git a/index/extract_refs_test.go b/index/extract_refs_test.go index 41b9ce0..672a7ea 100644 --- a/index/extract_refs_test.go +++ b/index/extract_refs_test.go @@ -114,7 +114,6 @@ components: // https://github.com/pb33f/libopenapi/issues/112 func TestSpecIndex_ExtractRefs_CheckReferencesWithBracketsInName(t *testing.T) { - yml := `openapi: 3.0.0 components: schemas: @@ -137,7 +136,6 @@ components: // https://github.com/daveshanley/vacuum/issues/339 func TestSpecIndex_ExtractRefs_CheckEnumNotPropertyCalledEnum(t *testing.T) { - yml := `openapi: 3.0.0 components: schemas: @@ -164,11 +162,22 @@ components: example: - yo - hello + Schema2: + type: object + properties: + enumRef: + $ref: '#/components/schemas/enum' + enum: + type: string + enum: [big, small] + nullable: true + enum: + type: [string, null] + enum: [big, small] ` var rootNode yaml.Node _ = yaml.Unmarshal([]byte(yml), &rootNode) c := CreateOpenAPIIndexConfig() idx := NewSpecIndexWithConfig(&rootNode, c) - assert.Len(t, idx.allEnums, 1) - + assert.Len(t, idx.allEnums, 3) }