-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protect from recursion in openapi3.InternaliseRefs (#578)
Co-authored-by: Dmitriy Lukiyanchuk <[email protected]>
- Loading branch information
Showing
6 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type: object | ||
properties: | ||
cat: | ||
$ref: ../openapi.yml#/components/schemas/Cat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ components: | |
$ref: ./components/Foo/Foo2.yml | ||
Bar: | ||
$ref: ./components/Bar.yml | ||
Cat: | ||
$ref: ./components/Cat.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package openapi3 | ||
|
||
func newVisited() visitedComponent { | ||
return visitedComponent{ | ||
header: make(map[*Header]struct{}), | ||
schema: make(map[*Schema]struct{}), | ||
} | ||
} | ||
|
||
type visitedComponent struct { | ||
header map[*Header]struct{} | ||
schema map[*Schema]struct{} | ||
} | ||
|
||
// resetVisited clears visitedComponent map | ||
// should be called before recursion over doc *T | ||
func (doc *T) resetVisited() { | ||
doc.visited = newVisited() | ||
} | ||
|
||
// isVisitedHeader returns `true` if the *Header pointer was already visited | ||
// otherwise it returns `false` | ||
func (doc *T) isVisitedHeader(h *Header) bool { | ||
if _, ok := doc.visited.header[h]; ok { | ||
return true | ||
} | ||
|
||
doc.visited.header[h] = struct{}{} | ||
return false | ||
} | ||
|
||
// isVisitedHeader returns `true` if the *Schema pointer was already visited | ||
// otherwise it returns `false` | ||
func (doc *T) isVisitedSchema(s *Schema) bool { | ||
if _, ok := doc.visited.schema[s]; ok { | ||
return true | ||
} | ||
|
||
doc.visited.schema[s] = struct{}{} | ||
return false | ||
} |