Keeping state
By default every call is answered on its own: a POST returns a made-up record, and the next GET doesn’t know about it. With --stateful the mock keeps data, like the real server would:
npx rapidoc mock openapi.yaml --stateful- It works out the data model from the spec. Paths such as
/petsand/pets/{petId}that share a schema become one resource, with its key and its links to other resources. How it works has the details. - It starts with data. Each resource gets 10 records (
--rows). See Seed data. - Writes are kept. A create stores a record, an update or delete changes it, and reads and lists return what is stored.
- Lists filter and page. Query parameters that match a field filter the list;
limit,offsetandpagepage it, and a count beside the records gets the real total. - Records stay under their parent. A comment created at
/articles/{slug}/commentsis listed and found under that article only, whether or not it has a field for the article. - Responses keep the spec’s shape. A record goes where the response schema puts it, such as inside
datanext to arequest_id. - Everything else answers as before. An operation that fits no resource (a login, a search, a file upload) gets its example or generated data.
The data lives in memory and starts fresh on every run.
What a new record gets
Section titled “What a new record gets”Fields the caller can’t send, or left out, are filled the way a server would: an id, timestamps set to now, lists empty, counts at zero. A key the path expects as a number is a number.
When a record is missing
Section titled “When a record is missing”A read, update or delete of a record that isn’t there returns the spec’s own 404 response when it documents one.
- Sessions: a copy of the data per test.
- API styles: what works with no configuration.
- Correcting the mock: when it reads your spec wrongly.