rpc

package
v1.21.21 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOpenAPICommand

func NewOpenAPICommand() *cobra.Command

NewOpenAPICommand creates the OpenAPI command group that can be added to any cobra CLI

func NewOpenAPICommandWithConfig

func NewOpenAPICommandWithConfig(config *OpenAPIConfig) *cobra.Command

NewOpenAPICommandWithConfig creates the OpenAPI command group with custom configuration

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser opens the default browser to the specified URL

func ParamRole

func ParamRole(op RPCOperation, param RPCParameter) string

ParamRole classifies a parameter within its operation, deriving the supportsLookup/isListOp signals from the operation's Clicky metadata. Returns the UI role ("limit", "offset", "time-from", "time-to", "filter") or "".

func ValidateRPCOperation

func ValidateRPCOperation(operation *RPCOperation) error

ValidateRPCOperation validates a single RPC operation

func ValidateRPCService

func ValidateRPCService(service *RPCService) error

ValidateRPCService validates an RPC service before converting to OpenAPI

Types

type ClickyOperationMeta

type ClickyOperationMeta struct {
	SurfaceID          string   `json:"-"`
	Command            string   `json:"command,omitempty"`
	Surface            string   `json:"surface,omitempty"`
	Entity             string   `json:"-"`
	Parent             string   `json:"-"`
	Aliases            []string `json:"-"`
	Admin              bool     `json:"-"`
	Verb               string   `json:"verb,omitempty"`
	Scope              string   `json:"scope,omitempty"`
	ActionName         string   `json:"actionName,omitempty"`
	IDParam            string   `json:"idParam,omitempty"`
	SupportsLookup     bool     `json:"supportsLookup,omitempty"`
	SupportsFilterMode bool     `json:"supportsFilterMode,omitempty"`
	Order              int      `json:"-"`
}

ClickyOperationMeta is emitted as the OpenAPI operation-level x-clicky extension. SurfaceID/Aliases are internal-only fields used while building the final surface list.

type ClickyParameterMeta

type ClickyParameterMeta struct {
	// Role tells the UI how to render this parameter. Empty means "no
	// special handling". Recognised values:
	//   - "filter"     — show as a filter pill in the DataTable's FilterBar
	//                    (entity .Filters(...) keys or any list-op query param
	//                    when the op declares SupportsLookup).
	//   - "limit"      — drives DataTable pagination's pageSize.
	//   - "offset"     — drives DataTable pagination's page.
	//   - "time-from"  — left edge of a time-range picker.
	//   - "time-to"    — right edge of a time-range picker.
	Role string `json:"role,omitempty"`
}

ClickyParameterMeta carries UI hints for a single OpenAPI parameter so the explorer can route it to the right widget instead of treating every query param as a free-text input. Role is derived from the parameter name plus the operation's lookup capability — see paramRole.

type ClickySpecMeta

type ClickySpecMeta struct {
	Surfaces []ClickySurface `json:"surfaces,omitempty"`
}

ClickySpecMeta is emitted as the OpenAPI-level x-clicky extension.

type ClickySurface

type ClickySurface struct {
	Key         string `json:"key"`
	Entity      string `json:"entity"`
	Title       string `json:"title"`
	Parent      string `json:"parent,omitempty"`
	Admin       bool   `json:"admin,omitempty"`
	Description string `json:"description,omitempty"`
	Order       int    `json:"-"`
}

ClickySurface describes a UI surface resolved from clicky entity metadata.

type CommandExecutor

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

CommandExecutor handles dynamic execution of Cobra commands via HTTP requests

func NewCommandExecutor

func NewCommandExecutor(service *RPCService, config *ExecutorConfig) *CommandExecutor

NewCommandExecutor creates a new command executor

func (*CommandExecutor) ExecuteCommand

func (e *CommandExecutor) ExecuteCommand(op *RPCOperation, req *ExecutionRequest) (any, *ExecutionResponse, error)

