Documentation
¶
Index ¶
- func IsOpenAPI(src []byte, detectLines int) bool
- func PointerSegments(pointer string) []string
- func ResolveRefPath(fromPath, file string) string
- func URIToPath(uri string) string
- type Component
- type Context
- type ContextKind
- type Document
- func (d *Document) ContextAt(p protocol.Position) Context
- func (d *Document) InternalRefsTo(pointer string) []protocol.Range
- func (d *Document) IsPathItem() bool
- func (d *Document) PathItemMethods(pointer string) []MethodEntry
- func (d *Document) PointerAt(p protocol.Position) string
- func (d *Document) Resolve(pointer string) (protocol.Range, bool)
- func (d *Document) TopLevelDefs() []Component
- type MethodEntry
- type Operation
- type PathRef
- type Ref
- type RefTarget
- type RefUse
- type Workspace
- func (w *Workspace) Close(path string)
- func (w *Workspace) ExternalRefsTo(targetPath, pointer string) []protocol.Location
- func (w *Workspace) Get(path string) *Document
- func (w *Workspace) GetOrLoad(path string) *Document
- func (w *Workspace) Index()
- func (w *Workspace) OrphanComponents() []RefTarget
- func (w *Workspace) Put(path string, doc *Document)
- func (w *Workspace) ReachableTargets() []RefTarget
- func (w *Workspace) ResolveExternal(fromPath string, ref Ref) (protocol.Location, bool)
- func (w *Workspace) SpecDocs() []*Document
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsOpenAPI ¶
IsOpenAPI reports whether src looks like an OpenAPI/Swagger spec: a YAML document whose first detectLines lines contain a top-level openapi:/swagger: key.
func PointerSegments ¶
PointerSegments splits a JSON pointer into its decoded path segments (RFC 6901: ~1 -> '/', ~0 -> '~').
func ResolveRefPath ¶
ResolveRefPath resolves an external ref file (relative to fromPath) to an absolute path.
Types ¶
type Component ¶
type Component struct {
Kind string
Name string
Pointer string // e.g. "/components/schemas/User"
KeyRange protocol.Range // range of the name key
}
Component is a components.<kind>.<name> definition.
type Context ¶
type Context struct {
Kind ContextKind
Pointer string // JSON pointer of the target/definition
File string // external file (for a ref) if any
Ref *RefUse // populated when Kind == ContextRef
}
Context is the navigation target resolved at a cursor position.
type ContextKind ¶
type ContextKind int
ContextKind classifies what the cursor is sitting on.
const ( ContextNone ContextKind = iota ContextRef ContextComponent )
type Document ¶
type Document struct {
URI string
IsSpec bool // true when the file looks like an OpenAPI/Swagger spec
Operations []Operation
Components []Component
Refs []RefUse
PathRefs []PathRef
// contains filtered or unexported fields
}
Document is a parsed YAML file with an OpenAPI navigation index.
func Parse ¶
Parse parses src and builds the navigation index. On a YAML syntax error it returns a Document with an empty index plus the error, so callers can keep a previous good index if they prefer.
func (*Document) InternalRefsTo ¶
InternalRefsTo returns the ranges of internal $refs in this document that point at the given pointer.
func (*Document) IsPathItem ¶
IsPathItem reports whether the document's root is a path item (its top-level keys include HTTP methods). Such fragments are surfaced as operations, not as schema-like symbols.
func (*Document) PathItemMethods ¶
func (d *Document) PathItemMethods(pointer string) []MethodEntry
PathItemMethods returns the HTTP-method entries of the path item at pointer (or the document root when pointer is ""), each with its key range. It lets the workspace expand a path-item-level $ref into METHOD /path symbols.
func (*Document) PointerAt ¶
PointerAt returns the JSON pointer of the mapping key at an LSP position, or "" if the cursor is not on a key. This lets find-references work from any definition key, including in referenced files that are not specs themselves (e.g. a top-level schema in schemas/User.yaml).
func (*Document) TopLevelDefs ¶
TopLevelDefs returns the named definitions of a non-spec fragment file for the document outline: one entry per top-level mapping key, or — when the file is a single schema body — one entry named after the file.
type MethodEntry ¶
type MethodEntry struct {
Method string // upper-cased HTTP method
OperationID string
Summary string
Range protocol.Range
}
MethodEntry is one HTTP-method key of a path item, with its key range.
type Operation ¶
type Operation struct {
Method string // upper-cased HTTP method
Path string
OperationID string
Summary string
KeyRange protocol.Range // range of the method key (get:/post:/…)
PathRange protocol.Range // range of the parent path key (/users/{id}:)
}
Operation is a single METHOD /path entry under paths.
type PathRef ¶
type PathRef struct {
Path string
File string // external file part; empty for internal refs
Pointer string // JSON pointer incl. leading '/'; empty for whole-file
PathRange protocol.Range // range of the path key (/users:)
}
PathRef is a path-item-level $ref (paths./users: {$ref: ./paths/users.yaml}), where the whole path item — and thus its operations — lives in another file.
type Ref ¶
type Ref struct {
Value string
File string // external file part; empty for internal refs
Pointer string // JSON pointer incl. leading '/'; empty if none
}
Ref is a parsed $ref value, split into its file and JSON-pointer parts.
"#/components/schemas/User" -> {Pointer: "/components/schemas/User"}
"./schemas.yaml#/User" -> {File: "./schemas.yaml", Pointer: "/User"}
"./schemas/User.yaml" -> {File: "./schemas/User.yaml"}
func (Ref) IsInternal ¶
IsInternal reports whether the ref points within the current document.
type RefTarget ¶
type RefTarget struct {
Name string // last pointer segment, or the file stem for whole-file refs
Kind string // inferred component kind ("schemas", …) or parent dir name
URI string // file:// URI of the definition
Range protocol.Range // range of the definition key (zero for whole-file refs)
}
RefTarget is a definition reachable via $ref from a spec, surfaced as a workspace symbol even when it lives in a file that is not itself a spec (e.g. a bare schemas/User.yaml fragment whose definitions are top-level keys, not entries under components:). Targets in files that are themselves specs are not returned — their symbols already come from the spec's own Operations/Components.
type RefUse ¶
type RefUse struct {
Raw string
File string // external file part; empty for internal refs
Pointer string // JSON pointer incl. leading '/'
Range protocol.Range // range of the $ref value
}
RefUse is a single $ref occurrence.
type Workspace ¶
type Workspace struct {
// contains filtered or unexported fields
}
Workspace holds every parsed YAML document keyed by absolute path. Open documents (fed by the editor) take precedence over on-disk versions.
func NewWorkspace ¶
NewWorkspace creates a workspace rooted at the given directories.
func (*Workspace) Close ¶
Close marks a document as no longer open; its last-parsed version is kept for cross-file resolution.
func (*Workspace) ExternalRefsTo ¶
ExternalRefsTo returns Locations of $refs across the workspace that point at (targetPath, pointer) via an external file reference.
func (*Workspace) Index ¶
func (w *Workspace) Index()
Index walks the workspace roots and parses every YAML file it finds. Safe to call in a goroutine; it skips files already open in the editor.
func (*Workspace) OrphanComponents ¶
OrphanComponents returns components defined in non-spec files (an explicit components: block, e.g. a shared components.yaml) regardless of whether any $ref targets them, so a schema can be found before the first ref is written. Spec files are excluded — their components come from the spec symbol pass.
func (*Workspace) ReachableTargets ¶
ReachableTargets walks the $ref graph starting from every known spec and returns the external definitions those specs point at, transitively. It is the source of workspace symbols for split specs whose schemas live in non-spec fragment files.
func (*Workspace) ResolveExternal ¶
ResolveExternal resolves an external $ref from fromPath to a Location.