Documentation ¶
Overview ¶
Package index contains an OpenAPI indexer that will very quickly scan through an OpenAPI specification (all versions) and extract references to all the important nodes you might want to look up, as well as counts on total objects.
When extracting references, the index can determine if the reference is local to the file (recommended) or the reference is located in another local file, or a remote file. The index will then attempt to load in those remote files and look up the references there, or continue following the chain.
When the index loads in a local or remote file, it will also index that remote spec as well. This means everything is indexed and stored as a tree, depending on how deep the remote references go.
Index ¶
- Constants
- func DetermineReferenceResolveType(ref string) int
- func GenerateCleanSpecConfigBaseURL(baseURL *url.URL, dir string, includeFile bool) string
- type CircularReferenceResult
- type DescriptionReference
- type EnumReference
- type ExternalLookupFunction
- type IndexingError
- type ObjectReference
- type Reference
- type ReferenceMapped
- type RemoteURLHandler
- type SpecIndex
- func (index *SpecIndex) AddChild(child *SpecIndex)
- func (index *SpecIndex) AllowCircularReferenceResolving() bool
- func (index *SpecIndex) BuildIndex()
- func (index *SpecIndex) CheckForSeenRemoteSource(url string) (bool, *yaml.Node)
- func (index *SpecIndex) ExtractComponentsFromRefs(refs []*Reference) []*Reference
- func (index *SpecIndex) ExtractExternalDocuments(node *yaml.Node) []*Reference
- func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string, level int, poly bool, pName string) []*Reference
- func (index *SpecIndex) FindComponent(componentId string, parent *yaml.Node) *Reference
- func (index *SpecIndex) FindComponentInRoot(componentId string) *Reference
- func (index *SpecIndex) GetAllCallbacks() map[string]*Reference
- func (index *SpecIndex) GetAllCombinedReferences() map[string]*Reference
- func (index *SpecIndex) GetAllComponentSchemas() map[string]*Reference
- func (index *SpecIndex) GetAllDescriptions() []*DescriptionReference
- func (index *SpecIndex) GetAllDescriptionsCount() int
- func (index *SpecIndex) GetAllEnums() []*EnumReference
- func (index *SpecIndex) GetAllExamples() map[string]*Reference
- func (index *SpecIndex) GetAllExternalDocuments() map[string]*Reference
- func (index *SpecIndex) GetAllExternalIndexes() map[string]*SpecIndex
- func (index *SpecIndex) GetAllHeaders() map[string]*Reference
- func (index *SpecIndex) GetAllInlineSchemaObjects() []*Reference
- func (index *SpecIndex) GetAllInlineSchemas() []*Reference
- func (index *SpecIndex) GetAllLinks() map[string]*Reference
- func (index *SpecIndex) GetAllObjectsWithProperties() []*ObjectReference
- func (index *SpecIndex) GetAllOperationsServers() map[string]map[string][]*Reference
- func (index *SpecIndex) GetAllParameters() map[string]*Reference
- func (index *SpecIndex) GetAllParametersFromOperations() map[string]map[string]map[string][]*Reference
- func (index *SpecIndex) GetAllPaths() map[string]map[string]*Reference
- func (index *SpecIndex) GetAllReferences() map[string]*Reference
- func (index *SpecIndex) GetAllRequestBodies() map[string]*Reference
- func (index *SpecIndex) GetAllResponses() map[string]*Reference
- func (index *SpecIndex) GetAllRootServers() []*Reference
- func (index *SpecIndex) GetAllSchemas() []*Reference
- func (index *SpecIndex) GetAllSecuritySchemes() map[string]*Reference
- func (index *SpecIndex) GetAllSequencedReferences() []*Reference
- func (index *SpecIndex) GetAllSummaries() []*DescriptionReference
- func (index *SpecIndex) GetAllSummariesCount() int
- func (index *SpecIndex) GetChildren() []*SpecIndex
- func (index *SpecIndex) GetCircularReferences() []*CircularReferenceResult
- func (index *SpecIndex) GetComponentParameterCount() int
- func (index *SpecIndex) GetComponentSchemaCount() int
- func (index *SpecIndex) GetDiscoveredReferences() map[string]*Reference
- func (index *SpecIndex) GetGlobalCallbacksCount() int
- func (index *SpecIndex) GetGlobalLinksCount() int
- func (index *SpecIndex) GetGlobalTagsCount() int
- func (index *SpecIndex) GetGlobalTagsNode() *yaml.Node
- func (index *SpecIndex) GetInlineDuplicateParamCount() int
- func (index *SpecIndex) GetInlineOperationDuplicateParameters() map[string][]*Reference
- func (index *SpecIndex) GetInlineUniqueParamCount() int
- func (index *SpecIndex) GetLinesWithReferences() map[int]bool
- func (index *SpecIndex) GetMappedReferences() map[string]*Reference
- func (index *SpecIndex) GetMappedReferencesSequenced() []*ReferenceMapped
- func (index *SpecIndex) GetOperationCount() int
- func (index *SpecIndex) GetOperationParameterReferences() map[string]map[string]map[string][]*Reference
- func (index *SpecIndex) GetOperationParametersIndexErrors() []error
- func (index *SpecIndex) GetOperationTags() map[string]map[string][]*Reference
- func (index *SpecIndex) GetOperationTagsCount() int
- func (index *SpecIndex) GetOperationsParameterCount() int
- func (index *SpecIndex) GetParametersNode() *yaml.Node
- func (index *SpecIndex) GetPathCount() int
- func (index *SpecIndex) GetPathsNode() *yaml.Node
- func (index *SpecIndex) GetPolyAllOfReferences() []*Reference
- func (index *SpecIndex) GetPolyAnyOfReferences() []*Reference
- func (index *SpecIndex) GetPolyOneOfReferences() []*Reference
- func (index *SpecIndex) GetPolyReferences() map[string]*Reference
- func (index *SpecIndex) GetRawReferenceCount() int
- func (index *SpecIndex) GetReferenceIndexErrors() []error
- func (index *SpecIndex) GetReferencesWithSiblings() map[string]Reference
- func (index *SpecIndex) GetRefsByLine() map[string]map[int]bool
- func (index *SpecIndex) GetRootNode() *yaml.Node
- func (index *SpecIndex) GetRootSecurityNode() *yaml.Node
- func (index *SpecIndex) GetRootSecurityReferences() []*Reference
- func (index *SpecIndex) GetRootServersNode() *yaml.Node
- func (index *SpecIndex) GetSchemasNode() *yaml.Node
- func (index *SpecIndex) GetSecurityRequirementReferences() map[string]map[string][]*Reference
- func (index *SpecIndex) GetTotalTagsCount() int
- func (index *SpecIndex) SearchAncestryForSeenURI(uri string) *SpecIndex
- func (index *SpecIndex) SearchIndexForReference(ref string) []*Reference
- func (index *SpecIndex) SetAllowCircularReferenceResolving(allow bool)
- func (index *SpecIndex) SetCircularReferences(refs []*CircularReferenceResult)
- type SpecIndexConfig
Examples ¶
Constants ¶
const ( LocalResolve = iota HttpResolve FileResolve )
Constants used to determine if resolving is local, file based or remote file based.
Variables ¶
This section is empty.
Functions ¶
func DetermineReferenceResolveType ¶ added in v0.0.5
Types ¶
type CircularReferenceResult ¶
type CircularReferenceResult struct { Journey []*Reference Start *Reference LoopIndex int LoopPoint *Reference IsPolymorphicResult bool // if this result comes from a polymorphic loop. IsInfiniteLoop bool // if all the definitions in the reference loop are marked as required, this is an infinite circular reference, thus is not allowed. }
CircularReferenceResult contains a circular reference found when traversing the graph.
func (*CircularReferenceResult) GenerateJourneyPath ¶ added in v0.0.5
func (c *CircularReferenceResult) GenerateJourneyPath() string
type DescriptionReference ¶
DescriptionReference holds data about a description that was found and where it was found.
type EnumReference ¶
type EnumReference struct { Node *yaml.Node Type *yaml.Node Path string SchemaNode *yaml.Node ParentNode *yaml.Node }
type ExternalLookupFunction ¶
type ExternalLookupFunction func(id string) (foundNode *yaml.Node, rootNode *yaml.Node, lookupError error)
ExternalLookupFunction is for lookup functions that take a JSONSchema reference and tries to find that node in the URI based document. Decides if the reference is local, remote or in a file.
type IndexingError ¶
IndexingError holds data about something that went wrong during indexing.
func (*IndexingError) Error ¶
func (i *IndexingError) Error() string
type ObjectReference ¶ added in v0.4.8
type ObjectReference struct { Node *yaml.Node Path string ParentNode *yaml.Node }
type Reference ¶
type Reference struct { Definition string Name string Node *yaml.Node ParentNode *yaml.Node Resolved bool Circular bool Seen bool IsRemote bool RemoteLocation string Path string // this won't always be available. RequiredRefProperties map[string][]string // definition names (eg, #/definitions/One) to a list of required properties on this definition which reference that definition }
Reference is a wrapper around *yaml.Node results to make things more manageable when performing algorithms on data models. the *yaml.Node def is just a bit too low level for tracking state.
type ReferenceMapped ¶
ReferenceMapped is a helper struct for mapped references put into sequence (we lose the key)
type RemoteURLHandler ¶ added in v0.9.3
type SpecIndex ¶
type SpecIndex struct {
// contains filtered or unexported fields
}
SpecIndex is a complete pre-computed index of the entire specification. Numbers are pre-calculated and quick direct access to paths, operations, tags are all available. No need to walk the entire node tree in rules, everything is pre-walked if you need it.
func NewSpecIndex
deprecated
func NewSpecIndex(rootNode *yaml.Node) *SpecIndex
NewSpecIndex will create a new index of an OpenAPI or Swagger spec. It's not resolved or converted into anything other than a raw index of every node for every content type in the specification. This process runs as fast as possible so dependencies looking through the tree, don't need to walk the entire thing over, and over.
Deprecated: Use NewSpecIndexWithConfig instead, this function will be removed in the future because it defaults to allowing remote references and file references. This is a potential security risk and should be controlled by providing a SpecIndexConfig that explicitly sets the AllowRemoteLookup and AllowFileLookup to true. This function also does not support specifications with relative references that may not exist locally.
Example ¶
Example of how to load in an OpenAPI Specification and index it.
// define a rootNode to hold our raw spec AST. var rootNode yaml.Node // load in the stripe OpenAPI specification into bytes (it's pretty meaty) stripeSpec, _ := ioutil.ReadFile("../test_specs/stripe.yaml") // unmarshal spec into our rootNode _ = yaml.Unmarshal(stripeSpec, &rootNode) // create a new specification index. index := NewSpecIndexWithConfig(&rootNode, CreateOpenAPIIndexConfig()) // print out some statistics fmt.Printf("There are %d references\n"+ "%d paths\n"+ "%d operations\n"+ "%d component schemas\n"+ "%d inline schemas\n"+ "%d inline schemas that are objects or arrays\n"+ "%d total schemas\n"+ "%d enums\n"+ "%d polymorphic references", len(index.GetAllCombinedReferences()), len(index.GetAllPaths()), index.GetOperationCount(), len(index.GetAllComponentSchemas()), len(index.GetAllInlineSchemas()), len(index.GetAllInlineSchemaObjects()), len(index.GetAllSchemas()), len(index.GetAllEnums()), len(index.GetPolyOneOfReferences())+len(index.GetPolyAnyOfReferences()))
Output: There are 537 references 246 paths 402 operations 537 component schemas 9798 inline schemas 711 inline schemas that are objects or arrays 10335 total schemas 1516 enums 828 polymorphic references
func NewSpecIndexWithConfig ¶ added in v0.6.0
func NewSpecIndexWithConfig(rootNode *yaml.Node, config *SpecIndexConfig) *SpecIndex
NewSpecIndexWithConfig will create a new index of an OpenAPI or Swagger spec. It uses the same logic as NewSpecIndex except it sets a base URL for resolving relative references, except it also allows for granular control over how the index is set up.
func (*SpecIndex) AllowCircularReferenceResolving ¶ added in v0.0.5
AllowCircularReferenceResolving will return a bit that allows developers to determine what to do with circular refs.
func (*SpecIndex) BuildIndex ¶ added in v0.9.0
func (index *SpecIndex) BuildIndex()
BuildIndex will run all of the count operations required to build up maps of everything. It's what makes the index useful for looking up things, the count operations are all run in parallel and then the final calculations are run the index is ready.
func (*SpecIndex) CheckForSeenRemoteSource ¶ added in v0.6.0
CheckForSeenRemoteSource will check to see if we have already seen this remote source and return it, to avoid making duplicate remote calls for document data.
func (*SpecIndex) ExtractComponentsFromRefs ¶
ExtractComponentsFromRefs returns located components from references. The returned nodes from here can be used for resolving as they contain the actual object properties.
func (*SpecIndex) ExtractExternalDocuments ¶
ExtractExternalDocuments will extract the number of externalDocs nodes found in the document.
func (*SpecIndex) ExtractRefs ¶
func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string, level int, poly bool, pName string) []*Reference
ExtractRefs will return a deduplicated slice of references for every unique ref found in the document. The total number of refs, will generally be much higher, you can extract those from GetRawReferenceCount()
func (*SpecIndex) FindComponent ¶
FindComponent will locate a component by its reference, returns nil if nothing is found. This method will recurse through remote, local and file references. For each new external reference a new index will be created. These indexes can then be traversed recursively.
func (*SpecIndex) FindComponentInRoot ¶ added in v0.0.5
func (*SpecIndex) GetAllCallbacks ¶
GetAllCallbacks will return all links found in the document (under components)
func (*SpecIndex) GetAllCombinedReferences ¶
GetAllCombinedReferences will return the number of unique and polymorphic references discovered.
func (*SpecIndex) GetAllComponentSchemas ¶ added in v0.5.0
GetAllComponentSchemas will return all schemas defined in the components section of the document.
func (*SpecIndex) GetAllDescriptions ¶
func (index *SpecIndex) GetAllDescriptions() []*DescriptionReference
GetAllDescriptions will return all descriptions found in the document
func (*SpecIndex) GetAllDescriptionsCount ¶
GetAllDescriptionsCount will collect together every single description found in the document
func (*SpecIndex) GetAllEnums ¶
func (index *SpecIndex) GetAllEnums() []*EnumReference
GetAllEnums will return all enums found in the document
func (*SpecIndex) GetAllExamples ¶
GetAllExamples will return all examples found in the document (under components)
func (*SpecIndex) GetAllExternalDocuments ¶
GetAllExternalDocuments will return all external documents found
func (*SpecIndex) GetAllExternalIndexes ¶ added in v0.0.5
GetAllExternalIndexes will return all indexes for external documents
func (*SpecIndex) GetAllHeaders ¶
GetAllHeaders will return all headers found in the document (under components)
func (*SpecIndex) GetAllInlineSchemaObjects ¶ added in v0.5.0
GetAllInlineSchemaObjects will return all schemas that are inline (not inside components) and that are also typed as 'object' or 'array' (not primitives).
func (*SpecIndex) GetAllInlineSchemas ¶ added in v0.5.0
GetAllInlineSchemas will return all schemas defined in the components section of the document.
func (*SpecIndex) GetAllLinks ¶
GetAllLinks will return all links found in the document (under components)
func (*SpecIndex) GetAllObjectsWithProperties ¶ added in v0.4.8
func (index *SpecIndex) GetAllObjectsWithProperties() []*ObjectReference
GetAllObjectsWithProperties will return all objects with properties found in the document
func (*SpecIndex) GetAllOperationsServers ¶
GetAllOperationsServers will return all operation overrides for servers.
func (*SpecIndex) GetAllParameters ¶
GetAllParameters will return all parameters found in the document (under components)
func (*SpecIndex) GetAllParametersFromOperations ¶
func (index *SpecIndex) GetAllParametersFromOperations() map[string]map[string]map[string][]*Reference
GetAllParametersFromOperations will return all paths indexed in the document
func (*SpecIndex) GetAllPaths ¶
GetAllPaths will return all paths indexed in the document
func (*SpecIndex) GetAllReferences ¶
GetAllReferences will return every reference found in the spec, after being de-duplicated.
func (*SpecIndex) GetAllRequestBodies ¶
GetAllRequestBodies will return all requestBodies found in the document (under components)
func (*SpecIndex) GetAllResponses ¶
GetAllResponses will return all responses found in the document (under components)
func (*SpecIndex) GetAllRootServers ¶
GetAllRootServers will return all root servers defined
func (*SpecIndex) GetAllSchemas ¶
GetAllSchemas will return references to all schemas found in the document both inline and those under components The first elements of at the top of the slice, are all the inline references (using GetAllInlineSchemas), and then following on are all the references extracted from the components section (using GetAllComponentSchemas).
func (*SpecIndex) GetAllSecuritySchemes ¶
GetAllSecuritySchemes will return all security schemes / definitions found in the document.
func (*SpecIndex) GetAllSequencedReferences ¶
GetAllSequencedReferences will return every reference (in sequence) that was found (non-polymorphic)
func (*SpecIndex) GetAllSummaries ¶
func (index *SpecIndex) GetAllSummaries() []*DescriptionReference
GetAllSummaries will return all summaries found in the document
func (*SpecIndex) GetAllSummariesCount ¶
GetAllSummariesCount will collect together every single summary found in the document
func (*SpecIndex) GetChildren ¶ added in v0.6.0
GetChildren returns the children of this index.
func (*SpecIndex) GetCircularReferences ¶ added in v0.0.5
func (index *SpecIndex) GetCircularReferences() []*CircularReferenceResult
GetCircularReferences will return any circular reference results that were found by the resolver.
func (*SpecIndex) GetComponentParameterCount ¶
GetComponentParameterCount returns the number of parameter components defined
func (*SpecIndex) GetComponentSchemaCount ¶
GetComponentSchemaCount will return the number of schemas located in the 'components' or 'definitions' node.
func (*SpecIndex) GetDiscoveredReferences ¶
GetDiscoveredReferences will return all unique references found in the spec
func (*SpecIndex) GetGlobalCallbacksCount ¶ added in v0.0.5
GetGlobalCallbacksCount for each response of each operation method, multiple callbacks can be defined
func (*SpecIndex) GetGlobalLinksCount ¶
GetGlobalLinksCount for each response of each operation method, multiple callbacks can be defined
func (*SpecIndex) GetGlobalTagsCount ¶
GetGlobalTagsCount will return the number of tags found in the top level 'tags' node of the document.
func (*SpecIndex) GetGlobalTagsNode ¶
func (index *SpecIndex) GetGlobalTagsNode() *yaml.Node
GetGlobalTagsNode returns document root tags node.
func (*SpecIndex) GetInlineDuplicateParamCount ¶
GetInlineDuplicateParamCount returns the number of inline duplicate parameters (operation params)
func (*SpecIndex) GetInlineOperationDuplicateParameters ¶
GetInlineOperationDuplicateParameters will return a map of duplicates located in operation parameters.
func (*SpecIndex) GetInlineUniqueParamCount ¶
GetInlineUniqueParamCount returns the number of unique inline parameters (operation params)
func (*SpecIndex) GetLinesWithReferences ¶
GetLinesWithReferences will return a map of lines that have a $ref
func (*SpecIndex) GetMappedReferences ¶
GetMappedReferences will return all references that were mapped successfully to actual property nodes. this collection is completely unsorted, traversing it may produce random results when resolving it and encountering circular references can change results depending on where in the collection the resolver started its journey through the index.
func (*SpecIndex) GetMappedReferencesSequenced ¶
func (index *SpecIndex) GetMappedReferencesSequenced() []*ReferenceMapped
GetMappedReferencesSequenced will return all references that were mapped successfully to nodes, performed in sequence as they were read in from the document.
func (*SpecIndex) GetOperationCount ¶
GetOperationCount returns the number of operations (for all paths) located in the document
func (*SpecIndex) GetOperationParameterReferences ¶
func (index *SpecIndex) GetOperationParameterReferences() map[string]map[string]map[string][]*Reference
GetOperationParameterReferences will return all references to operation parameters
func (*SpecIndex) GetOperationParametersIndexErrors ¶
GetOperationParametersIndexErrors any errors that occurred when indexing operation parameters
func (*SpecIndex) GetOperationTags ¶
GetOperationTags will return all references to all tags found in operations.
func (*SpecIndex) GetOperationTagsCount ¶
GetOperationTagsCount will return the number of operation tags found (tags referenced in operations)
func (*SpecIndex) GetOperationsParameterCount ¶
GetOperationsParameterCount returns the number of parameters defined in paths and operations. this method looks in top level (path level) and inside each operation (get, post etc.). Parameters can be hiding within multiple places.
func (*SpecIndex) GetParametersNode ¶
func (index *SpecIndex) GetParametersNode() *yaml.Node
GetParametersNode will return the schema's node found in the spec
func (*SpecIndex) GetPathCount ¶
GetPathCount will return the number of paths found in the spec
func (*SpecIndex) GetPathsNode ¶
func (index *SpecIndex) GetPathsNode() *yaml.Node
GetPathsNode returns document root node.
func (*SpecIndex) GetPolyAllOfReferences ¶
GetPolyAllOfReferences will return every 'allOf' polymorphic reference in the doc
func (*SpecIndex) GetPolyAnyOfReferences ¶
GetPolyAnyOfReferences will return every 'anyOf' polymorphic reference in the doc
func (*SpecIndex) GetPolyOneOfReferences ¶
GetPolyOneOfReferences will return every 'allOf' polymorphic reference in the doc
func (*SpecIndex) GetPolyReferences ¶
GetPolyReferences will return every polymorphic reference in the doc
func (*SpecIndex) GetRawReferenceCount ¶
GetRawReferenceCount will return the number of raw references located in the document.
func (*SpecIndex) GetReferenceIndexErrors ¶ added in v0.0.5
GetReferenceIndexErrors will return any errors that occurred when indexing references
func (*SpecIndex) GetReferencesWithSiblings ¶
GetReferencesWithSiblings will return a map of all the references with sibling nodes (illegal)
func (*SpecIndex) GetRefsByLine ¶
GetRefsByLine will return all references and the lines at which they were found.
func (*SpecIndex) GetRootNode ¶
func (index *SpecIndex) GetRootNode() *yaml.Node
GetRootNode returns document root node.
func (*SpecIndex) GetRootSecurityNode ¶
func (index *SpecIndex) GetRootSecurityNode() *yaml.Node
GetRootSecurityNode will return the root security node
func (*SpecIndex) GetRootSecurityReferences ¶
GetRootSecurityReferences will return all root security settings
func (*SpecIndex) GetRootServersNode ¶
func (index *SpecIndex) GetRootServersNode() *yaml.Node
GetRootServersNode will return the root servers node
func (*SpecIndex) GetSchemasNode ¶
func (index *SpecIndex) GetSchemasNode() *yaml.Node
GetSchemasNode will return the schema's node found in the spec
func (*SpecIndex) GetSecurityRequirementReferences ¶ added in v0.1.4
GetSecurityRequirementReferences will return all security requirement definitions found in the document
func (*SpecIndex) GetTotalTagsCount ¶
GetTotalTagsCount will return the number of global and operation tags found that are unique.
func (*SpecIndex) SearchAncestryForSeenURI ¶ added in v0.8.2
func (*SpecIndex) SearchIndexForReference ¶ added in v0.6.0
SearchIndexForReference searches the index for a reference, first looking through the mapped references and then externalSpecIndex for a match. If no match is found, it will recursively search the child indexes extracted when parsing the OpenAPI Spec.
func (*SpecIndex) SetAllowCircularReferenceResolving ¶ added in v0.0.5
SetAllowCircularReferenceResolving will flip a bit that can be used by any consumers to determine if they want to allow or disallow circular references to be resolved or visited
func (*SpecIndex) SetCircularReferences ¶ added in v0.0.5
func (index *SpecIndex) SetCircularReferences(refs []*CircularReferenceResult)
SetCircularReferences is a convenience method for the resolver to pass in circular references if the resolver is used.
type SpecIndexConfig ¶ added in v0.6.0
type SpecIndexConfig struct { // The BaseURL will be the root from which relative references will be resolved from if they can't be found locally. // // For example: // - $ref: somefile.yaml#/components/schemas/SomeSchema // // Might not be found locally, if the file was pulled in from a remote server (a good example is the DigitalOcean API). // so by setting a BaseURL, the reference will try to be resolved from the remote server. // // If our baseURL is set to https://pb33f.io/libopenapi then our reference will try to be resolved from: // - $ref: https://pb33f.io/libopenapi/somefile.yaml#/components/schemas/SomeSchema // // More details on relative references can be found in issue #73: https://github.com/pb33f/libopenapi/issues/73 BaseURL *url.URL // set the Base URL for resolving relative references if the spec is exploded. // If resolving remotely, the RemoteURLHandler will be used to fetch the remote document. // If not set, the default http client will be used. // Resolves [#132]: https://github.com/pb33f/libopenapi/issues/132 RemoteURLHandler func(url string) (*http.Response, error) // FSHandler is an entity that implements the `fs.FS` interface that will be used to fetch local or remote documents. // This is useful if you want to use a custom file system handler, or if you want to use a custom http client or // custom network implementation for a lookup. // // libopenapi will pass the path to the FSHandler, and it will be up to the handler to determine how to fetch // the document. This is really useful if your application has a custom file system or uses a database for storing // documents. // // Is the FSHandler is set, it will be used for all lookups, regardless of whether they are local or remote. // it also overrides the RemoteURLHandler if set. // // Resolves[#85] https://github.com/pb33f/libopenapi/issues/85 FSHandler fs.FS // If resolving locally, the BasePath will be the root from which relative references will be resolved from BasePath string // set the Base Path for resolving relative references if the spec is exploded. // In an earlier version of libopenapi (pre 0.6.0) the index would automatically resolve all references // They could have been local, or they could have been remote. This was a problem because it meant // There was a potential for a remote exploit if a remote reference was malicious. There aren't any known // exploits, but it's better to be safe than sorry. // // To read more about this, you can find a discussion here: https://github.com/pb33f/libopenapi/pull/64 AllowRemoteLookup bool // Allow remote lookups for references. Defaults to false AllowFileLookup bool // Allow file lookups for references. Defaults to false // ParentIndex allows the index to be created with knowledge of a parent, before being parsed. This allows // a breakglass to be used to prevent loops, checking the tree before recursing down. ParentIndex *SpecIndex // If set to true, the index will not be built out, which means only the foundational elements will be // parsed and added to the index. This is useful to avoid building out an index if the specification is // broken up into references and you want it fully resolved. // // Use the `BuildIndex()` method on the index to build it out once resolved/ready. AvoidBuildIndex bool // contains filtered or unexported fields }
SpecIndexConfig is a configuration struct for the SpecIndex introduced in 0.6.0 that provides an expandable set of granular options. The first being the ability to set the Base URL for resolving relative references, and allowing or disallowing remote or local file lookups.
func CreateClosedAPIIndexConfig ¶ added in v0.6.0
func CreateClosedAPIIndexConfig() *SpecIndexConfig
CreateClosedAPIIndexConfig is a helper function to create a new SpecIndexConfig with the AllowRemoteLookup and AllowFileLookup set to false. This is the default behaviour of the index in versions 0.6.0+
The default BasePath is the current working directory.
func CreateOpenAPIIndexConfig ¶ added in v0.6.0
func CreateOpenAPIIndexConfig() *SpecIndexConfig
CreateOpenAPIIndexConfig is a helper function to create a new SpecIndexConfig with the AllowRemoteLookup and AllowFileLookup set to true. This is the default behaviour of the index in previous versions of libopenapi. (pre 0.6.0)
The default BasePath is the current working directory.