contractspike

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config

func Config() huma.Config

Config returns the Huma API configuration used by the spike.

func OpenAPIJSON

func OpenAPIJSON(api huma.API) ([]byte, error)

OpenAPIJSON marshals the Huma-generated OpenAPI document.

func WriteOpenAPI

func WriteOpenAPI(path string) error

WriteOpenAPI writes the Huma-generated OpenAPI document to path.

Types

type CreateWidgetBody

type CreateWidgetBody struct {
	Name  string `json:"name" minLength:"1" maxLength:"80" example:"Second widget" doc:"Human-readable widget name"`
	Color string `json:"color,omitempty" maxLength:"30" example:"green" doc:"Optional display color"`
}

CreateWidgetBody is the typed JSON request body for POST /widgets.

type Server

type Server struct {
	Router *gin.Engine
	API    huma.API
}

Server is the M0-2 spike surface that proves Huma can share a Gin router with raw Gin-only routes.

func NewServer

func NewServer() *Server

NewServer creates the default Huma-over-Gin spike server.

func NewServerWithStore

func NewServerWithStore(store *WidgetStore) *Server

NewServerWithStore creates a spike server backed by the provided store.

type SuccessEnvelope

type SuccessEnvelope[T any] struct {
	Data T `json:"data"`
}

SuccessEnvelope is the D10 success response shape used by the spike routes.

type Widget

type Widget struct {
	ID    string `json:"id" example:"widget-1" doc:"Stable widget identifier"`
	Name  string `json:"name" example:"First widget" doc:"Human-readable widget name"`
	Color string `json:"color,omitempty" example:"blue" doc:"Optional display color"`
}

Widget is the sample typed resource used by the contract spike.

type WidgetStore

type WidgetStore struct {
	// contains filtered or unexported fields
}

WidgetStore is a concurrency-safe in-memory store for the spike handlers.

func NewWidgetStore

func NewWidgetStore(seed []Widget) *WidgetStore

NewWidgetStore creates an in-memory widget store seeded with the provided widgets.

func (*WidgetStore) Create

func (s *WidgetStore) Create(body CreateWidgetBody) Widget

Create stores a widget from the provided request body and returns it.

func (*WidgetStore) List

func (s *WidgetStore) List() []Widget

List returns a copy of the stored widgets.

Jump to

Keyboard shortcuts

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