ExecuteCommand executes a Cobra command with the given parameters Returns: (parsedData, metadata, error) - parsedData: The actual command output (parsed if possible, or ExecutionResponse wrapper) - metadata: Execution metadata for HTTP headers (CLI command, exit code, success) - error: Execution error if any

func (*CommandExecutor) ExtractRequestFromHTTP

func (e *CommandExecutor) ExtractRequestFromHTTP(r *http.Request, op *RPCOperation) (*ExecutionRequest, error)

ExtractRequestFromHTTP extracts execution parameters from HTTP request

func (*CommandExecutor) FindLookupOperation

func (e *CommandExecutor) FindLookupOperation(method, path string) *RPCOperation

func (*CommandExecutor) FindOperation

func (e *CommandExecutor) FindOperation(method, path string) *RPCOperation

FindOperation finds an RPC operation by HTTP method and path. Supports templated paths like /api/v1/policy/{id} matched against concrete paths like /api/v1/policy/12345.

func (*CommandExecutor) ValidateParameters

func (e *CommandExecutor) ValidateParameters(req *ExecutionRequest, op *RPCOperation) error

ValidateParameters validates request parameters against operation schema

type Config

type Config struct {
	// Default HTTP method for operations
	DefaultMethod string
	// Path prefix for REST APIs
	PathPrefix string
	// Whether to auto-generate REST paths from command hierarchy
	AutoGeneratePaths bool
	// Tags to apply to all operations
	DefaultTags []string
}

Config holds configuration for RPC conversion

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a sensible default configuration

type ContextDataFunc

type ContextDataFunc func(ctx context.Context, flags map[string]string, args []string) (any, error)

ContextDataFunc is a context-aware variant of DataFunc. When set on an operation, the executor prefers it over DataFunc and passes the request's context.Context (from r.Context() on the HTTP path, or cmd.Context() on the CLI path). It lets handlers resolve request-scoped state (e.g. a per-request database/config bundle) instead of reaching for process globals.

type ContextLookupFunc

type ContextLookupFunc func(ctx context.Context, flags map[string]string, args []string) (any, error)

ContextLookupFunc is the context-aware variant of the filter LookupFunc. When set on an operation, handleLookupCommand prefers it over LookupFunc and passes the request's context.Context (r.Context()), letting a filter resolve request-scoped state (e.g. the per-request database handle) when enumerating its option set.

type Converter

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

Converter handles converting Cobra commands to generic RPC operations

func NewConverter

func NewConverter(config *Config) *Converter

NewConverter creates a new RPC converter with the given configuration

func (*Converter) ConvertCommand

func (c *Converter) ConvertCommand(cmd *cobra.Command) (*RPCOperation, error)

ConvertCommand converts a single Cobra command to an RPC operation

func (*Converter) ConvertCommandTree

func (c *Converter) ConvertCommandTree(rootCmd *cobra.Command) (*RPCService, error)

ConvertCommandTree recursively converts a command and its subcommands

type DataFunc

type DataFunc func(flags map[string]string, args []string) (any, error)

DataFunc is a function that returns structured data directly, bypassing stdout capture. Used by commands registered via AddCommand to provide data to the HTTP handler.

type EntityActionDTO

type EntityActionDTO struct {
	Name  string `json:"name"`
	Short string `json:"short,omitempty"`
}

EntityActionDTO is the JSON shape of a registered action or bulk action.

type EntityDTO

type EntityDTO struct {
	Name        string               `json:"name"`
	Aliases     []string             `json:"aliases,omitempty"`
	Parent      string               `json:"parent,omitempty"`
	IsAdmin     bool                 `json:"is_admin,omitempty"`
	Operations  []EntityOperationDTO `json:"operations,omitempty"`
	Actions     []EntityActionDTO    `json:"actions,omitempty"`
	BulkActions []EntityActionDTO    `json:"bulk_actions,omitempty"`
}

EntityDTO is the JSON-serialisable projection of clicky.EntityInfo. reflect.Type and function fields are stripped so the registry can be exposed to HTTP clients (typically the web UI building its sidebar).

