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.
Supported Import Formats
Section titled “Supported Import Formats”| Format | File Extension | Auto-Detected | Description |
|---|---|---|---|
| OpenAPI | .yaml, .json | Yes | OpenAPI 3.x and Swagger 2.0 specs |
| Postman | .json | Yes | Postman Collection v2.0 and v2.1 |
| WireMock | directory | Yes | WireMock mapping JSON files |
| Mockoon | .json | Yes | Mockoon environment exports |
| HAR | .har | Yes | HTTP Archive files (from browser DevTools) |
| cURL | — | No | cURL command strings |
| WSDL | .wsdl, .xml | Yes | WSDL 1.1 service definitions (generates SOAP mocks) |
| mockd | .yaml, .json | Yes | mockd’s own config format |
Importing
Section titled “Importing”From OpenAPI Specs
Section titled “From OpenAPI Specs”Import an OpenAPI 3.x or Swagger 2.0 specification. mockd creates one mock per path+method combination, using example values from the spec:
mockd import openapi.yamlParsed 12 mocks from openapi.yaml (format: openapi)Imported 12 mocks to serverVerify what was created:
mockd listIf your spec doesn’t have example values, mockd generates placeholder responses based on the schema types.
From Postman Collections
Section titled “From Postman Collections”Import a Postman Collection (v2.0 or v2.1 format). Export your collection from Postman first (Collection → Export → Collection v2.1):
mockd import my-api.postman_collection.jsonPostman environment variables in requests are preserved as literal strings (e.g., {{baseUrl}}). You may need to adjust paths after import.
From WireMock
Section titled “From WireMock”If you’re migrating from WireMock, point mockd at a directory containing WireMock mapping files:
mockd import ./wiremock-mappings/mockd reads all .json files in the directory and converts WireMock’s request matching and response definitions to mockd format.
From Mockoon Environments
Section titled “From Mockoon Environments”Import a Mockoon environment JSON export:
mockd import environment.jsonmockd 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.
From HAR Files
Section titled “From HAR Files”Record API traffic in your browser (DevTools → Network → Export HAR), then import it:
mockd import recorded-traffic.harThis creates mocks for every request/response pair captured in the HAR file. Useful for quickly creating mocks that match real API behavior.
From WSDL Files
Section titled “From WSDL Files”Import WSDL service definitions to generate SOAP mocks:
mockd import service.wsdlmockd 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):
# Dedicated SOAP import with stateful CRUD heuristicsmockd soap import service.wsdl --statefulFrom cURL Commands
Section titled “From cURL Commands”Convert a cURL command directly into a mock:
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 serverThe --format curl flag is required since cURL commands can’t be auto-detected from file content.
Dry Run
Section titled “Dry Run”Preview what would be imported without actually applying it:
mockd import --dry-run openapi.yamlThis parses and validates the file, showing you what mocks would be created, without changing anything on the server.
Merge vs Replace
Section titled “Merge vs Replace”By default, imported mocks are merged with existing mocks. To replace all existing mocks with the imported ones:
mockd import --replace openapi.yamlExporting
Section titled “Exporting”To mockd YAML
Section titled “To mockd YAML”Export your current mock configuration:
mockd export --format yaml > mocks-backup.yamlTo mockd JSON
Section titled “To mockd JSON”mockd export --format json > mocks-backup.jsonTo OpenAPI
Section titled “To OpenAPI”Generate an OpenAPI 3.0 spec from your current mocks:
mockd export --format openapi > api-spec.yamlThis is useful for documenting the API your mocks represent, or for sharing the spec with frontend teams.
Common Workflows
Section titled “Common Workflows”Migrate from WireMock
Section titled “Migrate from WireMock”# Import WireMock stubsmockd import ./wiremock-mappings/
# Verify everything looks rightmockd list
# Export as mockd config for future usemockd export --format yaml > mockd.yamlMigrate from Mockoon
Section titled “Migrate from Mockoon”# Export your Mockoon environment (File → Export → Current Environment)# Then import into mockdmockd import mockoon-environment.json
# Verify the importmockd list
# Export as mockd config for future usemockd export --format yaml > mockd.yamlCapture Real Traffic → Mock
Section titled “Capture Real Traffic → Mock”# Start the MITM proxy (records traffic to disk)mockd proxy start --port 8888
# Configure your app to use the proxy, then run ithttp_proxy=http://localhost:8888 npm test
# Stop recording with Ctrl+C, then convert to mocksmockd convert -o mocks.yamlImport from Browser
Section titled “Import from Browser”- Open your browser’s DevTools → Network tab
- Use your application normally
- Right-click in the Network tab → Save all as HAR
- Import into mockd:
mockd import network-traffic.harCI/CD Pipeline
Section titled “CI/CD Pipeline”Use import in your test pipeline to load mocks from version-controlled specs:
# In your CI scriptmockd serve &sleep 2mockd import ./test-fixtures/api-spec.yamlpytest tests/Round-Trip: Export → Edit → Import
Section titled “Round-Trip: Export → Edit → Import”# Export current statemockd 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.yamlFormat Detection
Section titled “Format Detection”mockd auto-detects the format of imported files based on content:
- Files with
openapiorswaggerkeys → OpenAPI - Files with
info.schemamatching Postman patterns → Postman Collection - Files with
log.entries→ HAR - Files with
request.url+responseat top level → WireMock - Files with
routesarray +endpointPrefix→ Mockoon environment - Files with
<definitions>or<wsdl:definitions>root elements → WSDL - Files with
mocksarray orversion: "1.0"→ mockd native format - Directories → scanned for WireMock JSON mappings
You can override auto-detection with --format:
mockd import --format openapi ambiguous-file.jsonUsing —json
Section titled “Using —json”Import and export commands support --json for scripting:
mockd import --json openapi.yaml{ "imported": 12, "format": "openapi", "source": "openapi.yaml"}