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

1Upload Spec

Paste YAML/JSON or upload a file. Supports OpenAPI 3.x and Swagger 2.0.

2Parse & Store

Spec is versioned and stored in R2. Endpoints, schemas, and error responses are extracted.

3Generate Data

Resources are auto-detected. Use Faker.js or AI to seed realistic mock data.

4Serve Requests

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.

petstore.yamlyaml
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.

GET
/pet

Lists all pets from mock data with pagination

GET
/pet/findByStatus?status=available

Smart filter — queries mock_data JSONB for matching records

GET
/pet/3

Parameterized route — finds pet with id=3

POST
/pet

Creates a new pet in mock_data

DELETE
/pet/3

Deletes 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.

terminalbash
# 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/42

The 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.

response.jsonjson
// 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.

terminalbash
# 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
  }'
response.jsonjson
{
  "message": "Spec imported successfully",
  "specId": "abc-123",
  "version": 1,
  "endpoints": 12,
  "resources": ["pet", "store", "user"],
  "skipped": ["login", "logout"]
}

// API Reference

POST/api/mock-apis/:id/import
GET/api/mock-apis/:id/specs
GET/api/mock-apis/:id/specs/:specId
POST/api/mock-apis/:id/specs/:specId/activate
DELETE/api/mock-apis/:id/specs?specId=:specId
GET/api/mock-apis/:id/endpoints