func EntitySnapshot

func EntitySnapshot() []EntityDTO

EntitySnapshot returns a serialisable projection of the current entity registry. Callers that need to embed the registry in something other than the HTTP handler (tests, custom routes) can call this directly.

type EntityOperationDTO

type EntityOperationDTO struct {
	Verb string `json:"verb"`
}

EntityOperationDTO is the JSON shape of a registered CRUD operation.

type ExecutionRequest

type ExecutionRequest struct {
	Args  []string          `json:"args,omitempty"`  // Positional arguments
	Flags map[string]string `json:"flags,omitempty"` // Flag values

	// Context carries the request's context.Context to a ContextDataFunc. On the
	// HTTP path it is r.Context(); on the CLI path it is cmd.Context(). It is
	// never serialized — it is transport state, not part of the wire contract.
	Context context.Context `json:"-"`
}

ExecutionRequest represents parameters for command execution

type ExecutionResponse

type ExecutionResponse struct {
	Success  bool              `json:"success"`
	Message  string            `json:"message,omitempty"`
	Output   string            `json:"output,omitempty"` // Combined stdout+stderr for backward compatibility
	Stdout   string            `json:"stdout,omitempty"` // Standard output only
	Stderr   string            `json:"stderr,omitempty"` // Standard error only
	ExitCode int               `json:"exit_code"`        // Command exit code (0 = success)
	Error    string            `json:"error,omitempty"`  // Error description
	Input    *ExecutionRequest `json:"input,omitempty"`  // Processed input parameters (included on errors for debugging)
	CLI      string            `json:"cli,omitempty"`    // Equivalent CLI command to reproduce this execution

	// DataIsStructured is true when the operation returned data via a DataFunc
	// (entity list/get) rather than captured stdout. The HTTP layer uses it to
	// serialize the data payload directly for structured wire formats instead of
	// substituting this (output-less) envelope. Not serialized — it's transport
	// metadata, not part of the response contract.
	DataIsStructured bool `json:"-"`
}

ExecutionResponse represents the result of command execution

type ExecutorConfig

type ExecutorConfig struct {
	Enabled    bool   // Enable dynamic command execution
	SkipPreRun bool   // Skip pre-run hooks during execution
	PathPrefix string // Path prefix for execution endpoints (defaults to /api/v1)
}

ExecutorConfig holds configuration for command execution

type HealthResponse

type HealthResponse struct {
	Status    string `json:"status"`
	Timestamp string `json:"timestamp"`
	Server    string `json:"server"`
	Version   string `json:"version"`
}

HealthResponse represents the health check response

type OpenAPIComponents

type OpenAPIComponents struct {
	Schemas         map[string]*OpenAPISchema        `json:"schemas,omitempty"`
	Responses       map[string]OpenAPIResponse       `json:"responses,omitempty"`
	Parameters      map[string]OpenAPIParameter      `json:"parameters,omitempty"`
	RequestBodies   map[string]OpenAPIRequestBody    `json:"requestBodies,omitempty"`
	Headers         map[string]OpenAPIHeader         `json:"headers,omitempty"`
	SecuritySchemes map[string]OpenAPISecurityScheme `json:"securitySchemes,omitempty"`
}

OpenAPIComponents contains reusable components

type OpenAPIConfig

type OpenAPIConfig struct {
	Title       string
	Description string
	Version     string
	Servers     []OpenAPIServer
	Contact     *OpenAPIContact
	License     *OpenAPILicense
	Tags        []OpenAPITag
}

OpenAPIConfig holds configuration for OpenAPI generation

type OpenAPIContact

type OpenAPIContact struct {
	Name  string `json:"name,omitempty"`
	URL   string `json:"url,omitempty"`
	Email string `json:"email,omitempty"`
}

OpenAPIContact contains contact information for the API

type OpenAPIExample

type OpenAPIExample struct {
	Summary     string      `json:"summary,omitempty"`
	Description string      `json:"description,omitempty"`
	Value       interface{} `json:"value,omitempty"`
}

