بنقرة واحدة
mock-server
// Build, customize, and troubleshoot OpenAPI mock servers with @scalar/mock-server, including x-handler, x-seed, authentication, and Docker.
// Build, customize, and troubleshoot OpenAPI mock servers with @scalar/mock-server, including x-handler, x-seed, authentication, and Docker.
Minimal starter runbook for cloud agents to install dependencies, run packages, execute tests, and troubleshoot the Scalar monorepo quickly.
Skill for writing and updating scalar.config.json — Scalar Docs configuration reference for users and LLMs.
Use consistent OpenAPI terminology and definitions when writing documentation, educational material, and tooling guidance.
Write clear, maintainable Vitest and Playwright tests with precise assertions, consistent structure, and strong behavioral coverage.
Write clear, predictable TypeScript and Vue TypeScript code with strong typing, maintainability, and consistent documentation conventions.
Build Vue 3 components with TypeScript and Tailwind using clean structure, composable logic, accessibility, and maintainable patterns.
| name | mock-server |
| description | Build, customize, and troubleshoot OpenAPI mock servers with @scalar/mock-server, including x-handler, x-seed, authentication, and Docker. |
Reference for implementing and debugging mock APIs with @scalar/mock-server.
Use this when you need realistic API responses from an OpenAPI description document, custom request behavior, seeded data, or Docker-based mock environments.
@scalar/mock-server>=22)createMockServer(options)x-handler): https://scalar.com/tools/mock-server/custom-request-handlerx-seed): https://scalar.com/tools/mock-server/data-seedingFastest way to run a mock server from a local OpenAPI description:
npx @scalar/cli document mock openapi.json --watch
Programmatic setup:
import { serve } from '@hono/node-server'
import { createMockServer } from '@scalar/mock-server'
const app = await createMockServer({
document: './openapi.yaml',
onRequest({ context, operation }) {
console.log(context.req.method, context.req.path, operation.operationId)
},
})
serve({ fetch: app.fetch, port: 3000 })
createMockServer() OptionsAt least one of the following is required:
document: OpenAPI description document as URL, file path, or objectspecification: deprecated alias for documentOptional:
onRequest({ context, operation }): callback before each request is processedWhen the server starts, it:
x-seed extensions (idempotent: only when collection is empty)./openapi.json/openapi.yamlx-handlerUse x-handler in an operation for dynamic behavior instead of static examples.
Helpers available in x-handler:
store for in-memory persistence (list, get, create, update, delete, clear)faker for generated test datareq for request data (body, params, query, headers)res for response examples by status code (res['200'], res['404'], ...)Status behavior:
store.get() / store.update() => 200 when found, 404 when not foundstore.create() => 201store.delete() => 204 when deleted, 404 when not foundstore.list() => 200null/undefined triggers 404 (uses responses.404 example/schema when provided)x-seedUse x-seed on components.schemas.<SchemaName> to seed initial data at startup.
Helpers available in x-seed:
seed.count(n, factory)seed(array)seed(factory) (single item shortcut)faker, store, and schemaKey rule: the schema key name is used as the collection name.
Run the Docker image:
docker run -p 3000:3000 scalarapi/mock-server --url https://api.example.com/openapi.yaml
Document source priority (high to low):
--url <URL>OPENAPI_DOCUMENTOPENAPI_DOCUMENT_URL/docs volume-mounted filesUseful routes:
/scalar/openapi.json, /openapi.yamldocument, --url, env var, or mounted file).x-seed exists on schema keys and the collection was empty on startup.securitySchemes and request credentials.x-handler runtime errors (mock server returns 500 with handler error details).