spec

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package spec loads the embedded OpenAPI document and derives the CLI's command surface from it.

Index

Constants

View Source
const WebhookEventsTag = "Webhook Events"

Marks 56 documentation stubs with no operationId, synthetic paths, and a 404 on call — excluded from commands but kept as the event-type list.

Variables

This section is empty.

Functions

func ApplyPaging

func ApplyPaging(req *Request, cmd Command, p Paging)

Sets limit/offset in the query for GET or the body for POST search operations, never overwriting values the caller already supplied.

func DeriveName

func DeriveName(tag, operationID string) (resource, action string)

Pure function of tag and operationId, whose stability is already an SDK contract, so derived names are just as stable.

func EventTypes

func EventTypes(doc *openapi3.T) []string

EventTypes reads webhook event names off the excluded stubs. These drive validation and completion for `trigger` and `listen --events`.

func Load

func Load() (*openapi3.T, error)

func Skeleton

func Skeleton(cmd Command) (string, error)

Only required fields are emitted live; optional ones are commented out, since an untouched optional numeric field sent as "" fails request binding.

func StripComments

func StripComments(s string) string

StripComments removes // lines so an edited skeleton can be parsed as JSON.

Types

type Command

type Command struct {
	Resource  string
	Action    string
	Operation Operation
	Derived   bool // true when auto-derived rather than curated
}

type Field

type Field struct {
	Name     string
	Type     string
	Required bool
	Nested   bool // objects and arrays cannot be expressed as a scalar flag
	Doc      string
}

Field describes one settable body or query field, used for --help and --edit.

func BodyFields

func BodyFields(cmd Command) []Field

BodyFields lists the top-level properties of the request body schema.

type Input

type Input struct {
	PositionalID string
	Flags        map[string]string
	Data         map[string]any // from --data or --edit
}

Input is everything the user supplied on the command line.

type Operation

type Operation struct {
	ID     string
	Method string
	Path   string
	Tag    string
	Op     *openapi3.Operation
	Item   *openapi3.PathItem
}

Operation is one callable API operation.

func Operations

func Operations(doc *openapi3.T) []Operation

Operations returns every callable operation, excluding the webhook stubs and anything without an operationId.

type Page

type Page struct {
	Count  int
	Total  int
	Offset int
	Limit  int
}

Page describes one response page. Total is 0 when the response is not a list.

func PageInfo

func PageInfo(raw []byte) (Page, error)

A bare top-level "total" is not evidence on its own — InvoiceResponse's is a string amount — so detection needs a numeric total plus a real array.

func (Page) HasMore

func (p Page) HasMore(seen int) bool

Ignores the echoed offset: the API returns offset == limit even when no offset was sent, so the caller tracks how many it has actually seen.

type Paging

type Paging struct {
	Limit  int
	Offset int
}

type Region

type Region struct {
	Key         string
	BaseURL     string
	Description string
}

func Regions

func Regions(doc *openapi3.T) []Region

Derived from servers[], so adding a region to the spec needs no code change.

type Registry

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

func NewRegistry

func NewRegistry(doc *openapi3.T) (*Registry, error)

func (*Registry) Actions

func (r *Registry) Actions(resource string) []string

func (*Registry) Columns

func (r *Registry) Columns(resource string) []string

func (*Registry) Commands

func (r *Registry) Commands() []Command

func (*Registry) Excluded

func (r *Registry) Excluded() []string

func (*Registry) Lookup

func (r *Registry) Lookup(resource, action string) (Command, bool)

func (*Registry) Resources

func (r *Registry) Resources() []string

func (*Registry) Warnings

func (r *Registry) Warnings() []string

type Request

type Request struct {
	Method string
	Path   string
	Query  url.Values
	Body   any
}

func BuildRequest

func BuildRequest(cmd Command, in Input) (Request, error)

Jump to

Keyboard shortcuts

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