Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1503,3 +1503,21 @@ func TestDocument_Issue418_NoFile(t *testing.T) {
assert.Len(t, errs, 0)
assert.Len(t, m.Model.Index.GetResolver().GetResolvingErrors(), 0)
}

func TestDocument_RecursiveSchemaHash(t *testing.T) {
data, err := os.ReadFile("test_specs/recursive-expression-test.yaml")
assert.NoError(t, err)

document, err := NewDocument(data)
assert.NoError(t, err)

model, errs := document.BuildV3Model()
assert.Empty(t, errs)

schema, found := model.Model.Components.Schemas.Get("RecursiveExpression")
assert.True(t, found)
assert.NotNil(t, schema)

hash := schema.Schema().GoLow().Hash()
assert.NotEmpty(t, hash)
}
16 changes: 14 additions & 2 deletions index/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,21 @@ func (resolver *Resolver) extractRelatives(ref *Reference, node, parent *yaml.No
}

if i%2 == 0 && n.Value != "$ref" && n.Value != "" {
if n.Value == "allOf" ||
// Check if we're inside a properties object
isInsideProperties := false
if parent != nil {
for j := 0; j < len(parent.Content); j += 2 {
if j < len(parent.Content) && parent.Content[j].Value == "properties" {
isInsideProperties = true
break
}
}
}

// Only treat as polymorphic keywords if not inside properties
if !isInsideProperties && (n.Value == "allOf" ||
n.Value == "oneOf" ||
n.Value == "anyOf" {
n.Value == "anyOf") {

// if this is a polymorphic link, we want to follow it and see if it becomes circular
if i+1 < len(node.Content) && utils.IsNodeMap(node.Content[i+1]) { // check for nested items
Expand Down
23 changes: 23 additions & 0 deletions test_specs/recursive-expression-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
openapi: 3.0.1
info:
title: Recursive Expression Test
version: 1
servers:
- url: https://dev.url
variables:
basePath:
default: ""
paths: {}
components:
schemas:
RecursiveExpression:
description: RecursiveExpression
title: RecursiveExpression
properties:
allOf:
type: array
items:
anyOf:
- $ref: "#/components/schemas/RecursiveExpression"
- type: string