Documentation
¶
Overview ¶
Package apiggo turns an OpenAPI contract into Go source: it loads the spec, builds an intermediate representation, and renders three layers — DTOs, HTTP adapters, and handler stubs. The generated HTTP layer depends only on the standard library plus the companion runtime in github.com/siyoga/apiggo/server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// ContractPath is the path to the OpenAPI contract (YAML or JSON).
ContractPath string
// OutRoot is the directory the generated tree is written under.
OutRoot string
// Module is the Go module path of the target project, used to build import
// paths in the generated code (e.g. "github.com/acme/svc").
Module string
// DTOPkg, RouterPkg and APIPkg are module-relative package paths for the
// three layers.
DTOPkg string // default "generated/dto"
RouterPkg string // default "generated/router"
APIPkg string // default "api"
}
Config drives a single generation run.
type Field ¶
type Field struct {
GoName string
Type string // Go type expression, in dto-package terms
JSON string // full struct tag body, e.g. `json:"name,omitempty"`
}
Field is one struct field.
type NamedType ¶
type NamedType struct {
Name string
Doc string
// exactly one of the following is populated
Struct []Field
Enum *EnumDef
Alias string // for `type Name = Alias`
// APIError marks a generated error type; when set the template emits the
// APIError methods (StatusCode/Body/Error).
APIError bool
Status int
MessageExpr string // expression returned by Error(), e.g. e.Message or a literal
}
NamedType is a top-level generated type in the dto package.
type Operation ¶
type Operation struct {
ID string // PascalCase base (from operationId)
Method string // "GET"
Pattern string // "/users/{id}" (Go 1.22 mux syntax matches OpenAPI)
Params []Param
HasBody bool
InType string // "<ID>In"
OutType string // "<ID>Out"
Errors []string
}
Operation is one contract operation to emit a descriptor + stub for.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
apiggo
command
Command apiggo generates dto, http-adapter and handler-stub code from an OpenAPI contract.
|
Command apiggo generates dto, http-adapter and handler-stub code from an OpenAPI contract. |
|
examples
|
|
|
petstore
command
Command petstore is the apiggo end-to-end example: an OpenAPI contract (api/openapi.yaml) generated into DTOs + HTTP adapters (generated/) with handler stubs (api/) implemented against an in-memory store, all wired onto the apiggo runtime and served over HTTP.
|
Command petstore is the apiggo end-to-end example: an OpenAPI contract (api/openapi.yaml) generated into DTOs + HTTP adapters (generated/) with handler stubs (api/) implemented against an in-memory store, all wired onto the apiggo runtime and served over HTTP. |
|
petstore/api/createpet
Package createpet implements the CreatePet operation handler for the petstore example.
|
Package createpet implements the CreatePet operation handler for the petstore example. |
|
petstore/api/getpet
Package getpet implements the GetPet operation handler for the petstore example.
|
Package getpet implements the GetPet operation handler for the petstore example. |
|
petstore/generated/dto
Code generated by apiggo.
|
Code generated by apiggo. |
|
petstore/generated/router
Code generated by apiggo.
|
Code generated by apiggo. |
|
petstore/store
Package store is a tiny in-memory pet repository.
|
Package store is a tiny in-memory pet repository. |
|
Package server is the thin net/http runtime that hosts apiggo-generated code: option-based configuration, a middleware chain, panic recovery, unified error handling via the APIError interface, and graceful shutdown.
|
Package server is the thin net/http runtime that hosts apiggo-generated code: option-based configuration, a middleware chain, panic recovery, unified error handling via the APIError interface, and graceful shutdown. |
Click to show internal directories.
Click to hide internal directories.