contract

command
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 6 Imported by: 0

README

Contract example

Demonstrates Huma DTOs, D10 validation errors, success meta, §41 category errors (not_found), /openapi.json, and the /docs try-it-out UI on framework.App.API().

Run

go run ./examples/contract

Open http://127.0.0.1:8080/docs for Swagger UI. Try-it-out calls this same process. Raw Gin routes are not listed there.

curl -sS http://127.0.0.1:8080/openapi.json
go run ./cmd/gombit openapi generate \
  --url http://127.0.0.1:8080/openapi.json \
  --out /tmp/gombit-openapi.json

List (data + page meta)

curl -sS http://127.0.0.1:8080/api/v1/widgets

Get existing / missing

curl -sS http://127.0.0.1:8080/api/v1/widgets/widget-1
curl -sS http://127.0.0.1:8080/api/v1/widgets/missing

Missing id returns:

{
  "error": {
    "code": "not_found",
    "message": "widget not found",
    "request_id": "..."
  }
}

Valid create

curl -sS -X POST http://127.0.0.1:8080/api/v1/widgets \
  -H 'Content-Type: application/json' \
  -d '{"name":"Second widget","color":"green"}'

Invalid body (D10 field errors)

curl -sS -X POST http://127.0.0.1:8080/api/v1/widgets \
  -H 'Content-Type: application/json' \
  -d '{}'

See docs/contract.md and docs/openapi.md.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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