Documentation
¶
Overview ¶
Package gen holds the pure parts of the generator: it validates the API spec and the shared hints and emits the Go source of the error catalog, the operation scope map and the hints table. scripts/generate.go is the command that wraps it with file and network access.
Index ¶
- Constants
- func EmitCatalog(spec map[string]any) ([]byte, error)
- func EmitHints(hints map[string]string) ([]byte, error)
- func EmitScopes(spec map[string]any) ([]byte, error)
- func NameInlineObjects(spec map[string]any) ([]string, error)
- func ParseHints(text []byte) (map[string]string, error)
- func ParseSpec(text []byte) (map[string]any, error)
- func PatchPathParameters(spec map[string]any) (patchedSpec []byte, changed []string, err error)
Constants ¶
const (
// DefaultSpec is where the generator fetches the API spec from when it is given no path.
DefaultSpec = "https://api.hushscript.com/openapi.json"
)
Variables ¶
This section is empty.
Functions ¶
func EmitCatalog ¶
EmitCatalog returns generated/catalog.go: the error catalog as a lookup by slug.
func EmitScopes ¶
EmitScopes returns generated/scopes.go: the permission each operation needs, keyed "METHOD /path".
func NameInlineObjects ¶ added in v1.1.0
NameInlineObjects gives every inline object schema that has properties a stable x-go-type-name derived from where it sits (Error.details becomes ErrorDetails), so oapi-codegen emits a named type instead of an anonymous struct. A named type can gain a field later without an incompatible change to package generated; an anonymous one cannot. The spec is changed in place and the names it assigned are returned, sorted. A name that another schema, another inline object or a type oapi-codegen derives from an operation already holds is an error: guessing would hide it.
func ParseHints ¶
ParseHints decodes hints.json: a flat object of slug to text.
func PatchPathParameters ¶
PatchPathParameters declares every path template variable that an operation leaves undeclared, as a required string parameter, because oapi-codegen refuses a path with an undeclared variable. It returns the patched spec as JSON for the generator's private copy (openapi.json itself is never touched) and the operations it changed. A declared path parameter that is not in the template is an error: that is a different defect, and guessing would hide it.
Types ¶
This section is empty.