mirror of
https://github.com/zap-proto/zip.git
synced 2026-10-19 15:38:57 +00:00
One registry, three projections. A typed op already produced a REST route, an OpenAPI path and an MCP tool; it now also produces a command. cli.go derives `<service> <operation>` from the op's own identity, so adding a route can never rename an existing command, and LocalInvoke runs it through the op's own invoke seam — a fused binary needs no client because the command IS the handler call. clispec.go builds the same commands from a served spec, which is what lets the CLI drive a service it was not linked against. cmd/zipdoc + internal/zipdoc close the gap Go leaves: doc comments do not exist at run time, so prose reaches the spec only via a build-time AST pass. Field docs and examples are extracted from source and keyed "<Type>.<field>". Two defects found by making the projections agree: commandName treated "ends in a parameter" as the only way to address one thing, so GET /v1/paas/apps/:app/deploy became apps-deploy-LIST — named for a collection, returning one deploy. The route already says which it is past its parameter: /apps/:app/deploy is singular, /nodes/:node/jobs is plural. OpenAPI parameters carried no description while the registry had one, so the same argument had help in-process and none from the spec. Both now read the same key, and query parameters get it too. internal/jsontag exists so the reflect view of the wire-name rule and the AST view cannot drift; transport gains a dial-only https, because reaching a published API is an ordinary Mount and terminating TLS stays the ingress's job. Co-authored-by: Hanzo Dev <[email protected]>
29 lines
670 B
Go
29 lines
670 B
Go
// Package badexample compiles fine and documents itself wrongly: its Example is
|
|
// not JSON. Generation has to fail on it, because the alternative is a spec that
|
|
// ships an example nobody can send.
|
|
package badexample
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zap-proto/zip"
|
|
)
|
|
|
|
// In is the request.
|
|
type In struct {
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// Out is the response.
|
|
type Out struct {
|
|
OK bool `json:"ok"`
|
|
}
|
|
|
|
// Register wires the one broken operation.
|
|
func Register(app *zip.App) { zip.Post(app, "/v1/things", Create) }
|
|
|
|
// Create makes a thing.
|
|
//
|
|
// Example: {"name": "ada",}
|
|
func Create(_ context.Context, in *In) (*Out, error) { return &Out{OK: in.Name != ""}, nil }
|