OpenAPI Mock Generator (MSW, json-server and Prism)
Mock an API before it exists: MSW handlers, json-server data and Prism examples.
Try before you buy.
- Free preview: the list of files with their sizes, and the first lines of each file (up to 20).
- Locked until you unlock it: download and copy.
- Unlock: Premium pass, ₹799 for 30 days or ₹249 for 1 week, a one-time payment that never renews. Unlock: Premium pass, $19.99 for 30 days or $7.99 for 1 week, a one-time payment that never renews.
Ways to unlock shows how to get the full result.
Printing this result is locked in the free preview.
OpenAPI 3.0, 3.1, 3.2 or Swagger 2.0, in YAML or JSON. A split description: open or drop all its files.
Problems
What to mock
The same seed gives the same data.
Your mock files
Locked in the free preview. Opens the ways to unlock this result.
Locked in the free preview. Batch runs unlock with a pass.
Locked in the free preview. Query results unlock with a pass.
About the OpenAPI Mock Generator (MSW, json-server and Prism)
Paste or open an OpenAPI 3.0, 3.1 or 3.2 description — or a Swagger 2.0 one — and get the files a front-end or test team needs to work before the API exists: Mock Service Worker request handlers in TypeScript, a json-server db.json with a collection for each list endpoint, a copy of the description with an example on every response for Prism, and example payloads for each response code, with a README on how to run each. With a Premium pass, download them all as one ZIP.
The data is made from the schemas: formats, enums, minimum and maximum, lengths, patterns, item counts and required properties are respected, and names, e-mail addresses, cities, prices and dates look real. The description’s own examples are used first. Choose the operations, the status codes, how many items lists get, and a seed for the same data every time. MySmartCoPilot hosts no mock endpoint: the files run on your own machine.
Without a pass the result is a free preview: the list of files and the first lines of each. The whole files, copying them and the ZIP unlock with a Premium pass.
How to use it
- Paste the description, open the file, or drop it on the box (a split description: all its files at once, or the folder).
- Choose the operations to mock, whether each handler knows every documented status or only the success response, and how many items lists get.
- Pick the files to make, the MSW version and, if your app calls another address, the base URL.
- Press Make the mocks, read the files and, with a Premium pass or after unlocking this result, download the ZIP. The README in it has the commands to run each mock.
Examples
GET /events/{eventId} — responses 200 (Event) and 404 (Problem)http.get(`${BASE_URL}/events/:eventId`, ({ request }) => {
switch (preferredCode(request)) {
case 404:
return HttpResponse.json({ "title": …, "status": 404 }, { status: 404 });
default:
return HttpResponse.json({ "id": "7d3c2a1e-…", "name": "Monsoon Jazz Night", … }, { status: 200 });
}
}),Send the header Prefer: code=404 to get the 404 — the same header Prism reads, so the front end works with either mock.
GET /events returns { items: Event[], page }, list size 3db.json: { "events": [ { "id": "…", "name": "…", … }, … 3 items ] }
npx json-server json-server/db.json → GET /events, GET /events/:id, POST /events …Common uses
- Building a front end before the back end is ready, against the contract you agreed on.
- Tests that need realistic responses, including error responses, without a running server.
- Demos and prototypes with believable data from the API description.
- Checking that a description is complete enough to mock: operations without responses or schemas show up at once.
Mock Service Worker
mocks/handlers.ts has one handler per operation with the response written in, and mocks/browser.ts and mocks/node.ts start them with setupWorker and setupServer, as the Mock Service Worker documentation describes. MSW 3 imports http and HttpResponse from msw/http; choose MSW 2 for msw. Path parameters become :name, JSON bodies HttpResponse.json(), text and XML their own helpers, and a response without a body new HttpResponse(null). With every documented status, a handler returns the success response unless the request asks for another with Prefer: code=….
json-server
json-server turns a db.json into a REST server: each array is a collection with GET, POST, PUT, PATCH and DELETE routes, each object a single resource. Every GET endpoint without path parameters becomes one, from the list in its response (an array, or the array inside an items, data or results object). json-server 1.x treats every id as a string, so ids are written as strings, and items without an id get one. It serves paths without the API’s base path; routes.json adds it back for json-server 0.17. Nested paths such as /users/{id}/orders are not routes json-server has.
Prism and the example payloads
Prism mocks straight from a description and checks every request against it. The copy in prism/ is your description with a generated example named generated on every JSON response that had none (your own examples are kept), so prism mock returns believable data; choose a response with Prefer: code=404 or Prefer: example=generated. examples/ holds each response body and request body as a file for tests and fixtures.
How the data is made
Values follow the schema first: const and enum values, formats (date-time, date, email, uri, uuid, ipv4 …), patterns (each value is checked against the pattern), minimum / maximum with exclusive limits and multipleOf, lengths, item counts and unique items, allOf merged and the first oneOf alternative. Then the property’s name picks a believable value — firstName, email, city, price, createdAt, currency — made with the open-source Faker library and a seed, so the same seed gives the same data. Links and e-mail addresses use example.com, example.org and example.net, the domains reserved for examples. Read-only properties are left out of request bodies and write-only ones out of responses; a schema that contains itself stops after one level.
Limitations
- One success response per handler is the default answer; other documented statuses come only when the request asks for them.
- Binary bodies (files, images, PDFs) are not generated: the mock answers with the status and content type only.
- MSW has no TRACE or QUERY handler, so such operations are left out of handlers.ts.
- Patterns that use constructs the data library cannot produce (groups with alternatives, look-arounds, back-references) fall back to the description’s example when it matches, otherwise to a value that may not match.
- Webhooks are not mocked: they are requests your server receives, not responses.
Privacy
On this device: nothing is sent
Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.
Frequently asked questions
What do I get without a pass?
Without a pass, OpenAPI Mock Generator (MSW, json-server and Prism) shows the list of files with their sizes, and the first lines of each file (up to 20). Until you unlock it, the result can’t be downloaded or copied. A Premium or Ultimate pass, a one-time payment that never renews, unlocks the full result. The pricing page lists the passes and their prices.
Is my API description uploaded?
No. Reading the description and making the files happen in your browser, in a background worker; the page works offline once loaded. The mocks you download run on your own machine.
Does MySmartCoPilot host a mock server for me?
No. Hosted mock endpoints would let anyone send traffic through them, so the files run locally instead: MSW inside your app or tests, json-server and Prism with one command each.
Which should I use: MSW, json-server or Prism?
MSW intercepts requests inside the browser or Node.js, so no server runs and tests stay fast. json-server is a real server whose data changes when you POST, PATCH or DELETE. Prism follows the description exactly and rejects requests that do not match it, which is good for checking the client.
Can I get the same data again?
Yes. The data depends only on the description, the options and the seed: keep the seed and you get the same files; press New data for another set.
How do I make an endpoint return an error?
Choose Every documented status, then send Prefer: code=404 (or any documented code) with the request. With Prism the same header works, so front-end code that tests error states works with both.