apidoc

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 2 Imported by: 0

README

apidoc

import "github.com/brpaz/lib-go/apidoc"

Package apidoc provides an HTTP handler for serving OpenAPI documentation.

It exposes two routes:

  • GET /openapi.yml — raw OpenAPI spec (always enabled)
  • GET / — Scalar UI (opt-in via WithScalarUI)
Basic usage
spec, _ := os.ReadFile("openapi.yml")

h, err := apidoc.New(
    apidoc.WithSpec(spec),
    apidoc.WithScalarUI(),
)
if err != nil {
    log.Fatal(err)
}

// Mount under a prefix with chi:
r.Mount("/docs", h)

// Or with stdlib:
http.Handle("/docs/", http.StripPrefix("/docs", h))

Index

type Handler

Handler serves OpenAPI documentation. It implements [http.Handler] and is intended to be mounted at a path prefix (e.g. chi's router.Mount or http.StripPrefix + http.Handle).

GET /             → Scalar UI (requires [WithScalarUI])
GET /openapi.yml  → raw YAML spec
type Handler struct {
    // contains filtered or unexported fields
}

func New
func New(opts ...Option) (*Handler, error)

New creates a new Handler and validates required options.

func (*Handler) ServeHTTP
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Option

Option configures a Handler.

type Option func(*Handler)

func WithScalarUI
func WithScalarUI() Option

WithScalarUI enables the Scalar UI route at the handler root.

func WithSpec
func WithSpec(spec []byte) Option

WithSpec sets the raw OpenAPI spec bytes to serve.

Generated by gomarkdoc

Documentation

Overview

Package apidoc provides an HTTP handler for serving OpenAPI documentation.

It exposes two routes:

  • GET /openapi.yml — raw OpenAPI spec (always enabled)
  • GET / — Scalar UI (opt-in via WithScalarUI)

Basic usage

spec, _ := os.ReadFile("openapi.yml")

h, err := apidoc.New(
    apidoc.WithSpec(spec),
    apidoc.WithScalarUI(),
)
if err != nil {
    log.Fatal(err)
}

// Mount under a prefix with chi:
r.Mount("/docs", h)

// Or with stdlib:
http.Handle("/docs/", http.StripPrefix("/docs", h))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler serves OpenAPI documentation. It implements http.Handler and is intended to be mounted at a path prefix (e.g. chi's router.Mount or http.StripPrefix + http.Handle).

GET /             → Scalar UI (requires [WithScalarUI])
GET /openapi.yml  → raw YAML spec

func New

func New(opts ...Option) (*Handler, error)

New creates a new Handler and validates required options.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Option

type Option func(*Handler)

Option configures a Handler.

func WithScalarUI

func WithScalarUI() Option

WithScalarUI enables the Scalar UI route at the handler root.

func WithSpec

func WithSpec(spec []byte) Option

WithSpec sets the raw OpenAPI spec bytes to serve.

Jump to

Keyboard shortcuts

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