Skip to content

Import & Export

mockd can import mock definitions from formats you probably already have — OpenAPI specs, Postman collections, WireMock stubs, Mockoon environments, HAR files from your browser, and even cURL commands.

FormatFile ExtensionAuto-DetectedDescription
OpenAPI.yaml, .jsonYesOpenAPI 3.x and Swagger 2.0 specs
Postman.jsonYesPostman Collection v2.0 and v2.1
WireMockdirectoryYesWireMock mapping JSON files
Mockoon.jsonYesMockoon environment exports
HAR.harYesHTTP Archive files (from browser DevTools)
cURLNocURL command strings
WSDL.wsdl, .xmlYesWSDL 1.1 service definitions (generates SOAP mocks)
mockd.yaml, .jsonYesmockd’s own config format

Import an OpenAPI 3.x or Swagger 2.0 specification. mockd creates one mock per path+method combination, using example values from the spec:

Terminal window
mockd import openapi.yaml
Parsed 12 mocks from openapi.yaml (format: openapi)
Imported 12 mocks to server

Verify what was created:

Terminal window
mockd list

If your spec doesn’t have example values, mockd generates placeholder responses based on the schema types.

Import a Postman Collection (v2.0 or v2.1 format). Export your collection from Postman first (Collection → Export → Collection v2.1):

Terminal window
mockd import my-api.postman_collection.json

Postman environment variables in requests are preserved as literal strings (e.g., {{baseUrl}}). You may need to adjust paths after import.

If you’re migrating from WireMock, point mockd at a directory containing WireMock mapping files:

Terminal window
mockd import ./wiremock-mappings/

mockd reads all .json files in the directory and converts WireMock’s request matching and response definitions to mockd format.

Import a Mockoon environment JSON export:

Terminal window
mockd import environment.json

mockd converts Mockoon routes (including CRUD resources), response templates, path parameters (:id{id}), and Handlebars helpers ({{faker 'person.firstName'}}{{faker.firstName}}). Disabled routes are skipped, and per-response + global latency is preserved.

Record API traffic in your browser (DevTools → Network → Export HAR), then import it:

Terminal window
mockd import recorded-traffic.har

This creates mocks for every request/response pair captured in the HAR file. Useful for quickly creating mocks that match real API behavior.

Import WSDL service definitions to generate SOAP mocks:

Terminal window
mockd import service.wsdl

mockd parses the WSDL operations and generates SOAP mock endpoints. Use --format wsdl if auto-detection doesn’t work, or use the dedicated mockd soap import command for more control (e.g., --stateful to auto-detect CRUD patterns):

Terminal window
# Dedicated SOAP import with stateful CRUD heuristics
mockd soap import service.wsdl --stateful

Convert a cURL command directly into a mock:

Terminal window
mockd import --format curl 'curl -X POST https://api.example.com/orders -H "Content-Type: application/json" -d {"item":"widget","qty":5}'
Parsed 1 mocks from curl command (format: curl)
Imported 1 mocks to server

The --format curl flag is required since cURL commands can’t be auto-detected from file content.

Preview what would be imported without actually applying it:

Terminal window
mockd import --dry-run openapi.yaml

This parses and validates the file, showing you what mocks would be created, without changing anything on the server.

By default, imported mocks are merged with existing mocks. To replace all existing mocks with the imported ones:

Terminal window
mockd import --replace openapi.yaml

Export your current mock configuration:

Terminal window
mockd export --format yaml > mocks-backup.yaml
Terminal window
mockd export --format json > mocks-backup.json

Generate an OpenAPI 3.0 spec from your current mocks:

Terminal window
mockd export --format openapi > api-spec.yaml

This is useful for documenting the API your mocks represent, or for sharing the spec with frontend teams.

Terminal window
# Import WireMock stubs
mockd import ./wiremock-mappings/
# Verify everything looks right
mockd list
# Export as mockd config for future use
mockd export --format yaml > mockd.yaml
Terminal window
# Export your Mockoon environment (File → Export → Current Environment)
# Then import into mockd
mockd import mockoon-environment.json
# Verify the import
mockd list
# Export as mockd config for future use
mockd export --format yaml > mockd.yaml
Terminal window
# Start the MITM proxy (records traffic to disk)
mockd proxy start --port 8888
# Configure your app to use the proxy, then run it
http_proxy=http://localhost:8888 npm test
# Stop recording with Ctrl+C, then convert to mocks
mockd convert -o mocks.yaml
  1. Open your browser’s DevTools → Network tab
  2. Use your application normally
  3. Right-click in the Network tab → Save all as HAR
  4. Import into mockd:
Terminal window
mockd import network-traffic.har

Use import in your test pipeline to load mocks from version-controlled specs:

Terminal window
# In your CI script
mockd serve &
sleep 2
mockd import ./test-fixtures/api-spec.yaml
pytest tests/
Terminal window
# Export current state
mockd export --format yaml > mocks.yaml
# Edit the file (add mocks, change responses, etc.)
vim mocks.yaml
# Re-import (replace mode to get a clean state)
mockd import --replace mocks.yaml

mockd auto-detects the format of imported files based on content:

  • Files with openapi or swagger keys → OpenAPI
  • Files with info.schema matching Postman patterns → Postman Collection
  • Files with log.entries → HAR
  • Files with request.url + response at top level → WireMock
  • Files with routes array + endpointPrefix → Mockoon environment
  • Files with <definitions> or <wsdl:definitions> root elements → WSDL
  • Files with mocks array or version: "1.0" → mockd native format
  • Directories → scanned for WireMock JSON mappings

You can override auto-detection with --format:

Terminal window
mockd import --format openapi ambiguous-file.json

Import and export commands support --json for scripting:

Terminal window
mockd import --json openapi.yaml
{
"imported": 12,
"format": "openapi",
"source": "openapi.yaml"
}