@darksol/openapi-mock
v0.2.0
Published
Generate and serve mock APIs directly from OpenAPI specs
Downloads
47
Readme
@darksol/openapi-mock
Generate a local mock API server from an OpenAPI 3 spec.
Install
npm i -D @darksol/openapi-mockOr run directly:
npx @darksol/openapi-mock mock:start --spec ./openapi.yamlQuickstart
npm install
npm run mock:start -- --spec ./examples/petstore.yaml --port 4010 --strict --cors --verboseCLI
openapi-mock mock:start \
--spec <path-or-url> \
[--config ./mock.config.yaml] \
[--port 4010] \
[--seed 42] \
[--examples first|random] \
[--strict] \
[--cors] \
[--verbose] \
[--watch] \
[--error-rate 0.0] \
[--error-status 500]
openapi-mock mock:build \
--spec <path-or-url> \
[--out ./.mock-snapshot] \
[--seed 42] \
[--examples first|random]
openapi-mock mock:check \
--spec <path-or-url>Error simulation
- Header
x-mock-error: <status>forces an error status for that request. --error-rateinjects probabilistic errors globally.--configenables per-operation overrides.
Example mock.config.yaml:
operations:
getPet:
errorRate: 0.2
errorStatus: 503Error payload:
{
"error": {
"code": "MOCK_ERROR",
"message": "Simulated error",
"status": 500
}
}Notes
- Prefers response examples first (
example/examples). - Falls back to schema-derived payload generation.
--strictvalidates query/path/header and JSON body.- Chooses success responses in this order:
200,201, first2xx. - UUID schema format uses deterministic seeded UUID generation.
--watchreloads local spec/config updates without restarting.