OpenAPIExample represents an example in the OpenAPI spec

type OpenAPIExternalDocs

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

OpenAPIExternalDocs represents external documentation

type OpenAPIGenerator

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

OpenAPIGenerator generates OpenAPI specifications from RPC services

func NewOpenAPIGenerator

func NewOpenAPIGenerator(config *OpenAPIConfig) *OpenAPIGenerator

NewOpenAPIGenerator creates a new OpenAPI generator

func (*OpenAPIGenerator) GenerateFromCobra

func (g *OpenAPIGenerator) GenerateFromCobra(rootCmd *cobra.Command) (*OpenAPISpec, error)

GenerateFromCobra generates an OpenAPI spec directly from a Cobra command tree using the default converter Config. Equivalent to GenerateFromCobraWithConfig with a nil config.

func (*OpenAPIGenerator) GenerateFromCobraWithConfig

func (g *OpenAPIGenerator) GenerateFromCobraWithConfig(rootCmd *cobra.Command, cfg *Config) (*OpenAPISpec, error)

GenerateFromCobraWithConfig generates an OpenAPI spec from a Cobra command tree using the supplied converter Config (path prefix, default method, tags). Pass nil to fall back to DefaultConfig. Callers that mount the executor under a non-default PathPrefix (see ExecutorConfig.PathPrefix) MUST use this so the generated spec paths match the actually-registered ServeMux patterns.

func (*OpenAPIGenerator) GenerateFromService

func (g *OpenAPIGenerator) GenerateFromService(service *RPCService) *OpenAPISpec

GenerateFromService generates an OpenAPI spec from an RPC service

type OpenAPIHeader

type OpenAPIHeader struct {
	Description string         `json:"description,omitempty"`
	Required    bool           `json:"required,omitempty"`
	Schema      *OpenAPISchema `json:"schema,omitempty"`
}

OpenAPIHeader represents a header in the OpenAPI spec

type OpenAPIInfo

type OpenAPIInfo struct {
	Title       string          `json:"title"`
	Description string          `json:"description,omitempty"`
	Version     string          `json:"version"`
	Contact     *OpenAPIContact `json:"contact,omitempty"`
	License     *OpenAPILicense `json:"license,omitempty"`
}

OpenAPIInfo contains metadata about the API

type OpenAPILicense

type OpenAPILicense struct {
	Name string `json:"name"`
	URL  string `json:"url,omitempty"`
}

OpenAPILicense contains license information for the API

type OpenAPIMediaType

type OpenAPIMediaType struct {
	Schema   *OpenAPISchema            `json:"schema,omitempty"`
	Example  interface{}               `json:"example,omitempty"`
	Examples map[string]OpenAPIExample `json:"examples,omitempty"`
}

OpenAPIMediaType represents a media type in the OpenAPI spec

type OpenAPIOAuthFlow

type OpenAPIOAuthFlow struct {
	AuthorizationURL string            `json:"authorizationUrl,omitempty"`
	TokenURL         string            `json:"tokenUrl,omitempty"`
	RefreshURL       string            `json:"refreshUrl,omitempty"`
	Scopes           map[string]string `json:"scopes"`
}

OpenAPIOAuthFlow represents an OAuth flow

type OpenAPIOAuthFlows

type OpenAPIOAuthFlows struct {
	Implicit          *OpenAPIOAuthFlow `json:"implicit,omitempty"`
	Password          *OpenAPIOAuthFlow `json:"password,omitempty"`
	ClientCredentials *OpenAPIOAuthFlow `json:"clientCredentials,omitempty"`
	AuthorizationCode *OpenAPIOAuthFlow `json:"authorizationCode,omitempty"`
}

OpenAPIOAuthFlows represents OAuth flows

type OpenAPIOperation

