Documentation ¶
Index ¶
- type Resolver
- func (resolver *Resolver) CheckForCircularReferences() []*ResolvingError
- func (resolver *Resolver) GetCircularErrors() []*index.CircularReferenceResult
- func (resolver *Resolver) GetNonPolymorphicCircularErrors() []*index.CircularReferenceResult
- func (resolver *Resolver) GetPolymorphicCircularErrors() []*index.CircularReferenceResult
- func (resolver *Resolver) GetResolvingErrors() []*ResolvingError
- func (resolver *Resolver) Resolve() []*ResolvingError
- func (resolver *Resolver) VisitReference(ref *index.Reference, seen map[string]bool, journey []*index.Reference, ...) []*yaml.Node
- type ResolvingError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver will use a *index.SpecIndex to stitch together a resolved root tree using all the discovered references in the doc.
func NewResolver ¶
NewResolver will create a new resolver from a *index.SpecIndex
Example ¶
Example of how to resolve the Stripe OpenAPI specification, and check for circular reference errors
// create a yaml.Node reference as a root node. var rootNode yaml.Node // load in the Stripe OpenAPI spec (lots of polymorphic complexity in here) stripeBytes, _ := ioutil.ReadFile("../test_specs/stripe.yaml") // unmarshal bytes into our rootNode. _ = yaml.Unmarshal(stripeBytes, &rootNode) // create a new spec index (resolver depends on it) index := index.NewSpecIndex(&rootNode) // create a new resolver using the index. resolver := NewResolver(index) // resolve the document, if there are circular reference errors, they are returned/ // WARNING: this is a destructive action and the rootNode will be PERMANENTLY altered and cannot be unresolved circularErrors := resolver.Resolve() // The Stripe API has a bunch of circular reference problems, mainly from polymorphism. // So let's print them out. // fmt.Printf("There are %d circular reference errors, %d of them are polymorphic errors, %d are not", len(circularErrors), len(resolver.GetPolymorphicCircularErrors()), len(resolver.GetNonPolymorphicCircularErrors()))
Output: There are 21 circular reference errors, 19 of them are polymorphic errors, 2 are not
func (*Resolver) CheckForCircularReferences ¶ added in v0.0.5
func (resolver *Resolver) CheckForCircularReferences() []*ResolvingError
CheckForCircularReferences Check for circular references, without resolving, a non-destructive run.
func (*Resolver) GetCircularErrors ¶
func (resolver *Resolver) GetCircularErrors() []*index.CircularReferenceResult
GetCircularErrors returns all circular reference errors found.
func (*Resolver) GetNonPolymorphicCircularErrors ¶ added in v0.0.5
func (resolver *Resolver) GetNonPolymorphicCircularErrors() []*index.CircularReferenceResult
GetNonPolymorphicCircularErrors returns all circular errors that DO NOT stem from polymorphism
func (*Resolver) GetPolymorphicCircularErrors ¶ added in v0.0.5
func (resolver *Resolver) GetPolymorphicCircularErrors() []*index.CircularReferenceResult
GetPolymorphicCircularErrors returns all circular errors that stem from polymorphism
func (*Resolver) GetResolvingErrors ¶
func (resolver *Resolver) GetResolvingErrors() []*ResolvingError
GetResolvingErrors returns all errors found during resolving
func (*Resolver) Resolve ¶
func (resolver *Resolver) Resolve() []*ResolvingError
Resolve will resolve the specification, everything that is not polymorphic and not circular, will be resolved. this data can get big, it results in a massive duplication of data. This is a destructive method and will permanently re-organize the node tree. Make sure you have copied your original tree before running this (if you want to preserve original data)
type ResolvingError ¶
ResolvingError represents an issue the resolver had trying to stitch the tree together.