Skip to content

Commit

Permalink
openapi3: fix an infinite loop that may have been introduced in #700 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp authored Feb 13, 2023
1 parent 28d8a4e commit 47d329d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 58 deletions.
25 changes: 24 additions & 1 deletion openapi3/issue542_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,31 @@ import (
)

func TestIssue542(t *testing.T) {
spec := []byte(`
openapi: '3.0.0'
info:
version: '1.0.0'
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths: {}
components:
schemas:
Cat:
anyOf:
- $ref: '#/components/schemas/Kitten'
- type: object
Kitten:
type: string
`[1:])

sl := NewLoader()

_, err := sl.LoadFromFile("testdata/issue542.yml")
doc, err := sl.LoadFromData(spec)
require.NoError(t, err)

doc.Validate(sl.Context)
require.NoError(t, err)
}
11 changes: 9 additions & 2 deletions openapi3/issue615_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (

func TestIssue615(t *testing.T) {
{
var old int
old, openapi3.CircularReferenceCounter = openapi3.CircularReferenceCounter, 1
defer func() { openapi3.CircularReferenceCounter = old }()

loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
_, err := loader.LoadFromFile("testdata/recursiveRef/issue615.yml")
require.NoError(t, err)
require.ErrorContains(t, err, openapi3.CircularReferenceError)
}

var old int
Expand All @@ -22,6 +26,9 @@ func TestIssue615(t *testing.T) {

loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
_, err := loader.LoadFromFile("testdata/recursiveRef/issue615.yml")
doc, err := loader.LoadFromFile("testdata/recursiveRef/issue615.yml")
require.NoError(t, err)

doc.Validate(loader.Context)
require.NoError(t, err)
}
12 changes: 0 additions & 12 deletions openapi3/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ func (loader *Loader) resolveHeaderRef(doc *T, component *HeaderRef, documentPat
return err
}
component.Value = resolved.Value
return nil
}
}
value := component.Value
Expand Down Expand Up @@ -552,7 +551,6 @@ func (loader *Loader) resolveParameterRef(doc *T, component *ParameterRef, docum
return err
}
component.Value = resolved.Value
return nil
}
}
value := component.Value
Expand Down Expand Up @@ -609,7 +607,6 @@ func (loader *Loader) resolveRequestBodyRef(doc *T, component *RequestBodyRef, d
return err
}
component.Value = resolved.Value
return nil
}
}
value := component.Value
Expand Down Expand Up @@ -671,7 +668,6 @@ func (loader *Loader) resolveResponseRef(doc *T, component *ResponseRef, documen
return err
}
component.Value = resolved.Value
return nil
}
}
value := component.Value
Expand Down Expand Up @@ -754,7 +750,6 @@ func (loader *Loader) resolveSchemaRef(doc *T, component *SchemaRef, documentPat
return err
}
component.Value = resolved.Value
return nil
}
if loader.visitedSchema == nil {
loader.visitedSchema = make(map[*Schema]struct{})
Expand Down Expand Up @@ -836,7 +831,6 @@ func (loader *Loader) resolveSecuritySchemeRef(doc *T, component *SecurityScheme
return err
}
component.Value = resolved.Value
return nil
}
}
return nil
Expand Down Expand Up @@ -873,7 +867,6 @@ func (loader *Loader) resolveExampleRef(doc *T, component *ExampleRef, documentP
return err
}
component.Value = resolved.Value
return nil
}
}
return nil
Expand Down Expand Up @@ -910,7 +903,6 @@ func (loader *Loader) resolveCallbackRef(doc *T, component *CallbackRef, documen
return err
}
component.Value = resolved.Value
return nil
}
}
value := component.Value
Expand Down Expand Up @@ -957,7 +949,6 @@ func (loader *Loader) resolveLinkRef(doc *T, component *LinkRef, documentPath *u
return err
}
component.Value = resolved.Value
return nil
}
}
return nil
Expand Down Expand Up @@ -999,10 +990,7 @@ func (loader *Loader) resolvePathItemRef(doc *T, pathItem *PathItem, documentPat
}
pathItem.Ref = ref
}
return loader.resolvePathItemRefContinued(doc, pathItem, documentPath)
}

func (loader *Loader) resolvePathItemRefContinued(doc *T, pathItem *PathItem, documentPath *url.URL) (err error) {
for _, parameter := range pathItem.Parameters {
if err = loader.resolveParameterRef(doc, parameter, documentPath); err != nil {
return
Expand Down
43 changes: 0 additions & 43 deletions openapi3/testdata/issue542.yml

This file was deleted.

0 comments on commit 47d329d

Please sign in to comment.