generate_api_tests_from_swagger

generate_api_tests_from_swagger is a command for Claude Code from anhtester/ClaudeCode_Playwright_Demo. It costs 36 tokens per session (4,847 once invoked), scanned A, original, MIT.

An API testing tool that reads a Swagger or OpenAPI file, a document describing an API's endpoints and data formats, and creates test cases from it.

In plain words
What is it for?
Use it in SPEC mode for documented test cases and test data, or in FULL mode for those materials plus automation scripts.
Why use it?
It removes the need to inspect the API specification and write every endpoint check by hand. It uses the actual specification instead of guessing the API structure.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/anhtester/claudecode_playwright_demo/generate_api_tests_from_swagger
Clone the repo
git clone --depth 1 https://github.com/anhtester/ClaudeCode_Playwright_Demo

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for generate_api_tests_from_swagger

README.md
[![agentmods](https://agentmods.dev/badge/commands/anhtester/claudecode_playwright_demo/generate_api_tests_from_swagger.svg)](https://agentmods.dev/commands/anhtester/claudecode_playwright_demo/generate_api_tests_from_swagger)
Your own site
<a href="https://agentmods.dev/commands/anhtester/claudecode_playwright_demo/generate_api_tests_from_swagger"><img src="https://agentmods.dev/badge/commands/anhtester/claudecode_playwright_demo/generate_api_tests_from_swagger.svg" alt="Measured on agentmods" height="20"></a>
Per session 36 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 4,847 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00036 $0.04847
Opus 5 $0.00018 $0.02423
Sonnet 5 $0.00007 $0.00969
Haiku 4.5 $0.00004 $0.00485

Measured 5d ago against content hash e7a00709c7fa, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

generate_api_tests_from_swagger scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/generate_api_tests_from_swagger.md · 340 lines

How it starts

The opening of the file, as written. The whole thing — 340 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Workflow: Sinh API Tests từ Swagger/OpenAPI

BẮT BUỘC (MANDATORY SKILL): Bạn PHẢI nạp và đọc kỹ nội dung của skill qa_automation_engineer (tại .agent/skills/qa_automation_engineer/SKILL.md) trước khi bắt đầu. Ngoài ra, tham khảo thêm skill test_data_generator để sinh test data đúng chuẩn.

Workflow này giúp agent phân tích Swagger/OpenAPI specification, xác định các endpoints, sinh API test cases có cấu trúc, và (tùy mode) tự động sinh automation scripts hoàn chỉnh.

⚠️ Nguyên tắc thực thi

  • Tất cả output bằng Tiếng Việt
  • KHÔNG đoán schema/endpoint — phải đọc spec thực tế (JSON/YAML)
  • Phải chờ user xác nhận scope tại Bước 2 trước khi sinh chi tiết
  • Nếu user chưa cung cấp Swagger URL/file → hỏi trước khi bắt đầu
  • ⚠️ Rule E3: Khi test FAIL → tự đọc log → phân tích → sửa → chạy lại. KHÔNG hỏi user trong quá trình fix lỗi

2 Chế độ (Mode)

Mode Khi nào sử dụng Output
SPEC (mặc định) User cần API test cases dưới dạng tài liệu API Test Cases (Markdown) + Test Data Matrix
FULL User yêu cầu cả automation scripts Như SPEC + Automation Scripts + Project Structure

Nếu user nói "generate automation", "viết code test API", hoặc yêu cầu scripts → tự động chuyển sang Mode FULL.

Các bước thực hiện

Bước 1: Tiếp nhận & Phân tích Spec (Parse & Analyze)

  1. Thu thập Swagger/OpenAPI spec từ user:
    • URL trực tiếp (VD: https://api.example.com/swagger.json) → dùng read_url_content để fetch
    • File local (JSON/YAML) → dùng view_file để đọc
    • Swagger UI URL → trích xuất URL spec gốc (thường là /v2/api-docs hoặc /v3/api-docs)
    • Scalar API Reference URL → inspect HTML để tìm data-configuration chứa URL spec (thường là /swagger/json, /reference/json, hoặc relative path trong attribute url). VD: https://book.anhtester.com/swagger → spec tại https://book.anhtester.com/swagger/json
    • Các dạng API Doc khác (Redoc, Stoplight, RapiDoc) → tìm URL spec trong page source hoặc network requests
  2. Parse spec và trích xuất thông tin:
    • Base URL, API version, authentication scheme (Bearer, API Key, OAuth2, Basic)
    • Danh sách tất cả endpoints: method + path
    • Request parameters: path, query, header, body (schema + required fields)
    • Response schemas: status codes, response body structure
    • Models/Definitions: reusable data models
  3. Phân loại endpoints theo nhóm:
    • CRUD operations — Create, Read, Update, Delete
    • Authentication — Login, Register, Token refresh
    • Business Logic — Các API xử lý nghiệp vụ phức tạp
    • Utility — Health check, config, metadata

Read the full file on GitHub · 340 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 340 lines · 36 tokens per session scan A e7a00709c7fa

Subscribe to this mod's changes

generate_api_tests_from_swagger is a command published in the GitHub repository anhtester/ClaudeCode_Playwright_Demo (2 stars, last pushed 3mo ago), licensed MIT. It adds 36 tokens to every session and 4,847 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.