openapi

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package openapi provides search functionality over a pre-processed Microsoft Graph OpenAPI index.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFTSDatabase added in v1.0.14

func BuildFTSDatabase(endpoints []FullEndpoint, dbPath string) error

BuildFTSDatabase creates a SQLite FTS5 database from the full endpoint data extracted from the OpenAPI spec. The database contains both a content table (for returning results) and an FTS5 virtual table (for full-text search with Porter stemming).

func FormatFTSResults added in v1.0.14

func FormatFTSResults(results []FTSSearchResult) interface{}

FormatFTSResults converts a slice of FTSSearchResult into the standard JSON output format.

Types

type Endpoint

type Endpoint struct {
	Path        string   `json:"path"`
	Method      string   `json:"method"`
	Summary     string   `json:"summary"`
	Description string   `json:"description,omitempty"`
	Scopes      []string `json:"scopes,omitempty"`
	Resource    string   `json:"resource,omitempty"` // e.g. "users", "groups", "messages"
}

Endpoint represents a single API endpoint in the index.

type FTSIndex added in v1.0.14

type FTSIndex struct {
	// contains filtered or unexported fields
}

FTSIndex provides full-text search over a SQLite FTS5 database containing OpenAPI endpoint data.

func LoadFTSIndex added in v1.0.14

func LoadFTSIndex(path string) (*FTSIndex, error)

LoadFTSIndex opens a SQLite FTS database for searching. Callers must call Close() when done.

func (*FTSIndex) Close added in v1.0.14

func (idx *FTSIndex) Close() error

Close releases the database connection.

func (*FTSIndex) Search added in v1.0.14

func (idx *FTSIndex) Search(query, resource, method string, limit int) []FTSSearchResult

Search finds endpoints matching the given criteria using FTS5 full-text search with BM25 ranking. All criteria are ANDed together. Empty criteria are ignored.

type FTSSearchResult added in v1.0.14

type FTSSearchResult struct {
	Path            string `json:"path"`
	Method          string `json:"method"`
	OperationID     string `json:"operationId,omitempty"`
	Summary         string `json:"summary"`
	Description     string `json:"description,omitempty"`
	Resource        string `json:"resource,omitempty"`
	PathDescription string `json:"pathDescription,omitempty"`
	Tags            string `json:"tags,omitempty"`
	Scopes          string `json:"scopes,omitempty"`

	Deprecated      bool   `json:"deprecated,omitempty"`
	DocURL          string `json:"docUrl,omitempty"`
	OperationType   string `json:"operationType,omitempty"`
	Pageable        bool   `json:"pageable,omitempty"`
	Parameters      string `json:"parameters,omitempty"`
	RequestBodyRef  string `json:"requestBodyRef,omitempty"`
	RequestBodyDesc string `json:"requestBodyDesc,omitempty"`
	ResponseRef     string `json:"responseRef,omitempty"`

	MatchReason string  `json:"matchReason"`
	Score       float64 `json:"score,omitempty"`
}

FTSSearchResult contains a search result with all available fields.

func (*FTSSearchResult) SearchResultCompat added in v1.0.14

func (r *FTSSearchResult) SearchResultCompat() SearchResult

SearchResultCompat converts an FTSSearchResult to the legacy SearchResult format for backward compatibility with the JSON output format.

func (*FTSSearchResult) ToOutputMap added in v1.0.14

func (r *FTSSearchResult) ToOutputMap() map[string]interface{}

ToOutputMap converts an FTSSearchResult to a map for JSON output, including all available fields. Empty fields are omitted.

type FullEndpoint added in v1.0.14

type FullEndpoint struct {
	Path        string   `json:"path"`
	Method      string   `json:"method"`
	OperationID string   `json:"operationId,omitempty"`
	Summary     string   `json:"summary"`
	Description string   `json:"description,omitempty"`
	Resource    string   `json:"resource,omitempty"`
	Scopes      []string `json:"scopes,omitempty"`
	Tags        []string `json:"tags,omitempty"`

	// Documentation
	DocURL          string `json:"docUrl,omitempty"`
	PathDescription string `json:"pathDescription,omitempty"`

	// Deprecation
	Deprecated             bool   `json:"deprecated,omitempty"`
	DeprecationDate        string `json:"deprecationDate,omitempty"`
	DeprecationRemovalDate string `json:"deprecationRemovalDate,omitempty"`
	DeprecationDescription string `json:"deprecationDescription,omitempty"`

	// Operation metadata
	OperationType string `json:"operationType,omitempty"` // operation, action, function
	Pageable      bool   `json:"pageable,omitempty"`

	// Parameters
	Parameters []Parameter `json:"parameters,omitempty"`

	// Request/Response schema references
	RequestBodyRef  string `json:"requestBodyRef,omitempty"`
	RequestBodyDesc string `json:"requestBodyDesc,omitempty"`
	ResponseRef     string `json:"responseRef,omitempty"`
}

FullEndpoint contains all data extracted from the OpenAPI spec for a single operation, without truncation. This is the rich representation stored in the SQLite FTS database.

type Index

type Index struct {
	Endpoints []Endpoint `json:"endpoints"`
}

Index holds the full searchable OpenAPI index.

func LoadIndex

func LoadIndex(path string) (*Index, error)

LoadIndex reads and parses the pre-processed OpenAPI index JSON file.

func (*Index) Search

func (idx *Index) Search(query, resource, method string, limit int) []SearchResult

Search finds endpoints matching the given criteria. All criteria are ANDed together. Empty criteria are ignored.

type Parameter added in v1.0.14

type Parameter struct {
	Name string `json:"name"`
	In   string `json:"in"` // query, header, path
}

Parameter represents an API parameter extracted from the OpenAPI spec.

type SearchResult

type SearchResult struct {
	Endpoint
	MatchReason string `json:"matchReason"`
}

SearchResult wraps an endpoint with a relevance indicator.

Jump to

Keyboard shortcuts

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