# Code Deb Mock

A deterministic OpenAPI sandbox for API development, client integration tests and failure simulation. The engine supports JSON OpenAPI 3.0 and 3.1, explicit response examples and bounded schema-derived data.

## Import an API contract

Open [Mock](/docs/platform/mock), select a Code Deb project and paste an OpenAPI JSON specification. The parser accepts up to 80 paths, 150 documented HTTP operations and 90 KB of JSON. It rejects malformed paths, unsafe templates and invalid response codes. YAML is not currently supported; export JSON from your OpenAPI authoring tool.

Example:

```json
{
  "openapi": "3.1.0",
  "info": { "title": "Products sandbox", "version": "1.0.0" },
  "paths": {
    "/products": {
      "get": {
        "responses": {
          "200": {
            "description": "List products",
            "content": { "application/json": { "example": [{ "id": "demo", "name": "Example product" }] } }
          },
          "503": {
            "description": "Temporary failure",
            "content": { "application/json": { "example": { "error": "unavailable" } } }
          }
        }
      }
    }
  }
}
```

The built-in preview evaluates the contract **in the browser**, so it does not contact the customer's API or imply the server sandbox is deployed.

## Hosted sandbox invocation

After saving the spec and creating a project API key with `mock:invoke`:

```bash
curl https://api.codedeb.com/api/developer/v1/invoke/PROJECT_UUID/products \
 -H "Authorization: Bearer $CODEDEB_API_KEY"
```

Use `X-Mock-Status: 503` to request the declared failure response. Undeclared status codes fall back to a documented success response when available. Nonexistent operations return 404; they never proxy unknown requests to a live backend.

## Data generation policy

The mock engine uses examples, defaults, enum options and bounded schema types to generate deterministic values. It does not fetch external `$ref` URLs, execute imported JavaScript or invent personal customer information. The pure `fakeDataset` helper permits 1–50 reproducible sample responses using the declared schema.

## Test conditions

- Validate the intended method/path/status combination, including parameterized routes.
- Test invalid response documents, malformed input and error scenarios.
- Keep sandbox API keys scoped and rotate them independently from production service keys.
- Do not treat fabricated sandbox responses as operational customer data or evidence of a live integration.

## Limitations

The first release supports JSON and local/hosted response simulation only. OpenAPI YAML, OAuth sandbox issuer, custom mock behavior scripts, data persistence for fake resources, team sharing and remote schema resolution are not implemented. Hosted use requires the Code Deb backend and project database migration.

[API Hub](/docs/platform/api-hub) · [CLI](/docs/platform/cli) · [Developer resources](/docs/resources)
