Getting Started
Import & Export via OpenAPI
Already have a spec for the API you're mocking? Skip typing out routes by hand — import an OpenAPI 3.x document (JSON or YAML) and MockBase turns every operation into a route automatically. Going the other way, export any mock as a spec other tools can open.
Importing a spec
From the Dashboard, choose Import OpenAPI instead of creating a mock manually, and paste in your spec. You can also import into a mock you already have, to add more routes to it later without starting over.
For each operation, MockBase picks a response like this:
- The lowest 2xx status the operation declares becomes the route's status code (falling back to
default, then whatever's listed first, if there's no 2xx). - The response body comes from the operation's own
example, or its firstexamplesentry, when either is present. - Otherwise, MockBase synthesizes a body from the response schema — objects and arrays are rebuilt field by field (one item deep for arrays), and each scalar gets a placeholder matching its declared type and format: an ISO date-time for
format: date-time, a UUID forformat: uuid, an address-shaped string forformat: email, and so on. Internal$refreferences (#/components/...) are resolved; references to another file are not. - A status code your spec declares that MockBase doesn't support (see the list in Quickstart) falls back to
200for that route rather than failing the whole import.
If the spec can't be parsed as JSON or YAML, or declares no path operations at all, the import is rejected with an explanation instead of creating an empty mock.
Exporting a mock
Open a mock and choose Export, or call:
GET /api/v1/mocks/<mock_id>/export?format=json
GET /api/v1/mocks/<mock_id>/export?format=yaml
to download it as an OpenAPI 3.0 document. Every route becomes a path and operation, with its configured status code and response body as that operation's example response; any {name} segment in the path is declared as a required path parameter. The document's servers entry points straight at the mock's own public URL, so it opens correctly in Swagger UI, Postman, or a code generator without any editing first.
The export reflects the routes you've configured, not the live behavior layered on top of them — conditional matching, dynamic templates, chaos, and stateful CRUD aren't simulated in the document, since there's no single "example response" for a route that behaves differently request to request.
Trial limits still apply
Importing obeys the same anonymous limits as creating a mock by hand. If your spec would generate more routes than your plan allows, MockBase doesn't reject it — it creates the mock with as many routes as fit and reports how many it dropped via an X-Mockbase-Routes-Dropped response header, so you always get something to start from.