Skip to main content

Mock

Start an HTTP mock server from an OMG API definition. Responses are generated from the endpoint schemas. The process stays running until stopped with Ctrl+C.

Usage​

omg mock <input> [options]
ArgumentDescription
inputPath to the root API definition, such as my-api/api.omg.md

Options​

OptionDefaultDescription
-p, --port <port>3000Port to listen on
-b, --base-path <path>No prefixPrefix endpoint paths, for example /api/v1
-d, --delay <ms>0Add a response delay in milliseconds
-s, --seed <seed>UnsetSet the random seed; see the current determinism limitation below
--no-corsCORS enabledDisable CORS response headers
-q, --quietRequest logging enabledDisable request logs; startup messages still appear
--simpleVague generatorUse the simple generator instead of Vague
-w, --watchOffWatch .omg.md files under the API directory and restart after changes
-h, --help—Show command help

Examples​

# Default server at http://localhost:3000
omg mock my-api/api.omg.md

# Prefix endpoint paths and seed generated responses
omg mock my-api/api.omg.md --port 8080 --base-path /api/v1 --seed 42

# Delayed responses without CORS headers or request logs
omg mock my-api/api.omg.md --delay 250 --no-cors --quiet

# Use the simple generator
omg mock my-api/api.omg.md --simple

# Restart after specification edits
omg mock my-api/api.omg.md --watch

The default Vague generator supports the @vague annotation, which supplies an expression for a field's mock value. --simple selects the alternative generator.

Watch mode​

--watch observes .omg.md files recursively under the input API file's directory, including endpoints and partials. Changes, additions, and removals restart the server after a short debounce. Hidden paths and other file types are ignored.

Restarts wait for active responses to finish. Edits received during a restart are processed sequentially, and subsequent requests use the updated specification.

The Watching for changes... message appears when the initial directory scan is complete. Ctrl+C closes the watcher and stops the server.

Current limitations​

Named response types​

The default Vague generator can return {"value": null} for a named top-level response schema instead of the declared object. --simple preserves the object shape in this case. Importing an OpenAPI document with --inline also avoids the named reference. This is tracked in #134.

Seeded Faker fields​

The same --seed can produce different Faker-backed field values after a server restart, even when other generated values repeat. Complete response determinism in Vague mode is tracked in #135.

For contract testing, see omg test. For static HTML output, see omg docs.