petstore

command module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 10 Imported by: 0

README

petstore — forge kit reference service

Runnable example of a REST service built with github.com/fromforgesoftware/forge/go/kit. Demonstrates:

  • rest.WithOpenAPI(...) — auto-generated OpenAPI 3.1 spec for every registered route
  • rest.HandlerWithOpenAPI(...) — per-route annotation (summary, description, tags, errors)
  • openapi.SpecSecurityScheme + openapi.DefaultSecurity — bearer auth applied to all routes by default
  • openapi.NoSecurity() — explicit per-route override (used by the mock login)
  • Swagger UI — served at /docs, with a working Authorize button

Run

go run .

Then:

# Inspect the spec
curl http://localhost:8080/openapi.json | jq

# Open the interactive UI
open http://localhost:8080/docs

Try it from Swagger UI

  1. Open http://localhost:8080/docs.
  2. Hit POST /login-mock, send any username, copy the returned token.
  3. Click Authorize at the top, paste the token, Authorize, Close.
  4. Use any of the /v1/pets endpoints with "Try it out".

Endpoints

Method Path Notes
POST /v1/pets Create — Errors(401, 400)
GET /v1/pets List
GET /v1/pets/{id} Get — Errors(404)
PATCH /v1/pets/{id} Update — Errors(404, 400)
DELETE /v1/pets/{id} Delete — Errors(404)
POST /v1/pets/{id}/adopt Action endpoint — Errors(404, 409)
POST /login-mock Public — NoSecurity()

Layout

A single main.go for readability — domain, repo, HTTP handlers, and entry point in one file. A real service would split these into packages (internal/domain, internal/repository, internal/transport/http); this example deliberately doesn't, so the kit's surface is visible end-to-end at a glance.

Documentation

Overview

Package main is the Pet Store example service for forge kit.

It exercises every kit feature touched by the OpenAPI 3.1 work:

  • rest.WithOpenAPI server option
  • per-handler annotations via rest.HandlerWithOpenAPI
  • openapi.Spec* spec-level options (title, version, servers, tags, security)
  • openapi.DefaultSecurity + openapi.NoSecurity override
  • openapi.SpecSecurityScheme with openapi.BearerJWT
  • Swagger UI rendered at /docs

Run with:

go run ./go/cmd/petstore

Then:

curl http://localhost:8080/openapi.json | jq
open http://localhost:8080/docs

Jump to

Keyboard shortcuts

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