type OpenAPIOperation struct {
	Tags        []string                   `json:"tags,omitempty"`
	Summary     string                     `json:"summary,omitempty"`
	Description string                     `json:"description,omitempty"`
	OperationID string                     `json:"operationId,omitempty"`
	Parameters  []OpenAPIParameter         `json:"parameters,omitempty"`
	RequestBody *OpenAPIRequestBody        `json:"requestBody,omitempty"`
	Responses   map[string]OpenAPIResponse `json:"responses"`
	Security    []map[string][]string      `json:"security,omitempty"`
	Clicky      *ClickyOperationMeta       `json:"x-clicky,omitempty"`
}

OpenAPIOperation represents an operation in the OpenAPI spec

type OpenAPIParameter

type OpenAPIParameter struct {
	Name        string               `json:"name"`
	In          string               `json:"in"`
	Description string               `json:"description,omitempty"`
	Required    bool                 `json:"required,omitempty"`
	Schema      *OpenAPISchema       `json:"schema,omitempty"`
	Example     interface{}          `json:"example,omitempty"`
	Clicky      *ClickyParameterMeta `json:"x-clicky,omitempty"`
}

OpenAPIParameter represents a parameter in the OpenAPI spec

type OpenAPIPath

type OpenAPIPath map[string]OpenAPIOperation

OpenAPIPath represents a path item in the OpenAPI spec

type OpenAPIRequestBody

type OpenAPIRequestBody struct {
	Description string                      `json:"description,omitempty"`
	Content     map[string]OpenAPIMediaType `json:"content"`
	Required    bool                        `json:"required,omitempty"`
}

OpenAPIRequestBody represents a request body in the OpenAPI spec

type OpenAPIResponse

type OpenAPIResponse struct {
	Description string                      `json:"description"`
	Headers     map[string]OpenAPIHeader    `json:"headers,omitempty"`
	Content     map[string]OpenAPIMediaType `json:"content,omitempty"`
}

OpenAPIResponse represents a response in the OpenAPI spec

type OpenAPISchema

type OpenAPISchema struct {
	Type                 string                    `json:"type,omitempty"`
	Format               string                    `json:"format,omitempty"`
	Description          string                    `json:"description,omitempty"`
	Enum                 []interface{}             `json:"enum,omitempty"`
	Default              interface{}               `json:"default,omitempty"`
	Properties           map[string]*OpenAPISchema `json:"properties,omitempty"`
	Required             []string                  `json:"required,omitempty"`
	Items                *OpenAPISchema            `json:"items,omitempty"`
	AdditionalProperties *OpenAPISchema            `json:"additionalProperties,omitempty"`
	Nullable             bool                      `json:"nullable,omitempty"`
	Example              interface{}               `json:"example,omitempty"`
}

OpenAPISchema represents a schema in the OpenAPI spec

type OpenAPISecurityScheme

type OpenAPISecurityScheme struct {
	Type         string             `json:"type"`
	Description  string             `json:"description,omitempty"`
	Name         string             `json:"name,omitempty"`
	In           string             `json:"in,omitempty"`
	Scheme       string             `json:"scheme,omitempty"`
	BearerFormat string             `json:"bearerFormat,omitempty"`
	Flows        *OpenAPIOAuthFlows `json:"flows,omitempty"`
}

OpenAPISecurityScheme represents a security scheme

type OpenAPIServer

type OpenAPIServer struct {
	URL         string                     `json:"url"`
	Description string                     `json:"description,omitempty"`
	Variables   map[string]OpenAPIVariable `json:"variables,omitempty"`
}

OpenAPIServer represents a server in the OpenAPI spec

type OpenAPISpec

type OpenAPISpec struct {
	OpenAPI    string                 `json:"openapi"`
	Info       OpenAPIInfo            `json:"info"`
	Servers    []OpenAPIServer        `json:"servers,omitempty"`
	Paths      map[string]OpenAPIPath `json:"paths"`
	Components *OpenAPIComponents     `json:"components,omitempty"`
	Tags       []OpenAPITag           `json:"tags,omitempty"`
	Clicky     *ClickySpecMeta        `json:"x-clicky,omitempty"`
}

OpenAPISpec represents an OpenAPI 3.0 specification

