openapi

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package openapi generates OpenAPI documents from Runa routes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApiKey

func ApiKey(name string, in string, key string) route.Security

ApiKey returns an api key security scheme name.

func Basic

func Basic(name string) route.Security

Basic returns a basic auth security scheme name.

func Bearer

func Bearer(name string) route.Security

Bearer returns a bearer auth security scheme name.

func ExportCommand

func ExportCommand(registry *Registry, routes *route.Registry) runacommand.Command

ExportCommand creates an OpenAPI export command.

func OAuth2

func OAuth2(name string, flows OAuthFlows) route.Security

OAuth2 returns an OAuth2 security scheme name.

func Provider

func Provider(docs ...Config) provider.Provider

Provider creates an OpenAPI provider.

Types

type Components

type Components struct {
	SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty"`
}

Components stores reusable OpenAPI components.

type Config

type Config struct {
	Name        string
	Title       string
	Version     string
	Description string
	Servers     []ServerInfo
	JSONPath    string
	UIPath      string
	Viewer      Viewer
}

Config stores OpenAPI document domain config.

func Register

func Register(name string, options ...Option) Config

Register creates an OpenAPI document config.

type Document

type Document struct {
	OpenAPI    string                          `json:"openapi"`
	Info       Info                            `json:"info"`
	Servers    []ServerInfo                    `json:"servers,omitempty"`
	Paths      map[string]map[string]Operation `json:"paths"`
	Components Components                      `json:"components,omitempty"`
}

Document is a minimal OpenAPI 3.1 document.

func Generate

func Generate(config Config, routes []*route.Route) Document

Generate creates an OpenAPI document from routes.

type Header struct {
	Description string            `json:"description,omitempty"`
	Schema      *route.TypeSchema `json:"schema,omitempty"`
}

Header describes a response header.

type Info

type Info struct {
	Title       string `json:"title"`
	Version     string `json:"version"`
	Description string `json:"description,omitempty"`
}

Info describes the API.

type Media

type Media struct {
	Schema *route.TypeSchema `json:"schema,omitempty"`
}

Media describes media type content.

type OAuthFlows

type OAuthFlows map[string]any

OAuthFlows stores OAuth2 flow definitions.

type Operation

type Operation struct {
	OperationID string                `json:"operationId,omitempty"`
	Summary     string                `json:"summary,omitempty"`
	Description string                `json:"description,omitempty"`
	Tags        []string              `json:"tags,omitempty"`
	Deprecated  bool                  `json:"deprecated,omitempty"`
	Security    []map[string][]string `json:"security,omitempty"`
	Parameters  []Parameter           `json:"parameters,omitempty"`
	RequestBody *RequestBody          `json:"requestBody,omitempty"`
	Responses   map[string]Response   `json:"responses"`
}

Operation describes an endpoint operation.

type Option

type Option func(*Config)

Option configures an OpenAPI document domain.

func Description

func Description(value string) Option

Description sets document description.

func JSON

func JSON(path string) Option

JSON sets JSON output path.

func Server

func Server(url string, description ...string) Option

Server appends a document server.

func ServerURL

func ServerURL(url string, description ...string) Option

ServerURL appends a document server.

func Title

func Title(value string) Option

Title sets document title.

func UI

func UI(path string, viewers ...Viewer) Option

UI sets UI output path.

func Version

func Version(value string) Option

Version sets document version.

type Parameter

type Parameter struct {
	Name        string            `json:"name"`
	In          string            `json:"in"`
	Description string            `json:"description,omitempty"`
	Required    bool              `json:"required,omitempty"`
	Schema      *route.TypeSchema `json:"schema,omitempty"`
}

Parameter describes an operation parameter.

type Registry

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

Registry stores OpenAPI document domains.

func Default

func Default() *Registry

Default returns the default OpenAPI registry.

func New

func New() *Registry

New creates an OpenAPI registry.

func (*Registry) Config

func (registry *Registry) Config(name string) (Config, bool)

Config returns a document domain config.

func (*Registry) Document

func (registry *Registry) Document(name string, routes []*route.Route) (Document, bool)

Document generates a document domain.

func (*Registry) JSONBytes

func (registry *Registry) JSONBytes(name string, routes []*route.Route) ([]byte, bool, error)

JSONBytes generates JSON bytes for a document domain.

func (*Registry) List

func (registry *Registry) List() []Config

List returns registered document domains.

func (*Registry) Mount

func (registry *Registry) Mount(routes *route.Registry, name string, options ...Option) Config

Mount registers OpenAPI JSON and UI routes.

func (*Registry) MountConfig

func (registry *Registry) MountConfig(routes *route.Registry, config Config) Config

MountConfig registers an OpenAPI config and mounts JSON/UI routes.

func (*Registry) Register

func (registry *Registry) Register(name string, options ...Option) Config

Register registers a document domain.

func (*Registry) RegisterConfig

func (registry *Registry) RegisterConfig(config Config) Config

RegisterConfig registers a document domain from an already merged config.

type RequestBody

type RequestBody struct {
	Required bool             `json:"required,omitempty"`
	Content  map[string]Media `json:"content"`
}

RequestBody describes an operation request body.

type Response

type Response struct {
	Description string            `json:"description"`
	Content     map[string]Media  `json:"content,omitempty"`
	Headers     map[string]Header `json:"headers,omitempty"`
}

Response describes an operation response.

type SecurityScheme

type SecurityScheme struct {
	Type         string `json:"type"`
	Scheme       string `json:"scheme,omitempty"`
	BearerFormat string `json:"bearerFormat,omitempty"`
	In           string `json:"in,omitempty"`
	Name         string `json:"name,omitempty"`
}

SecurityScheme describes a security scheme.

type ServerInfo

type ServerInfo struct {
	URL         string `json:"url"`
	Description string `json:"description,omitempty"`
}

ServerInfo describes an OpenAPI server.

type Viewer

type Viewer interface {
	HTML(config Config, specURL string) string
}

Viewer renders an OpenAPI web UI.

func ScalarViewer

func ScalarViewer() Viewer

ScalarViewer renders Scalar API Reference from CDN.

type ViewerFunc

type ViewerFunc func(config Config, specURL string) string

ViewerFunc adapts a function to Viewer.

func (ViewerFunc) HTML

func (fn ViewerFunc) HTML(config Config, specURL string) string

HTML renders an OpenAPI web UI.

Jump to

Keyboard shortcuts

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