
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
@cerios/openapi-to-k6
Advanced tools
Generate type-safe K6 HTTP clients from OpenAPI specifications with TypeScript types
Generate type-safe K6 HTTP clients from OpenAPI specifications with TypeScript types.
npm install @cerios/openapi-to-k6
# or
pnpm add @cerios/openapi-to-k6
# Initialize a config file
npx openapi-to-k6 init
# Generate with config file
npx openapi-to-k6
# Generate with CLI options
npx openapi-to-k6 --input openapi.yaml --output k6/api-client.ts
import { OpenApiK6Generator } from "@cerios/openapi-to-k6";
const generator = new OpenApiK6Generator({
input: "./openapi.yaml",
outputClient: "./k6/api-client.ts",
outputTypes: "./k6/api-types.ts",
useOperationId: true,
});
generator.generate();
Create an openapi-to-k6.config.ts file:
import { defineConfig } from "@cerios/openapi-to-k6";
export default defineConfig({
defaults: {
includeDescriptions: true,
showStats: true,
preferredContentTypes: ["application/json"],
},
specs: [
{
input: "openapi.yaml",
outputClient: "k6/api-client.ts",
outputTypes: "k6/api-types.ts",
useOperationId: true,
basePath: "/api/v1",
},
],
});
The generated client follows the K6 HTTP patterns:
import http from "k6/http";
import type { Params, Response } from "k6/http";
export interface ListUsersParams {
page?: number;
limit?: number;
}
export interface ListUsersHeaders {
"X-Request-ID"?: string;
}
export class ApiClient {
private readonly baseUrl: string;
private readonly commonRequestParameters: Params;
constructor(baseUrl: string, commonRequestParameters: Params = {}) {
this.baseUrl = baseUrl.replace(/\/$/, "");
this.commonRequestParameters = commonRequestParameters;
}
private _mergeRequestParameters(requestParams: Params, commonParams: Params): Params {
return {
...commonParams,
...requestParams,
headers: {
...commonParams?.headers,
...requestParams?.headers,
},
tags: {
...commonParams?.tags,
...requestParams?.tags,
},
};
}
/**
* @summary List all users
* @method GET /users
*/
listUsers(
headers?: ListUsersHeaders,
params?: ListUsersParams,
requestParameters?: Params
): { response: Response; data: User[] } {
const url = this.baseUrl + `/users` + this._buildQueryString(params);
const mergedParams = this._mergeRequestParameters(requestParameters || {}, this.commonRequestParameters);
const response = http.request("GET", url, undefined, {
...mergedParams,
headers: {
...mergedParams?.headers,
...this._stringifyHeaders(headers || {}),
},
});
const data = response.json() as User[];
return { response, data };
}
// ... more methods
}
import { ApiClient } from "./api-client";
import { check, sleep } from "k6";
// Create client with base URL and common parameters
const client = new ApiClient("https://api.example.com", {
headers: {
Authorization: "Bearer token123",
"Content-Type": "application/json",
},
tags: {
name: "api-test",
},
timeout: "30s",
});
export default function () {
// Simple GET request
const { response, data } = client.listUsers();
check(response, {
"status is 200": r => r.status === 200,
"has users": () => data.length > 0,
});
// GET with query parameters
const { response: filteredResponse, data: filteredUsers } = client.listUsers(
undefined, // headers
{ page: 1, limit: 10 }, // query params
{ timeout: "5s" } // request-specific K6 params
);
// POST with body
const { response: createResponse, data: newUser } = client.createUser(
{ name: "John", email: "john@example.com" }, // body
{ timeout: "10s" } // request params
);
// Path parameters
const { response: userResponse, data: user } = client.getUserById(
"123" // userId path param
);
sleep(1);
}
export const options = {
vus: 10,
duration: "30s",
};
| Option | Type | Default | Description |
|---|---|---|---|
input | string | required | Path to OpenAPI specification file |
outputClient | string | required | Output path for generated K6 client |
outputTypes | string | - | Separate file for TypeScript types |
useOperationId | boolean | false | Use operationId for client/service method names and operation-derived TypeScript type names |
basePath | string | - | Base path to prepend to all endpoints |
stripPathPrefix | string | - | Strip prefix from paths (glob support) |
ignoreHeaders | string[] | - | Header patterns to ignore |
includeDescriptions | boolean | true | Include JSDoc descriptions |
showStats | boolean | true | Show generation statistics |
preferredContentTypes | string[] | ["application/json"] | Preferred content types |
{
operationFilters: {
includeTags: ['users', 'auth'], // Only these tags
excludeTags: ['admin'], // Exclude these tags
includeMethods: ['get', 'post'], // Only these HTTP methods
excludeMethods: ['delete'], // Exclude these methods
includePaths: ['/api/**'], // Only matching paths (glob)
excludePaths: ['/internal/**'], // Exclude matching paths
includeOperationIds: ['getUser'], // Only these operationIds
excludeOperationIds: ['deleteAll'], // Exclude these operationIds
excludeDeprecated: true, // Exclude deprecated operations
}
}
MIT
FAQs
Generate type-safe K6 HTTP clients from OpenAPI specifications with TypeScript types
We found that @cerios/openapi-to-k6 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.