Skip to content

jay-tank/mocksmith

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mocksmith

Point it at an OpenAPI spec and get a real, running mock API in one command. Zero config, single Go binary, schema-valid responses — for when the backend you need isn't ready, is flaky, or costs money to call.

CI Go License: MIT

Every time I build something that talks to an API that isn't ready yet — or is flaky, or rate-limited, or a paid third party I can't hammer in CI — I end up doing the same tedious thing: hand-rolling a fake version of it. Hardcoded JSON in the app, a throwaway Express/Flask stub, or a pile of WireMock config. I redo it every feature, and the fake always drifts from the real API.

mocksmith kills that busywork. Give it your OpenAPI spec and it stands up a real HTTP server that answers every endpoint with schema-valid data:

mocksmith openapi.json
# mocksmith serving 6 path(s) on :8080
$ curl localhost:8080/pets/7
{
  "id": 1,
  "name": "string",
  "status": "available",
  "email": "user@example.com",
  "createdAt": "2024-01-01T00:00:00Z"
}

Why it's worth a tool (and not a chatbot)

Because it's a running server your app connects to, not an answer you paste. You can't develop a frontend against a chat window. mocksmith is the thing in the other terminal that behaves like the backend — and it drops into CI so your tests never hit a real or paid API.

Install

go install github.com/jay-tank/mocksmith@latest
# or clone + build:
git clone https://github.com/jay-tank/mocksmith.git && cd mocksmith && go build -o mocksmith .

Single static binary, no runtime dependencies.

Use it

mocksmith openapi.json                       # serve on :8080
mocksmith --addr :9000 openapi.json          # pick a port
mocksmith --latency 200ms openapi.json       # simulate a slow backend
mocksmith --error-rate 0.1 openapi.json      # 10% of requests return an injected 500
  • Schema-valid responses — it reads each endpoint's response schema and returns a matching body, honoring $ref, enums (first value), and string format (email, uuid, date-time, …). Explicit examples in the spec are used as-is.
  • Path params/pets/{id} matches /pets/7.
  • Latency & error injection — test your timeouts, retries, and error handling without touching the real service.

See docs/USAGE.md.

Honest scope

  • v0.1 reads JSON OpenAPI 3 specs. That keeps the binary dependency-free. YAML support is the top roadmap item (convert with any yaml→json tool in the meantime).
  • It returns representative data, not a stateful backend — a POST doesn't actually create anything you can GET back later. It's for developing and testing against shapes, not a real database.
  • Realistic AI-generated sample data (names, addresses, believable values instead of "string") is on the roadmap; today's data is deterministic and type/format-based.

There are heavier tools in this space (WireMock, Prism); mocksmith's niche is one Go binary, zero config, instant.

License

MIT — see LICENSE.

About

Zero-config mock API server from an OpenAPI spec — schema-valid responses, latency/error injection, one static Go binary.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages