Skip to Content
Mock ServerDocuments and base paths

Documents and base paths

A spec-based mock server serves one or more API documents from one commit of your repository. Each document is mounted under a base path, so several APIs can live on one mock server without their routes colliding.

https://petstore-sandbox.mockserver.apigit.com ├── /pets/v3 openapi/petstore.yaml ├── /orders/v2 openapi/orders.yaml └── /graphql schema.graphql

Supported documents

  • OpenAPI 3.0.x and 3.1.x, in YAML or JSON
  • Swagger 2.0, converted automatically
  • GraphQL SDL: a complete schema in a .graphql or .gql file with a query root
  • Split documents: the local files a document references with $ref are collected with it, including files in other folders of the repository

A remote $ref (one with a URL) is refused at publish, because the mock fetches nothing from the internet. Inline or vendor those definitions into the repository.

GraphQL schemas

GraphQL schemas answer HTTP queries and mutations at their base path, defaulting to /graphql, and can share a hosted mock with OpenAPI documents. See GraphQL mock servers for a complete example and limits. AsyncAPI documents are not mock inputs.

Base paths

For OpenAPI, the default base path is the path part of the document’s first servers URL, for example /orders/v2 for https://api.acme.example/orders/v2. An OpenAPI document with no servers, or a URL with no path, defaults to /. A GraphQL schema defaults to /graphql and answers at that path itself.

You can set any other base path, even for a single document. The document’s own servers path then plays no part in routing.

A base path:

  • starts with /
  • uses plain segments of letters, digits, ., _, ~ and -, with no {parameters}
  • has no trailing slash, except / itself
  • has at most 128 characters
  • is unique within the mock server
  • is not under /apigit-mockserver-, which is reserved for the built-in routes

How a request finds its document

The longest base path that matches whole path segments wins. That base path is removed, and the rest of the path is matched against the document’s operations.

Base pathsRequestServed by
/api, /api/v2/api/v2/pets/api/v2, as /pets
/api, /api/v2/api/v2x/api, as /v2x
/petstore/petNothing: 404 no-base-path, which lists the base paths
/any pathThe document at /

Documents never share a route table, so two documents can both declare /pets under different base paths.

Change documents after publishing

Open the mock server, choose Setting, and use Documents & Base Paths. The section lists OpenAPI files and GraphQL schemas at the commit the mock serves.

Documents and base paths on a mock server's Setting page

  • Check a document to add it, or uncheck one to remove it.
  • Edit a base path.
  • Turn OpenAPI validation checks on or off. These switches do not control GraphQL query validation.

Click Save documents. Changes apply without a republish, and the mock server keeps its URL and commit.

List what a mock serves

GET /apigit-mockserver-routes returns every document with its base path and operations:

curl https://petstore-sandbox.mockserver.apigit.com/apigit-mockserver-routes
{ "message": "Mock Server routes list", "routes": ["GET /orders/v2/orders", "..."], "mounts": [ { "kind": "openapi", "source": "openapi/orders.yaml", "base": "/orders/v2", "operations": [ { "method": "GET", "path": "/orders/v2/orders", "operationId": "listOrders" } ] } ] }

Limits

LimitValue
Documents per mock server1 on Free, 10 on Team and Enterprise
Files of a whole mock server200
Size of a whole mock server1,900,000 bytes uncompressed, per file and in total
OpenAPI operations of a whole mock server1000
Each GraphQL schema fileAt most 1 MiB, within the total file budget
Requests per second, per mock server60
Each documentMounted once per mock server

Mock server calls count toward your plan’s monthly quota, once per request.

Hosted spec-based mocks support OpenAPI and GraphQL. Local apigit mock serve runs both as well (a GraphQL schema since CLI 0.7.0). AsyncAPI mocking is not supported.

Last updated on