Import OpenAPI / Swagger Spec — Instant Mock Server
Upload an OpenAPI 3.x or Swagger 2.0 spec and get a fully-functional mock server in seconds. Every path, method, parameter, and error response is parsed—including parameterized routes like /pet/{petId} and smart query filters like /pet/findByStatus?status=available.
// How Import Works
Paste YAML/JSON or upload a file. Supports OpenAPI 3.x and Swagger 2.0.
Spec is versioned and stored in R2. Endpoints, schemas, and error responses are extracted.
Resources are auto-detected. Use Faker.js or AI to seed realistic mock data.
Smart router matches paths, methods, and query params. Returns spec-defined responses.
// Example: Petstore Spec
Import the classic Petstore spec. Every endpoint is automatically routed, including parameterized paths and query-based filters.
openapi: "3.0.3"
info:
title: Petstore
version: "1.0"
paths:
/pet:
get:
summary: List all pets
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Pet"
post:
summary: Add a new pet
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
"405":
description: Invalid input
/pet/{petId}:
get:
summary: Find pet by ID
parameters:
- name: petId
in: path
required: true
schema:
type: integer
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
"404":
description: Pet not found
delete:
summary: Delete a pet
responses:
"400":
description: Invalid pet value
/pet/findByStatus:
get:
summary: Find pets by status
parameters:
- name: status
in: query
schema:
type: string
enum: [available, pending, sold]
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Pet"
components:
schemas:
Pet:
type: object
properties:
id:
type: integer
name:
type: string
status:
type: string
enum: [available, pending, sold]
category:
type: object
properties:
id:
type: integer
name:
type: string// Smart Routing
The spec router resolves endpoints using a priority chain: exact match → parameterized regex → resource CRUD fallback → 404.
/petLists all pets from mock data with pagination
/pet/findByStatus?status=availableSmart filter — queries mock_data JSONB for matching records
/pet/3Parameterized route — finds pet with id=3
/petCreates a new pet in mock_data
/pet/3Deletes pet with id=3, returns spec-defined error if applicable
// Smart Query Filters
Endpoints like /pet/findByStatus are automatically recognized as filter endpoints. Query parameters are mapped to JSONB field lookups in mock data.
# Replace {projectId} and {base-path} with your project values
# Find by single field
curl https://moqapi.dev/api/invoke/{projectId}/petstore/pet/findByStatus?status=available
# Find by multiple fields
curl https://moqapi.dev/api/invoke/{projectId}/petstore/pet/findByTags?tags=friendly
# Parameterized path
curl https://moqapi.dev/api/invoke/{projectId}/petstore/pet/42The router strips the "findBy" prefix and checks if query param names match fields in your mock data. If they do, it filters using Postgres JSONB containment operators.
// Spec-Defined Error Responses
If your spec defines 4xx/5xx responses, they're stored and can be triggered. For example, GET /pet/999 on a missing ID returns the spec's 404 response with description.
// GET /pet/999 → 404
{
"error": "Pet not found",
"status": 404,
"spec_defined": true
}
// DELETE /pet/invalid → 400
{
"error": "Invalid pet value",
"status": 400,
"spec_defined": true
}// Import via API
You can also import specs programmatically using the management API.
# Import a spec from file
curl -X POST https://moqapi.dev/api/mock-apis/<mockApiId>/import \
-H "Content-Type: application/json" \
-d '{
"spec": "<your-yaml-or-json-string>",
"format": "yaml",
"generateData": true,
"recordCount": 25
}'{
"message": "Spec imported successfully",
"specId": "abc-123",
"version": 1,
"endpoints": 12,
"resources": ["pet", "store", "user"],
"skipped": ["login", "logout"]
}// API Reference
/api/mock-apis/:id/import/api/mock-apis/:id/specs/api/mock-apis/:id/specs/:specId/api/mock-apis/:id/specs/:specId/activate/api/mock-apis/:id/specs?specId=:specId/api/mock-apis/:id/endpoints