Documentation
¶
Overview ¶
Package spec parses the vendored PMOCK OpenAPI document and turns it into the CLI command catalog.
The OpenAPI file is the single source of truth: command paths, flags, descriptions, required fields and enum hints all come from it. The small overlay.yaml only supplies product decisions the spec cannot express (curated command names, aliases, risk level, hidden internal operations).
Index ¶
Constants ¶
const ( TypeString = "string" TypeInteger = "integer" TypeNumber = "number" TypeBoolean = "boolean" TypeStringArray = "string[]" TypeIntArray = "integer[]" )
Flag types understood by the command builder and the request encoder.
Variables ¶
var Methods = []string{"get", "post", "put", "delete", "patch"}
Methods lists the HTTP methods this CLI understands.
Functions ¶
Types ¶
type Catalog ¶
type Catalog struct {
Commands []*Command
// Doc is the OpenAPI document the catalog was built from. Skill rendering
// needs it to resolve response $refs into field tables.
Doc *Document
}
Catalog is the full command surface.
type Command ¶
type Command struct {
Key string // METHOD /path
Method string
Path string
Summary string
Description string
PathParts []string
Aliases []string
Risk Risk
Internal bool
Async string
OperateType string
BodyDefaults map[string]any
Examples []string
// Notes overrides upstream prose that is wrong or incomplete, rendered as
// a callout on the skill page. Empty for most commands.
Notes string
Flags []*Flag
// ComplexRequired lists required body fields that cannot be a flag
// (arrays of objects / nested objects); they must be supplied via --json.
ComplexRequired []string
Body *Schema
BodySchemaName string
// Resp is the resolved 200 response schema and RespSchemaName its
// components name. The generated skill pages render field tables from it.
Resp *Schema
RespSchemaName string
}
Command is one generated CLI leaf command.
func (*Command) HasJSONInput ¶
HasJSONInput reports whether --json is meaningful for this command.
type CommandOverride ¶
type CommandOverride struct {
Op string `yaml:"op"`
Path []string `yaml:"path"`
Aliases []string `yaml:"aliases,omitempty"`
Risk string `yaml:"risk,omitempty"`
Internal bool `yaml:"internal,omitempty"`
Async string `yaml:"async,omitempty"`
OperateType string `yaml:"operate_type,omitempty"`
Defaults map[string]any `yaml:"defaults,omitempty"`
Examples []string `yaml:"examples,omitempty"`
// Notes corrects or augments the upstream OpenAPI prose for one command,
// e.g. a parameter description that is wrong in the published spec.
// Rendered as a callout on the command's skill page.
Notes string `yaml:"notes,omitempty"`
// ParamDescriptions replaces the upstream description of individual
// flags, keyed by kebab-case flag name. The published spec is generated
// from backend annotations and is occasionally wrong (phone list used to
// claim page-size was capped at 1), so the correction must reach --help
// and the generated tables, not just the skill page.
ParamDescriptions map[string]string `yaml:"param_descriptions,omitempty"`
}
CommandOverride overrides one operation. Op is "METHOD /path".
type Components ¶
Components holds reusable schemas.
type Document ¶
type Document struct {
OpenAPI string `yaml:"openapi"`
Info Info `yaml:"info"`
Paths map[string]map[string]*Operation `yaml:"paths"`
Components Components `yaml:"components"`
}
Document is the subset of OpenAPI 3.0 used by this CLI.
func (*Document) BodySchema ¶
BodySchema returns the resolved JSON body schema for an operation.
func (*Document) Operations ¶
func (d *Document) Operations() []OperationRef
Operations returns all HTTP operations in a deterministic order.
type Flag ¶
type Flag struct {
Name string // kebab-case CLI name, without --
Field string // JSON / query field name
In string // query, path, or body
Type string
Description string
Required bool
Enum []any
Default any
}
Flag is one generated command-line flag.
type Info ¶
type Info struct {
Title string `yaml:"title"`
Description string `yaml:"description"`
Version string `yaml:"version"`
}
Info is the OpenAPI info block.
type Operation ¶
type Operation struct {
Summary string `yaml:"summary"`
Description string `yaml:"description"`
Tags []string `yaml:"tags"`
Parameters []Parameter `yaml:"parameters"`
RequestBody *RequestBody `yaml:"requestBody"`
Responses map[string]Response `yaml:"responses"`
Deprecated bool `yaml:"deprecated"`
}
Operation is one HTTP operation.
type OperationRef ¶
OperationRef is an operation plus its HTTP coordinates.
func (OperationRef) Key ¶
func (r OperationRef) Key() string
Key is the stable identifier used by overlay.yaml.
type Overlay ¶
type Overlay struct {
Commands []CommandOverride `yaml:"commands"`
}
Overlay supplies the product decisions that the OpenAPI document cannot express: the user-facing command path, aliases, risk level, and whether an operation is an internal building block that should stay out of `--help`.
type Parameter ¶
type Parameter struct {
Name string `yaml:"name"`
In string `yaml:"in"`
Description string `yaml:"description"`
Required bool `yaml:"required"`
Schema *Schema `yaml:"schema"`
}
Parameter is a path or query parameter. Header parameters (the doc generator's placeholder `chameleon`) are parsed but ignored by the catalog.
type RequestBody ¶
type RequestBody struct {
Required bool `yaml:"required"`
Content map[string]MediaType `yaml:"content"`
}
RequestBody describes a JSON request body.
type Response ¶
type Response struct {
Description string `yaml:"description"`
Content map[string]MediaType `yaml:"content"`
}
Response is an HTTP response.
type Schema ¶
type Schema struct {
Ref string `yaml:"$ref"`
Type string `yaml:"type"`
Format string `yaml:"format"`
Description string `yaml:"description"`
Required []string `yaml:"required"`
Properties map[string]*Schema `yaml:"properties"`
Items *Schema `yaml:"items"`
Enum []any `yaml:"enum"`
Example any `yaml:"example"`
Default any `yaml:"default"`
Nullable bool `yaml:"nullable"`
}
Schema is the subset of JSON Schema used by the PMOCK spec. It covers primitives, arrays and $ref objects; the spec uses no allOf/oneOf/anyOf.