func GenerateFromRPCOperation

func GenerateFromRPCOperation(operation *RPCOperation, config *OpenAPIConfig) (*OpenAPISpec, error)

GenerateFromRPCOperation creates an OpenAPI spec from a single RPC operation

func GenerateFromRPCService

func GenerateFromRPCService(service *RPCService, config *OpenAPIConfig) (*OpenAPISpec, error)

GenerateFromRPCService creates an OpenAPI spec directly from an RPC service

func (*OpenAPISpec) ToJSON

func (spec *OpenAPISpec) ToJSON() ([]byte, error)

ToJSON converts the OpenAPI spec to JSON

func (*OpenAPISpec) ToYAML

func (spec *OpenAPISpec) ToYAML() ([]byte, error)

ToYAML converts the OpenAPI spec to YAML

type OpenAPITag

type OpenAPITag struct {
	Name         string               `json:"name"`
	Description  string               `json:"description,omitempty"`
	ExternalDocs *OpenAPIExternalDocs `json:"externalDocs,omitempty"`
}

OpenAPITag represents a tag for grouping operations

type OpenAPIValidator

type OpenAPIValidator struct{}

OpenAPIValidator provides validation for OpenAPI specifications

func NewOpenAPIValidator

func NewOpenAPIValidator() *OpenAPIValidator

NewOpenAPIValidator creates a new OpenAPI validator

func (*OpenAPIValidator) Validate

func (v *OpenAPIValidator) Validate(spec *OpenAPISpec) *ValidationResult

Validate validates an OpenAPI specification

type OpenAPIVariable

type OpenAPIVariable struct {
	Enum        []string `json:"enum,omitempty"`
	Default     string   `json:"default"`
	Description string   `json:"description,omitempty"`
}

OpenAPIVariable represents a server variable

type Property

type Property struct {
	Type        string      `json:"type"`
	Description string      `json:"description"`
	Enum        []string    `json:"enum,omitempty"`
	Default     interface{} `json:"default,omitempty"`
}

Property represents a JSON schema property

type RPCOperation

type RPCOperation struct {
	Name              string               `json:"name"`
	Description       string               `json:"description"`
	Parameters        []RPCParameter       `json:"parameters"`
	Schema            Schema               `json:"schema"`
	Command           *cobra.Command       `json:"-"`                // Reference to original command
	Path              string               `json:"path,omitempty"`   // For REST APIs
	Method            string               `json:"method,omitempty"` // HTTP method
	Tags              []string             `json:"tags,omitempty"`   // For grouping
	DataFunc          DataFunc             `json:"-"`                // Direct data provider, bypasses stdout capture
	ContextDataFunc   ContextDataFunc      `json:"-"`                // Context-aware data provider; preferred over DataFunc when set
	LookupFunc        DataFunc             `json:"-"`                // Direct filter metadata provider
	ContextLookupFunc ContextLookupFunc    `json:"-"`                // Context-aware filter metadata provider; preferred over LookupFunc when set
	Clicky            *ClickyOperationMeta `json:"-"`                // Entity semantics used for OpenAPI extensions
	ResponseType      reflect.Type         `json:"-"`                // Static response type for OpenAPI generation
	ResponseArray     bool                 `json:"-"`                // Response body is an array of ResponseType
	ResponsePaged     bool                 `json:"-"`                // Response body is a paged envelope around ResponseType rows
	ResponseEntityID  bool                 `json:"-"`                // Array item schema should include Clicky _id metadata
}

RPCOperation represents a generic RPC operation that can be converted to various formats

type RPCParameter

type RPCParameter struct {
	Name        string      `json:"name"`
	Type        string      `json:"type"`
	Description string      `json:"description"`
	Required    bool        `json:"required"`
	Default     interface{} `json:"default,omitempty"`
	In          string      `json:"in,omitempty"` // "query", "path", "header" for REST
}

RPCParameter represents a parameter in an RPC operation

type RPCService

