đĨ Import OpenAPI and Postman collections
LiveMock can turn an API description into a set of expectations, so you do not have to re-create every endpoint by hand.
Supported formatsâ
| Source | Versions |
|---|---|
| OpenAPI | 3.0 / 3.1 (JSON or YAML) |
| Swagger | 2.0 (JSON or YAML, converted to OpenAPI 3 first) |
| Postman Collection | v2.0 / v2.1 (JSON) |
The format is detected automatically. A file that is none of the above is rejected with a message.
Importingâ
Imported expectations are appended to the currently open project. To start from a clean slate, either import into a new project or delete the existing expectations first.
Upload the file (click or drag it into the drop area) and choose the options:
| Option | Default | Effect |
|---|---|---|
| Path prefix | off | When on, the path prefix of the first servers entry in an OpenAPI document is kept in front of every path. The host is always ignored; servers entries that still contain an unresolved {variable} are skipped. |
| Overwrite existing | off | When on, an imported operation replaces an existing expectation with the same method and path. When off, such operations are skipped. |
Then click Import. The result dialog lists how many expectations were created, overwritten and skipped, plus the reason for every entry that could not be imported.
What is generatedâ
One expectation per OpenAPI operationâ
- Matchers - exactly two:
methodandpath.- A path without parameters becomes a
path ISmatcher, for example/users. - A path with parameters becomes a
path MATCH_GLOBmatcher, where each{param}is replaced by*, for example/users/{id}becomes/users/*.
- A path without parameters becomes a
- Status and body - the first 2xx response is used, preferring
200, then201; when there is no 2xx,defaultis used (treated as 200), otherwise the first declared response. - Body source, in order of preference: the first entry of
examples, thenexample, then a value sampled from theschema(formats such asdate-time,email,uuid,uriandhostnameproduce deterministic samples), and finally{}. - Response type - a JSON media type becomes a JSON response with the value pretty-printed; any other media type becomes plain text. An operation without a body (for example a 204) gets an empty JSON response.
- Name -
summary, thenoperationId, thenMETHOD /path. - Other fields - the expectation is active, with delay
0and priority0. Deprecated operations are imported like any other.
One expectation per Postman requestâ
- Folders are flattened; disabled items and non-HTTP items (websocket, gRPC, âĻ) are skipped and reported.
- Method comes from the request (default
GET). - Path is the pathname of the URL, so the host and the query string are dropped. Collection variables are resolved
with their default values. A path that still contains an unresolved
{{variable}}is skipped. - Placeholders such as
:idbecome*, and a path with*usesMATCH_GLOB(same rule as OpenAPI). - Status and body come from the first saved 2xx example of the request; without a saved example you get
200and{}. JSON previews and parseable bodies become JSON responses, everything else plain text.
Duplicatesâ
An import is considered a duplicate when the method value and the path matcher value already exist in the project.
With Overwrite existing the existing expectation keeps its id and its timing and state, while its name, matchers
and actions are replaced. A failure on one operation does not roll back the rest of the import.