func AddLoader(predicate DocMatcher, load DocLoader)
AddLoader for a document, executed before other previously set loaders.
This sets the configuration at the package level.
NOTE:
func JSONDoc(path string) (json.RawMessage, error)
JSONDoc loads a json document from either a file or a remote url
DocLoader represents a doc loader type
type DocLoader func(string) (json.RawMessage, error)
DocLoaderWithMatch describes a loading function for a given extension match.
type DocLoaderWithMatch struct { Fn DocLoader Match DocMatcher }
func NewDocLoaderWithMatch(fn DocLoader, matcher DocMatcher) DocLoaderWithMatch
NewDocLoaderWithMatch builds a DocLoaderWithMatch to be used in load options
DocMatcher represents a predicate to check if a loader matches
type DocMatcher func(string) bool
Document represents a swagger spec document
type Document struct { // specAnalyzer Analyzer *analysis.Spec // contains filtered or unexported fields }
func Analyzed(data json.RawMessage, version string, options ...LoaderOption) (*Document, error)
Analyzed creates a new analyzed spec document for a root json.RawMessage.
func Embedded(orig, flat json.RawMessage, options ...LoaderOption) (*Document, error)
Embedded returns a Document based on embedded specs. No analysis is required
func JSONSpec(path string, options ...LoaderOption) (*Document, error)
JSONSpec loads a spec from a json document
func Spec(path string, options ...LoaderOption) (*Document, error)
Spec loads a new spec document from a local or remote path
▹ Example
func (d *Document) BasePath() string
BasePath the base path for the API specified by this spec
func (d *Document) Expanded(options ...*spec.ExpandOptions) (*Document, error)
Expanded expands the $ref fields in the spec document and returns a new spec document
func (d *Document) Host() string
Host returns the host for the API
func (d *Document) OrigSpec() *spec.Swagger
OrigSpec yields the original spec
func (d *Document) Pristine() *Document
Pristine creates a new pristine document instance based on the input data
func (d *Document) Raw() json.RawMessage
Raw returns the raw swagger spec as json bytes
func (d *Document) ResetDefinitions() *Document
ResetDefinitions gives a shallow copy with the models reset to the original spec
func (d *Document) Schema() *spec.Schema
Schema returns the swagger 2.0 schema
func (d *Document) Spec() *spec.Swagger
Spec returns the swagger spec object model
func (d *Document) SpecFilePath() string
SpecFilePath returns the file path of the spec if one is defined
func (d *Document) Version() string
Version returns the version of this spec
LoaderOption allows to fine-tune the spec loader behavior
type LoaderOption func(*options)
▹ Example
func WithDocLoader(l DocLoader) LoaderOption
WithDocLoader sets a custom loader for loading specs
func WithDocLoaderMatches(l ...DocLoaderWithMatch) LoaderOption
WithDocLoaderMatches sets a chain of custom loaders for loading specs for different extension matches.
Loaders are executed in the order of provided DocLoaderWithMatch'es.