-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Almost complete rewrite using generics - Adds loading with `$ref` resolution - Adds validation
- Loading branch information
Showing
151 changed files
with
16,430 additions
and
5,780 deletions.
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
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,70 @@ | ||
package openapi | ||
|
||
import "fmt" | ||
|
||
type DuplicateAnchorError struct { | ||
A *Anchor | ||
B *Anchor | ||
} | ||
|
||
func (dae *DuplicateAnchorError) Error() string { | ||
return fmt.Sprintf("duplicate anchor: %s", dae.A.Name) | ||
} | ||
|
||
type AnchorType uint8 | ||
|
||
const ( | ||
AnchorTypeUndefined AnchorType = iota | ||
AnchorTypeRegular // $anchor | ||
AnchorTypeRecursive // $recursiveAnchor | ||
AnchorTypeDynamic // $dynamicAnchor | ||
) | ||
|
||
type Anchor struct { | ||
Location | ||
In *Schema | ||
Name Text | ||
Type AnchorType | ||
} | ||
|
||
type Anchors struct { | ||
Standard map[Text]Anchor // $anchor | ||
Recursive *Anchor // $recursiveAnchor | ||
Dynamic map[Text]Anchor // $dynamicAnchor | ||
} | ||
|
||
func (a *Anchors) merge(b *Anchors, err error) (*Anchors, error) { | ||
if err != nil { | ||
return nil, err | ||
} | ||
if b == nil { | ||
return a, nil | ||
} | ||
|
||
// we do not merge recursive anchors as they must be at the root of the | ||
// document. This method is only called when merging schemas from nested | ||
// components, so we can, and should, drop them from result if not coming | ||
// from a. | ||
|
||
if a == nil { | ||
return &Anchors{ | ||
Standard: b.Standard, | ||
Dynamic: b.Dynamic, | ||
}, nil | ||
} | ||
for k, bv := range b.Standard { | ||
if av, ok := a.Standard[k]; ok { | ||
return nil, &DuplicateAnchorError{&av, &bv} | ||
} | ||
a.Standard[k] = bv | ||
} | ||
|
||
for k, bv := range b.Dynamic { | ||
if av, ok := a.Dynamic[k]; ok { | ||
return nil, &DuplicateAnchorError{&av, &bv} | ||
} | ||
a.Dynamic[k] = bv | ||
} | ||
|
||
return a, nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.