jsonref

package
v0.27.2-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMaxRecursions = 10
View Source
var ErrMaxRecursion = errors.New("reached max number of recursions")
View Source
var ErrReferenceLoop = errors.New("reference loop detected")

Functions

This section is empty.

Types

type Option

type Option = option.Interface

func WithRecursiveResolution

func WithRecursiveResolution(b bool) Option

WithRecursiveResolution allows ou to enable recursive resolution on the *result* data structure. This means that after resolving the JSON reference in the structure at hand, it does another pass at resolving the entire data structure. Depending on your structure and size, this may incur significant cost.

Please note that recursive resolution of the result is still experimental. If you find problems, please submit a pull request with a failing test case.

type Provider

type Provider interface {
	Get(*url.URL) (interface{}, error)
}

Provider resolves a URL into a ... thing.

type Resolver

type Resolver struct {
	MaxRecursions int
	// contains filtered or unexported fields
}

Resolver is responsible for interpreting the provided JSON reference.

func New

func New() *Resolver

New creates a new Resolver

func (*Resolver) AddProvider

func (r *Resolver) AddProvider(p Provider) error

AddProvider adds a new Provider to be searched for in case a JSON pointer with more than just the URI fragment is given.

func (*Resolver) Resolve

func (r *Resolver) Resolve(v interface{}, ptr string, options ...Option) (ret interface{}, err error)

Resolve takes a target `v`, and a JSON pointer `spec`. spec is expected to be in the form of

[scheme://[userinfo@]host/path[?query]]#fragment
[scheme:opaque[?query]]#fragment

where everything except for `#fragment` is optional. If the fragment is empty, an error is returned.

If `spec` is the empty string, `v` is returned This method handles recursive JSON references.

If `WithRecursiveResolution` option is given and its value is true, an attempt to resolve all references within the resulting object is made by traversing the structure recursively. Default is false

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL