Import OpenAPI examples

Start a mock library from the response examples in your API description. Make one request concrete, inspect the generated fixture, and test your client against it before expanding coverage.

Start here when your spec has a useful example but you do not have recorded traffic. Explicit examples make the first response easier to review than a synthesized schema value.

Before you start

Use the licensed self-hosted Gostly installation and its local operator dashboard. Have permission to manage an isolated example workspace and service. These instructions describe the licensed product, not the separate OSS proxy CLI. A synthetic file can be inspected without an installation; importing and checking it requires the running stack.

Follow Install & Deploy if the stack is not ready. Review the shared import data-handling contract before uploading.

Download and inspect the input

A synthetic OpenAPI 3.0.3 operation with an explicit JSON request example and one 201 response example. It declares a fixture, not an order-processing implementation.

Download orders.openapi.json

Expected imported route: POST /orders. Expected response: 201 · application/json.

{
  "openapi": "3.0.3",
  "info": {
    "title": "Synthetic order API",
    "version": "1.0.0"
  },
  "paths": {
    "/orders": {
      "post": {
        "operationId": "createOrder",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "quantity": 2,
                "sku": "demo-book"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created example order",
            "content": {
              "application/json": {
                "example": {
                  "id": "order_demo_001",
                  "status": "created",
                  "total": 42
                }
              }
            }
          }
        }
      }
    }
  }
}

Expected response body

{
  "id": "order_demo_001",
  "status": "created",
  "total": 42
}

Prepare a safe source file

  • Work from a copy. Remove private server URLs, credentials and personal data from security-related examples, parameter/query values, request/response bodies, header examples and shared components.
  • For each operation with a declared request body, add one explicit JSON value. Keep the initial response equally concrete; a generated schema value is a fixture to review, not evidence of the upstream's behavior.
  • Bundle the local references needed by the example. Choose concrete status codes and paths for your first check, and decide whether the first server's base path belongs in the request route.

Import into the target service

  1. Prepare an example service. In an installed example workspace, create an empty service with Upstream URL https://orders.example.invalid, Routing Type Path and Routing Value /orders. Use a workspace without an overlapping route for this path.
  2. Import the spec. Open Seed in the local operator dashboard, choose orders.openapi.json, select the service and OpenAPI format, then Commit seed. For YAML, choose the format manually. Leave Prepend basePath off for this example.
  3. Read the generated fixture. Look for one added POST /orders mock. Check the request example, 201 status and response body. Read warnings before expanding the document; an omitted request-body example can remove an entire operation.
  4. Send the explicit request in MOCK mode. Switch the example service to MOCK. Pass the Gostly proxy origin as apiBase (http://localhost:8080 for the default local HTTP listener). The /orders path selects the service. Send the explicit JSON body and check the response and your client's behavior.

For authenticated API uploads, use the parent's seeding endpoint instructions. A stored count does not prove the library is serving: an explicit reload rejection returns 502 after storage. Resolve the reload and inspect serving state before importing again.

Review options, warnings and the stored fixture

  • Keep deduplication on for this file. The dashboard's 2xx only and Prepend basePath toggles both default off. The API options are success_only and prepend_basepath; the latter uses the first top-level servers URL's path.
  • For each response code, the importer selects one media type, preferring common JSON types. It tries the first named examples entry in sorted order, then a media-level example, then the response schema. Schema synthesis uses examples/defaults before representative values, merges allOf and chooses one oneOf/anyOf branch. It does not import all named examples or establish realistic distributions or complete validation.
  • Declared requestBody requires a supported explicit JSON example: a named example value, media-level example or schema-level example. It must encode as finite JSON within 8 KiB of canonical UTF-8 JSON. Schema shapes, defaults, enums and property-level examples do not generate request bodies. An unusable selected named example does not fall through. Missing, unsupported, invalid, oversized or unresolved examples omit every response row for that operation. Operations without requestBody use an empty body.
  • Only local references are resolved. Operation-level path parameter examples or schema examples/defaults can substitute paths; path-item-level parameters do not. Unresolved placeholders remain in the URI. A default response becomes status 500; a wildcard 2XX becomes 250. Review these representative statuses. Callbacks are not imported.

Read the full option contract and errors and warnings. Check the selected service, exact method/path/query, request body, response status, headers and body before relying on the imported case.

What the source supplies

OpenAPI field mapping and limits
Source fieldImport behavior
Version and documentOpenAPI 3.x JSON and YAML are accepted. Convert Swagger 2.0 to OpenAPI 3.x before using this importer.
ResponsesThe importer selects one media type and one example for each response status. Named examples are considered in name order; without an explicit example, response schemas can supply synthesized values.
Declared request bodiesAn operation with a request body needs an explicit JSON example. A schema declaration alone does not create a request fixture; that operation is skipped with a warning.
Paths and headersOperation-level path examples can make a route concrete. The first server's path can be prepended as an option. Response-header examples can carry over; request-header rules need separate setup.
References and behaviorUse local references within the document. External references are not fetched. Security declarations, callbacks and links do not become executable authentication, webhook or application workflows.

Check replay and application behavior

Save this JavaScript in your test harness and call the exported function with the Gostly proxy origin as apiBase. It is a reader-owned assertion; importing the file does not execute it. The reserved source hostname does not become the client base URL.

import assert from "node:assert/strict";

// Pass the base URL of your client configured to use Gostly.
export async function checkCreatedOrder(apiBase) {
  const response = await fetch(new URL("/orders", apiBase), {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ quantity: 2, sku: "demo-book" })
  });
  assert.equal(response.status, 201);
  assert.deepEqual(await response.json(), {
    id: "order_demo_001",
    status: "created",
    total: 42
  });
}

This checks the declared fixture. Add your own client assertion, such as persisting the returned order ID. Returning 201 does not create an order or implement the API's business rules.

  • Compare the stored request and response to the explicit examples. Check the base path and any substituted path parameters.
  • For a test upstream you control, deny live access or assert its request counter did not increase during replay.
  • Assert the response and the behavior your application owns. Author state changes, authentication and error scenarios separately when your test needs them.

Common questions

Will every named example become a separate mock?

No. For each response status, the importer chooses one media type and considers the first named example in sorted order, then a media-level example, then a schema example or schema synthesis. Split out the fixture you want when a test depends on a particular case.

Why was an operation with a request body skipped?

Declared request bodies require an explicit, serializable JSON example. Schema-only declarations, unsupported media, unresolved references and oversized examples can omit the operation with a warning. The seeding guide describes the accepted shape and limits.

Does the spec become a working API implementation?

Import supplies example responses. It does not execute security requirements, callbacks, validation rules or business logic. Your client supplies real requests and your test runner supplies the assertions.

Continue with your own case

Return to Seed a Mock Library for shared import, reload and storage behavior. Follow MOCK replay to inspect the response served to your application. Keep the useful client assertion as you expand coverage.