Documentation
¶
Overview ¶
Package openapi provides an OpenAPI specification content processor. It implements the core.ContentProcessor interface for indexing, searching, and rendering OpenAPI specs (both YAML and JSON) using Scalar API Reference.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Processor ¶
type Processor struct{}
Processor implements core.ContentProcessor for OpenAPI specifications. It uses kin-openapi to parse specs and extract structured information for search indexing and title extraction. HTML rendering returns the parsed spec marshaled to JSON for consumption by Scalar API Reference.
func (*Processor) ExtractHeadings ¶
ExtractHeadings returns headings for an OpenAPI spec that match the anchor IDs generated by Scalar API Reference (v1.46+) in single-document hash-routing mode. This allows search results to deep-link directly to the matching operation or tag section in the rendered Scalar UI.
The anchor format mirrors Scalar's default generateId logic:
- Tags: "tag/{github-slug(tagName)}"
- Operations: "tag/{tagSlug}/{METHOD}{path}" (when the op has at least one tag)
- Untagged: "{METHOD}{path}"
Headings are returned in the same order that ToPlainText emits their corresponding text, so that byte offsets from fragmentMatchIndex map correctly to section boundaries built by findAnchorAtPosition.
func (*Processor) ExtractTitle ¶
ExtractTitle returns the API title from the OpenAPI info section. Falls back to an empty string if the spec cannot be parsed or has no title.
func (*Processor) RenderHTML ¶
RenderHTML returns the raw OpenAPI spec as HTML-safe content for Scalar API Reference rendering. The view layer is responsible for embedding this into a Scalar API Reference container. Headings are not extracted here because Scalar API Reference manages its own client-side navigation and anchor generation.
func (*Processor) ToPlainText ¶
ToPlainText extracts searchable plain text from an OpenAPI spec. It collects the API title, description, tag names and descriptions, then for each path (sorted alphabetically) and each HTTP method (in a fixed canonical order), emits "{METHOD} {path}" followed by the operation summary and description. This deterministic ordering ensures that ExtractHeadings and ToPlainText iterate the spec in the same sequence, enabling accurate fragment-to-anchor mapping during search result deep-linking.