Introduction

DeepSeek Harness (DSH) adopts the “everything is a plugin” philosophy, allowing developers to extend agent capabilities through plugins. During API integration testing, waiting for backend APIs to be ready is a common bottleneck. dsh-api-mock solves this problem by providing a way to quickly generate a Mock server locally, helping frontend or testing personnel engage in the development workflow earlier.

Plugin Overview

dsh-api-mock is a web tool plugin maintained by uckkk. It parses OpenAPI 3.x specifications (supporting JSON or YAML) and generates a Mock server implemented in pure Node.js. The server depends on no external network services or third-party libraries and is built on Node’s built-in http module, ensuring that the frontend can directly fetch response data for integration testing.

Installation

To install the plugin, run the following command:

dsh plugin add dsh-api-mock

After installation, the plugin is registered in the current session.

Core Capabilities

The plugin mainly provides the following features:

  • Spec Parsing: Supports parsing JSON or YAML files in OpenAPI 3.x format.
  • Server Generation: Generates a mock-server.mjs file based on the specification. This file is dependency-free and can be run directly.
  • Deterministic Sample Data: Generates sample data deterministically according to the API response Schema. Data generation follows specific rules (for example, string becomes a sample string, integer becomes a number, email becomes an email-like value), while also respecting example, default, and enum values in field definitions.
  • Pure Local Execution: Runs entirely locally, without network requests or external service calls.

Usage

The plugin provides two main tool functions for invocation.

Generate a Mock Server

If you have an openapi.yaml file and need to generate a Mock server running on port 3000, you can call:

mock_generate(spec="openapi.yaml", port=3000)

After execution, a mock-server.mjs file is generated. Enter that directory and run the following command to start the server:

node mock-server.mjs

Generate Sample Data

If you need to create a test data sample for a specific Schema, such as the User schema, you can call:

mock_sample(spec="openapi.yaml", ref="#/components/schemas/User")

Notes

  • Data Generation Logic: Sample data is generated deterministically according to Schema types. For example, string fields are filled with sample strings, integer fields are filled with 42, email fields are filled with user@example.com, and enum fields take the first item. It also prioritizes example, default, or enum values defined in the Schema.
  • Response Selection Logic: The response returned by the Mock server is taken from the application/json schema of the first 2xx status code in the API definition. If there is no 2xx response, it uses the first response.
  • Code Execution Permissions: Installing the plugin causes third-party code to run on your local machine. Please review the source code before installation to ensure it is safe.

Reference Links