mock

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package mock turns an OpenAPI spec into a running, STATEFUL mock server:

optictrace mock -spec openapi.yaml -listen :7070

Three layers, in order of preference per request:

  1. State: collection/item routes (POST /cart then GET /cart/{id} returns what you posted) backed by an in-memory store. This is what makes the mock believable for frontend flows — state, not canned JSON.
  2. AI (optional, -ai + ANTHROPIC_API_KEY): non-CRUD operations ask Claude for a context-aware response conforming to the response schema.
  3. Deterministic generation: realistic values from schema + field-name heuristics (emails look like emails, prices look like prices).

Any failure in layer 2 falls back to layer 3 — the mock never depends on network access to function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(s *spec.Spec, sc *spec.Schema, fieldName string) any

Generate produces a realistic value for a schema; fieldName drives the heuristics ("email" fields get emails).

Types

type Options

type Options struct {
	AI bool // enable Claude-generated responses when ANTHROPIC_API_KEY is set
}

type Server

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

func New

func New(s *spec.Spec, logger *slog.Logger, opts Options) *Server

func (*Server) AIEnabled

func (s *Server) AIEnabled() bool

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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