From k6
Generates k6 load test scripts from OpenAPI 3.0/3.1 YAML/JSON specs. Parses endpoints, parameters, request bodies, and security schemes for API load testing.
npx claudepluginhub kimdoubleb/grafana-k6-skills --plugin k6This skill uses the workspace's default tool permissions.
Generate k6 load test scripts by parsing OpenAPI specification files (YAML format). Extracts endpoints, parameters, request bodies, and security schemes to create comprehensive test suites.
Generates k6, Artillery, wrk scripts for API load/stress/soak tests to validate performance, identify bottlenecks, and establish baselines under configurable loads.
Guides k6 load testing for APIs, WebSockets, browsers; writes scenarios (smoke/load/stress/spike/soak), sets thresholds, analyzes results, integrates with CI/CD.
Build API test suites — endpoint testing, contract testing, load testing for REST/GraphQL/gRPC APIs. Use when asked to "test this API", "API tests", "endpoint testing", "contract tests", or "load test".
Share bugs, ideas, or general feedback.
Generate k6 load test scripts by parsing OpenAPI specification files (YAML format). Extracts endpoints, parameters, request bodies, and security schemes to create comprehensive test suites.
Read the OpenAPI YAML file and extract:
Before generating test scripts, analyze security requirements.
Extract security definitions from components.securitySchemes:
Map per-endpoint security:
security arraysecurity overridessecurity: [])Generate k6 auth setup:
setup() function matching the required auth flowSee reference/openapi-auth-mapping.md for mapping security schemes to k6 code.
For each path and operation, extract:
paths:
/users:
get: # HTTP method
operationId: listUsers # Operation identifier
tags: [Users] # Grouping
parameters: # Query/header/path params
- name: page
in: query
schema:
type: integer
security: # Per-operation security
- bearerAuth: []
responses:
'200':
description: Success
Map to k6:
http.post() bodyConvert schema definitions to example values:
| Schema Type | Example Value |
|---|---|
string | "test-string" |
string (email) | "test@example.com" |
string (date-time) | "2024-01-01T00:00:00Z" |
string (uuid) | "550e8400-e29b-41d4-a716-446655440000" |
integer | 1 |
number | 1.0 |
boolean | true |
array | [<item_example>] |
object | {<property_examples>} |
enum | First enum value |
Use example or default values from the spec when available.
See reference/openapi-parsing.md for detailed parsing logic.
Organize the generated script by API tags:
import http from 'k6/http';
import { check, group, sleep } from 'k6';
const BASE_URL = __ENV.BASE_URL || 'https://api.example.com';
export const options = {
scenarios: {
api_test: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: '2m', target: 10 },
{ duration: '5m', target: 10 },
{ duration: '1m', target: 0 },
],
},
},
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.01'],
},
};
export function setup() {
// Auth flow based on security scheme
}
export default function (data) {
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${data.token}`,
};
group('Users', () => {
// GET /users
const listRes = http.get(`${BASE_URL}/users?page=1&limit=10`, {
headers, tags: { name: 'ListUsers' },
});
check(listRes, { 'list users 200': (r) => r.status === 200 });
// POST /users
const createRes = http.post(`${BASE_URL}/users`,
JSON.stringify({ name: 'Test User', email: 'test@example.com' }),
{ headers, tags: { name: 'CreateUser' } }
);
check(createRes, { 'create user 201': (r) => r.status === 201 });
// GET /users/{id}
const userId = createRes.json('id') || 1;
const getRes = http.get(`${BASE_URL}/users/${userId}`, {
headers, tags: { name: 'GetUser' },
});
check(getRes, { 'get user 200': (r) => r.status === 200 });
});
sleep(1);
}
Based on endpoint characteristics:
openapi: '3.1.0'
info:
title: My API
version: '1.0.0'
servers:
- url: https://api.example.com/v1
security:
- bearerAuth: [] # Global security
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
apiKey:
type: apiKey
in: header
name: X-API-Key
schemas:
User:
type: object
required: [name, email]
properties:
id:
type: integer
name:
type: string
email:
type: string
format: email
paths:
/users:
get:
tags: [Users]
parameters:
- name: page
in: query
schema: { type: integer, default: 1 }
responses:
'200':
description: User list
post:
tags: [Users]
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
'201':
description: Created
/users/{id}:
get:
tags: [Users]
parameters:
- name: id
in: path
required: true
schema: { type: integer }
responses:
'200':
description: User details
/k6:generating-api-load-tests/k6:designing-test-scenarios/k6:generating-tests-from-code