Create a mock API from an OpenAPI spec
An OpenAPI file already describes every endpoint of an API: its paths, methods, parameters and the shape of its responses. That is most of what a mock needs, so there is no reason to type it all again. Zyvra reads an OpenAPI 3.x spec (YAML or JSON) and turns it into a running mock API.
Import the spec into a mock service
- Install Zyvra and start a project (
zyvra init my-project, thenzyvra up). See the quick start. - Create a mock service: it listens on its own local port.
- Open it and choose Import OpenAPI. Choose the file, or paste the text.
- Zyvra lists every operation. Tick the ones you want. Each becomes an endpoint with example responses taken from the spec.
- Call it:
curl http://127.0.0.1:8080/pets(with the port you chose) returns what the spec’s example says it should.
Your app now has a working API to build against, before the real one is deployed, and the mock is a plain file in your project that you can keep in Git.
Make it behave, not just answer
A mock generated from a spec answers with the spec’s examples. From there you can add what a spec cannot say:
- Rules that answer differently by path, query, headers or body: a missing pet is a 404, a large amount goes to review.
- Scenarios such as an empty list or a server error, switched with one click.
- Stored state, so a created pet can be read back.
- Failures on purpose: latency, errors and rate limits.
When the spec changes
Specs change. Import the new version into the same service. Zyvra marks the routes that are already there, and you choose what happens to them: leave them as they are (the default), or add only the responses they are missing. Rules, faults, edited responses and the active scenario are never touched, so the work you added on top survives.
Check the mock against the spec
Add the spec to the project under API Specs to keep it with the code: it is stored as a plain file under specs/ and goes to Git. Zyvra shows each operation in full, with its parameters, request body and response schemas, and lets you edit the file with problems marked as you type.
In the API Client, every response then says whether it matches the spec that describes its request: the status, the content type and, for JSON, the body against the schema. That catches a mock, or a real service, that has drifted from the contract.
Other ways to start
zyvra import openapi spec.yamlturns a spec into a collection of requests, one per operation, ready to send and to add checks to.- A collection can be turned into a mock service, and a mock service back into a spec: see Importing and API Specs.
Read more about running mocks in Mock API server.
Questions people ask
Can I generate a mock server from an OpenAPI file?
Yes. In Zyvra, open a mock service and choose Import OpenAPI. It lists every operation in the spec and creates an endpoint for each one you tick, with example responses taken from the spec.
Does Zyvra support Swagger 2.0 files?
Zyvra reads OpenAPI 3.x in YAML or JSON. A Swagger 2.0 file needs converting to OpenAPI 3 first.
What happens when the spec changes?
Import the new version into the same service. Routes that already exist are marked, and you choose to leave them alone or to add only the responses they are missing. Your rules, faults, edited responses and active scenario are not touched.
Can I check that my mock matches the spec?
Yes. Add the spec to the project under API Specs. Every response in the API Client is then checked against the spec that describes its request, for a mock and for a real service alike.