openapi

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 8 Imported by: 0

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 New

func New() *Processor

New creates a new OpenAPI Processor.

func (*Processor) ExtractHeadings

func (p *Processor) ExtractHeadings(src []byte) []core.Heading

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

func (p *Processor) ExtractTitle(src []byte) string

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

func (p *Processor) RenderHTML(src []byte) ([]byte, []core.Heading, error)

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

func (p *Processor) ToPlainText(src []byte) string

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.

Jump to

Keyboard shortcuts

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