npm.io
1.7.0 • Published yesterday

@rafads/plugin-openapi

Licence
MIT
Version
1.7.0
Deps
6
Size
1.2 MB
Vulns
1
Weekly
0
Stars
2.7K

@rafads/plugin-openapi

Load OpenAPI specifications into an executor. Every operation in the spec becomes an invokable tool with a JSON-Schema input, automatic request building, and optional secret-backed auth.

Install

bun add @rafads/sdk @rafads/plugin-openapi
# or
npm install @rafads/sdk @rafads/plugin-openapi

Usage

import { createExecutor } from "@rafads/sdk";
import { openApiPlugin } from "@rafads/plugin-openapi";

const executor = await createExecutor({
  onElicitation: "accept-all",
  plugins: [openApiPlugin()] as const,
});

// Load a spec by URL (JSON or YAML, remote or file://)
await executor.openapi.addSpec({
  scope: executor.scopes[0]!.id,
  spec: "https://petstore3.swagger.io/api/v3/openapi.json",
  namespace: "petstore",
});

// List and invoke tools like any other plugin
const tools = await executor.tools.list();
const result = await executor.tools.invoke("petstore.listPets", {});

Secret-backed auth headers

Wire API keys or bearer tokens through the executor's secret store — never hard-code them in integration configs:

import { createExecutor } from "@rafads/sdk";
import { openApiPlugin } from "@rafads/plugin-openapi";
import { fileSecretsPlugin } from "@rafads/plugin-file-secrets";

const executor = await createExecutor({
  onElicitation: "accept-all",
  plugins: [fileSecretsPlugin(), openApiPlugin()] as const,
});

const scope = executor.scopes[0]!.id;

await executor.secrets.set({
  id: "stripe-key",
  name: "Stripe Key",
  value: "sk_live_...",
  scope,
});

await executor.openapi.addSpec({
  scope,
  spec: "https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json",
  namespace: "stripe",
  headers: {
    Authorization: { secretId: "stripe-key", prefix: "Bearer " },
  },
});

Using with Effect

If you're building on @rafads/sdk/core (the raw Effect entry), import this plugin from its /core subpath instead — it returns the Effect-shaped plugin with Effect.Effect<...>-returning methods rather than promisified wrappers:

import { openApiPlugin } from "@rafads/plugin-openapi/core";

Status

Pre-1.0. APIs may still change between beta releases. Part of the executor monorepo.

License

MIT