agentleFS
emmanuelperuemmanuelperu/microcks-skills/skills/microcks-import-artifacts/SKILL.md

microcks-import-artifacts

Skill4 starsChanged 42 days agoApache-2.0View on GitHub

Import OpenAPI specifications into a running Microcks instance and auto-configure dispatchers based on vendor extensions. Provides shell script templates for importing specs, downloading microcks-cli, and setting up JSON_BODY or SCRIPT dispatchers.

  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 1

    1. emmanuelperu/skills★ 4100% same

    Edited · 0

    None found.

    Wrote their own version · 0

    None found.

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository2 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 9 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Import OpenAPI specifications into Microcks and automatically configure dispatchers based on vendor extensions.

    line 9
  2. Distinctive:

    Use this skill when:

    line 13
  3. Very specific:

    Auto-configuring dispatchers: after writing a spec with x-mocking-microcks-dispatcher extensions

    line 16
  4. Very specific:

    Create the mocking/ directory structure:

    line 30
  5. Distinctive:

    Run the import script (this is the only command needed to import AND configure dispatchers):

    line 44
  6. Distinctive:

    Check that Microcks is running

    line 51
  7. Distinctive:

    Import the spec into Microcks

    line 53
  8. Very specific:

    Read x-mocking-microcks-dispatcher vendor extensions

    line 54
  9. Distinctive:

    Always inform the user and ask for confirmation before executing these scripts.

    line 65
  10. Distinctive:

    Add this vendor extension at the operation level in your OpenAPI spec to indicate which dispatcher type to use:

    line 71
  11. Distinctive:

    [microcks-local-server](../microcks-local-server/): Start a local Microcks server with Docker Compose

    line 248
  12. Distinctive:

    [microcks-openapi-mocking](../microcks-openapi-mocking/): Write OpenAPI examples that work with Microcks dispatchers

    line 253

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Microcks Import Artifacts

Import OpenAPI specifications into Microcks and automatically configure dispatchers based on vendor extensions.

When to Use This Skill

Use this skill when:

  • Importing an OpenAPI spec into a running Microcks instance for mocking
  • Auto-configuring dispatchers after writing a spec with x-mocking-microcks-dispatcher extensions
  • Setting up a repeatable import workflow with shell scripts

Prerequisites

  • Docker installed and running
  • Microcks started (use the microcks-local-server skill)
  • jq installed (brew install jq / apt install jq)
  • curl installed

Quick Start

IMPORTANT: The import and dispatcher configuration MUST be done by running the import-openapi.sh shell script. Do NOT attempt to configure dispatchers manually via curl or the Microcks API: the script handles the full workflow (import, discriminant detection, Groovy script loading, API calls).

  1. Create the mocking/ directory structure:
mkdir -p mocking/dispatchers
  1. Copy the template scripts into it:
cp templates/import-openapi.sh mocking/import-openapi.sh
cp templates/download-microcks-cli.sh mocking/download-microcks-cli.sh
chmod +x mocking/import-openapi.sh mocking/download-microcks-cli.sh
  1. Run the import script (this is the only command needed to import AND configure dispatchers):
./mocking/import-openapi.sh path/to/your-api-spec.yaml

The script will:

  • Check that Microcks is running
  • Download microcks-cli if not already cached
  • Import the spec into Microcks
  • Read x-mocking-microcks-dispatcher vendor extensions
  • Auto-configure dispatchers via the Microcks API

Security Notice

This skill provides shell script templates that the user copies into their project. These scripts:

  • Download an external binary (microcks-cli from GitHub releases of microcks/microcks-cli)
  • Run Docker containers (mikefarah/yq for YAML-to-JSON conversion, from mikefarah/yq)
  • Make network calls to the local Microcks REST API

Always inform the user and ask for confirmation before executing these scripts.


Vendor Extension: x-mocking-microcks-dispatcher

Add this vendor extension at the operation level in your OpenAPI spec to indicate which dispatcher type to use:

ValueMicrocks DispatcherBehavior
json_bodyJSON_BODYDetects the discriminant field in request body examples; routes by field value
script_header_errorSCRIPTRoutes on the error HTTP header: 400→invalid_input, 500→server_error, default→success
scriptSCRIPTLoads an external Groovy script from mocking/dispatchers/{METHOD}-{path-slug}.groovy

Example

paths:
  /orders:
    post:
      x-mocking-microcks-dispatcher: json_body
      # ...

  /health:
    get:
      x-mocking-microcks-dispatcher: script_header_error
      # ...

  /payments:
    post:
      x-mocking-microcks-dispatcher: script
      # ...

Groovy File Convention

For operations using the script dispatcher, place Groovy files at:

mocking/dispatchers/{METHOD}-{path-slug}.groovy

The path slug is built by:

  1. Removing the leading /
  2. Replacing / with -
  3. Removing { and }

Examples:

OperationGroovy File
POST /eventsmocking/dispatchers/POST-events.groovy
POST /v1/orders/{orderId}/paymentsmocking/dispatchers/POST-v1-orders-orderId-payments.groovy
GET /usersmocking/dispatchers/GET-users.groovy