type RPCService struct {
	Name        string         `json:"name"`
	Version     string         `json:"version"`
	Description string         `json:"description"`
	Operations  []RPCOperation `json:"operations"`
}

RPCService represents a collection of RPC operations

type Schema

type Schema struct {
	Type       string              `json:"type"`
	Properties map[string]Property `json:"properties"`
	Required   []string            `json:"required"`
}

Schema represents a JSON schema for operation input/output

type ServeConfig

type ServeConfig struct {
	Host        string
	Port        int
	Title       string
	Description string
	Version     string
	AutoRefresh bool
	Open        bool
	SkipHealth  bool            // Skip registering /health (caller provides their own)
	Executor    *ExecutorConfig // Optional command execution configuration
}

ServeConfig holds configuration for the OpenAPI serve command

func DefaultServeConfig

func DefaultServeConfig() *ServeConfig

DefaultServeConfig returns default configuration for the serve command

type SwaggerServer

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

SwaggerServer serves API reference documentation for the OpenAPI specification.

func NewSwaggerServer

func NewSwaggerServer(config *ServeConfig, rootCmd *cobra.Command, openAPIConfig *OpenAPIConfig) *SwaggerServer

NewSwaggerServer creates a new OpenAPI documentation server

func (*SwaggerServer) ConverterConfig

func (s *SwaggerServer) ConverterConfig() *Config

ConverterConfig returns the converter Config used to build the executor's routes (path prefix, default method, etc.). Callers that re-run GenerateFromCobraWithConfig outside this server — e.g. to merge a separate OpenAPI document with the executor spec — should pass this value so the regenerated paths match the actually-registered ServeMux patterns. Returns nil when the server was constructed without an executor.

func (*SwaggerServer) HandleEntities

func (s *SwaggerServer) HandleEntities(w http.ResponseWriter, r *http.Request)

HandleEntities serves the entity metadata endpoint. Exported so callers composing their own mux can register it independently of RegisterRoutes.

func (*SwaggerServer) HandleHealth

func (s *SwaggerServer) HandleHealth(w http.ResponseWriter, r *http.Request)

HandleHealth serves the liveness probe. Exported for the same reason as HandleEntities.

func (*SwaggerServer) HandleOpenAPIJSON

func (s *SwaggerServer) HandleOpenAPIJSON(w http.ResponseWriter, r *http.Request)

HandleOpenAPIJSON serves the OpenAPI 3 spec as JSON. Exported so callers that compose their own mux (and want to wrap or override this endpoint) can re-mount it without going through RegisterRoutes.

func (*SwaggerServer) HandleOpenAPIYAML

func (s *SwaggerServer) HandleOpenAPIYAML(w http.ResponseWriter, r *http.Request)

HandleOpenAPIYAML serves the OpenAPI 3 spec as YAML. See HandleOpenAPIJSON.

func (*SwaggerServer) RegisterExecutionRoutes

func (s *SwaggerServer) RegisterExecutionRoutes(mux *http.ServeMux)

RegisterExecutionRoutes registers only the dynamic executor patterns derived from the RPC service (one method+path per operation). Exported so callers that want everything from RegisterRoutes except the openapi handlers (because they intend to wrap /api/openapi.json with a merge across multiple specs) can opt in route-by-route.

func (*SwaggerServer) RegisterRoutes

func (s *SwaggerServer) RegisterRoutes(mux *http.ServeMux)

Start starts the HTTP server RegisterRoutes registers all API routes onto the provided mux. This allows callers to compose the SwaggerServer routes with other handlers.

func (*SwaggerServer) Start

func (s *SwaggerServer) Start(ctx context.Context) error

type TemplateData

type TemplateData struct {
	Title       string
	Description string
	Version     string
	Timestamp   string
	AutoRefresh bool
}

TemplateData holds data for rendering the HTML template

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a validation error

func (ValidationError) Error

func (e ValidationError) Error() string

type ValidationResult

type ValidationResult struct {
	Valid  bool
	Errors []ValidationError
}

ValidationResult contains the results of validation

Jump to

Keyboard shortcuts

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