Integration Workflow

The import-openapi.sh script performs a 6-step workflow that combines artifact import and dispatcher configuration in a single command. Understanding these steps is useful for debugging or building your own variant.

Step 1: Check that Microcks is reachable

The script sends a single request to {MICROCKS_URL}/api with a 5 second connection timeout. If Microcks does not answer, the script exits with instructions to start it (or to set MICROCKS_URL) rather than failing later on an HTTP error.

curl -s -o /dev/null --connect-timeout 5 "${MICROCKS_URL}/api"

Step 2: Import the OpenAPI spec

The script invokes microcks-cli to push the spec into Microcks as a primary artifact. Microcks parses the spec and creates a mock service for every operation, using the named examples to seed request/response pairs.

microcks-cli import "${SPEC_FILE}:true" \
  --microcksURL="${MICROCKS_URL}/api" \
  --keycloakClientId=foo \
  --keycloakClientSecret=bar

The Keycloak credentials are placeholders: the local server started by microcks-local-server runs without authentication.

For operations that already have a discriminating parameter or body, Microcks uses native dispatching (URI_PARAMS, URI_ELEMENTS, QUERY_HEADER). The script only needs to configure custom dispatchers for operations that opt in via x-mocking-microcks-dispatcher.

Step 3: Find the imported service

The script converts the YAML spec to JSON (via mikefarah/yq in Docker), reads info.title and info.version, then looks up the matching service in Microcks:

curl -s "${MICROCKS_URL}/api/services?page=0&size=1000" \
  | jq -r --arg name "$API_TITLE" --arg version "$API_VERSION" \
      'map(select(.name == $name and .version == $version)) | .[0].id'

Matching on name and version guarantees that dispatchers are pushed to the right service, even when Microcks hosts several APIs.

Step 4: Detect vendor extensions

The script finds every operation annotated with x-mocking-microcks-dispatcher using jq:

jq -r '.paths
  | to_entries[]
  | .key as $path
  | .value
  | to_entries[]
  | select(.value."x-mocking-microcks-dispatcher" != null)
  | "\(.key | ascii_upcase) \($path) \(.value."x-mocking-microcks-dispatcher")"'

This produces one METHOD path dispatcher line per operation to process.

Step 5: Build the dispatcher payload

The payload depends on the dispatcher type:

TypeMicrocks dispatcherdispatcherRules content
json_bodyJSON_BODY{"exp": "/<field>", "operator": "equals", "cases": {...}}. The script picks the first request body field whose values differ across examples (preferring one that is unique per example), maps each value to its example name, and uses the first example as default.
script_header_errorSCRIPTA static Groovy script that reads the error header (400 → invalid_input, 500 → server_error, default → success). Identical for every operation.
scriptSCRIPTThe contents of {METHOD}-{path-slug}.groovy, looked up next to the script (dispatchers/) then in mocking/dispatchers/ at the project root.

Step 6: Push the dispatcher via the Microcks API

The script calls PUT /api/services/{serviceId}/operation for each detected operation, with the dispatcher type and rules in the body:

PUT /api/services/{serviceId}/operation?operationName={METHOD}%20{path}
Content-Type: application/json

{
  "defaultDelay": 0,
  "dispatcher": "JSON_BODY",
  "dispatcherRules": "{\"exp\":\"/status\",\"operator\":\"equals\",\"cases\":{...}}",
  "parameterConstraints": []
}

Why dispatchers need names to match

Microcks correlates request and response examples by example name. After dispatching, the matched request example's name (e.g. success) is used to look up the response example with the same name. If names do not match across parameters, requestBody, and responses, Microcks falls back to the first available example. See the microcks-openapi-mocking skill for the full naming rules.


Script Templates

import-openapi.sh

The main import script. See templates/import-openapi.sh.

Usage:

# Basic usage (Microcks on default port 8080)
./mocking/import-openapi.sh path/to/api-spec.yaml

# Custom Microcks URL
MICROCKS_URL=http://localhost:9080 ./mocking/import-openapi.sh path/to/api-spec.yaml

What it does:

  1. Validates the spec file argument
  2. Health-checks the Microcks instance
  3. Downloads microcks-cli if not cached
  4. Imports the spec via microcks-cli
  5. Converts YAML to JSON via docker run mikefarah/yq
  6. Finds operations with x-mocking-microcks-dispatcher
  7. Configures dispatchers via the Microcks REST API
  8. Prints the Microcks UI URL

download-microcks-cli.sh

Downloads and caches the microcks-cli binary. See templates/download-microcks-cli.sh.

Features:

  • Multi-platform: macOS (Darwin) and Linux, amd64 and arm64
  • Cached in ~/.local/bin/ (shared across projects)
  • Version configurable via MICROCKS_CLI_VERSION env var (default: 0.5.6)

Complementary Skills

  • microcks-local-server: Start a local Microcks server with Docker Compose
    npx skills add emmanuelperu/skills --skill microcks-local-server
  • microcks-openapi-mocking: Write OpenAPI examples that work with Microcks dispatchers
    npx skills add emmanuelperu/skills --skill microcks-openapi-mocking

Related

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.