bruno-collection-generator
Express、Next.js、Fastify などのAPIルートからBrunoコレクションファイル(.bru)を生成します。オープンソースのBruno APIクライアント向けに、環境設定・認証・フォルダ構成を整理したコレクションを作成します。「Brunoコレクションを生成したい」「Bruno APIテスト」「.bruファイルを作成したい」「Brunoにインポートしたい」といったリクエストに対応します。
description の原文を見る
Generates Bruno collection files (.bru) from Express, Next.js, Fastify, or other API routes. Creates organized collections with environments, authentication, and folder structure for the open-source Bruno API client. Use when users request "generate bruno collection", "bruno api testing", "create bru files", or "bruno import".
SKILL.md 本文
Bruno コレクションジェネレータ
オープンソース、Git フレンドリー API クライアント用の Bruno コレクションファイルを生成します。
コアワークフロー
- ルートをスキャン: すべての API ルート定義を検出
- メタデータを抽出: メソッド、パス、パラメータ、ボディ
- コレクションを作成: bruno.json マニフェストを初期化
- .bru ファイルを生成: リクエストごとに 1 ファイル
- フォルダを整理: リソース別にグループ化
- 環境を追加: Dev、Staging、Production
Bruno コレクション構造
collection/
├── bruno.json # Collection manifest
├── environments/
│ ├── Development.bru
│ ├── Staging.bru
│ └── Production.bru
├── users/
│ ├── folder.bru
│ ├── get-users.bru
│ ├── get-user.bru
│ ├── create-user.bru
│ ├── update-user.bru
│ └── delete-user.bru
├── auth/
│ ├── folder.bru
│ ├── login.bru
│ ├── register.bru
│ └── logout.bru
└── products/
├── folder.bru
└── ...
bruno.json マニフェスト
{
"version": "1",
"name": "My API",
"type": "collection",
"ignore": ["node_modules", ".git"]
}
.bru ファイル構文
meta {
name: Get Users
type: http
seq: 1
}
get {
url: {{baseUrl}}/users
body: none
auth: bearer
}
auth:bearer {
token: {{authToken}}
}
query {
page: 1
limit: 10
}
headers {
Accept: application/json
}
docs {
Retrieve a paginated list of users.
}
ジェネレータスクリプト
// scripts/generate-bruno.ts
import * as fs from "fs";
import * as path from "path";
interface RouteInfo {
method: string;
path: string;
name: string;
description?: string;
body?: object;
queryParams?: { name: string; value: string }[];
auth?: boolean;
}
interface BrunoOptions {
collectionName: string;
outputDir: string;
baseUrl: string;
authType?: "bearer" | "basic" | "apikey";
}
function generateBrunoCollection(
routes: RouteInfo[],
options: BrunoOptions
): void {
const { outputDir, collectionName } = options;
// Create output directory
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Create bruno.json
const manifest = {
version: "1",
name: collectionName,
type: "collection",
ignore: ["node_modules", ".git"],
};
fs.writeFileSync(
path.join(outputDir, "bruno.json"),
JSON.stringify(manifest, null, 2)
);
// Create environments
generateEnvironments(outputDir, options);
// Group routes by resource
const groupedRoutes = groupRoutesByResource(routes);
for (const [resource, resourceRoutes] of Object.entries(groupedRoutes)) {
const folderPath = path.join(outputDir, resource);
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, { recursive: true });
}
// Create folder.bru
const folderBru = `meta {\n name: ${capitalize(resource)}\n}\n`;
fs.writeFileSync(path.join(folderPath, "folder.bru"), folderBru);
// Create request files
let seq = 1;
for (const route of resourceRoutes) {
const fileName = generateFileName(route);
const content = generateBruFile(route, seq++, options);
fs.writeFileSync(path.join(folderPath, `${fileName}.bru`), content);
}
}
}
function generateBruFile(
route: RouteInfo,
seq: number,
options: BrunoOptions
): string {
const lines: string[] = [];
// Meta section
lines.push("meta {");
lines.push(` name: ${route.name}`);
lines.push(" type: http");
lines.push(` seq: ${seq}`);
lines.push("}");
lines.push("");
// Request section
const method = route.method.toLowerCase();
const urlPath = route.path.replace(/:(\w+)/g, "{{$1}}");
lines.push(`${method} {`);
lines.push(` url: {{baseUrl}}${urlPath}`);
if (["post", "put", "patch"].includes(method) && route.body) {
lines.push(" body: json");
} else {
lines.push(" body: none");
}
if (route.auth && options.authType) {
lines.push(` auth: ${options.authType}`);
} else {
lines.push(" auth: none");
}
lines.push("}");
lines.push("");
// Auth section
if (route.auth && options.authType === "bearer") {
lines.push("auth:bearer {");
lines.push(" token: {{authToken}}");
lines.push("}");
lines.push("");
} else if (route.auth && options.authType === "basic") {
lines.push("auth:basic {");
lines.push(" username: {{username}}");
lines.push(" password: {{password}}");
lines.push("}");
lines.push("");
}
// Query params
if (route.queryParams?.length) {
lines.push("query {");
for (const param of route.queryParams) {
lines.push(` ${param.name}: ${param.value}`);
}
lines.push("}");
lines.push("");
}
// Headers
lines.push("headers {");
lines.push(" Accept: application/json");
if (["post", "put", "patch"].includes(method)) {
lines.push(" Content-Type: application/json");
}
lines.push("}");
lines.push("");
// Body
if (["post", "put", "patch"].includes(method) && route.body) {
lines.push("body:json {");
lines.push(JSON.stringify(route.body, null, 2));
lines.push("}");
lines.push("");
}
// Docs
if (route.description) {
lines.push("docs {");
lines.push(` ${route.description}`);
lines.push("}");
}
return lines.join("\n");
}
function generateEnvironments(outputDir: string, options: BrunoOptions): void {
const envsDir = path.join(outputDir, "environments");
if (!fs.existsSync(envsDir)) {
fs.mkdirSync(envsDir, { recursive: true });
}
const environments = [
{ name: "Development", baseUrl: "http://localhost:3000/api" },
{ name: "Staging", baseUrl: "https://staging-api.example.com" },
{ name: "Production", baseUrl: "https://api.example.com" },
];
for (const env of environments) {
const content = `vars {
baseUrl: ${env.baseUrl}
authToken:
}
vars:secret [
authToken
]
`;
fs.writeFileSync(path.join(envsDir, `${env.name}.bru`), content);
}
}
function generateFileName(route: RouteInfo): string {
return route.name.toLowerCase().replace(/\s+/g, "-");
}
function groupRoutesByResource(
routes: RouteInfo[]
): Record<string, RouteInfo[]> {
const groups: Record<string, RouteInfo[]> = {};
for (const route of routes) {
const parts = route.path.split("/").filter(Boolean);
const resource = parts[0] || "api";
if (!groups[resource]) {
groups[resource] = [];
}
groups[resource].push(route);
}
return groups;
}
function capitalize(str: string): string {
return str.charAt(0).toUpperCase() + str.slice(1);
}
完全な例ファイル
bruno.json
{
"version": "1",
"name": "My API",
"type": "collection",
"ignore": ["node_modules", ".git"]
}
environments/Development.bru
vars {
baseUrl: http://localhost:3000/api
authToken:
userId: 1
}
vars:secret [
authToken
]
environments/Production.bru
vars {
baseUrl: https://api.example.com
authToken:
userId:
}
vars:secret [
authToken
]
users/folder.bru
meta {
name: Users
}
users/get-users.bru
meta {
name: Get Users
type: http
seq: 1
}
get {
url: {{baseUrl}}/users
body: none
auth: bearer
}
auth:bearer {
token: {{authToken}}
}
query {
page: 1
limit: 10
}
headers {
Accept: application/json
}
docs {
Retrieve a paginated list of users.
## Query Parameters
- page: Page number (default: 1)
- limit: Items per page (default: 10, max: 100)
## Response
Returns paginated user list with metadata.
}
users/get-user.bru
meta {
name: Get User by ID
type: http
seq: 2
}
get {
url: {{baseUrl}}/users/{{userId}}
body: none
auth: bearer
}
auth:bearer {
token: {{authToken}}
}
headers {
Accept: application/json
}
docs {
Retrieve a single user by their ID.
}
users/create-user.bru
meta {
name: Create User
type: http
seq: 3
}
post {
url: {{baseUrl}}/users
body: json
auth: bearer
}
auth:bearer {
token: {{authToken}}
}
headers {
Accept: application/json
Content-Type: application/json
}
body:json {
{
"name": "John Doe",
"email": "john@example.com",
"role": "user"
}
}
docs {
Create a new user account.
## Request Body
- name: User's full name (required)
- email: User's email address (required, unique)
- role: User role (optional, default: "user")
}
users/update-user.bru
meta {
name: Update User
type: http
seq: 4
}
put {
url: {{baseUrl}}/users/{{userId}}
body: json
auth: bearer
}
auth:bearer {
token: {{authToken}}
}
headers {
Accept: application/json
Content-Type: application/json
}
body:json {
{
"name": "John Updated",
"email": "john.updated@example.com"
}
}
docs {
Update an existing user.
}
users/delete-user.bru
meta {
name: Delete User
type: http
seq: 5
}
delete {
url: {{baseUrl}}/users/{{userId}}
body: none
auth: bearer
}
auth:bearer {
token: {{authToken}}
}
headers {
Accept: application/json
}
docs {
Delete a user account.
}
auth/login.bru
meta {
name: Login
type: http
seq: 1
}
post {
url: {{baseUrl}}/auth/login
body: json
auth: none
}
headers {
Accept: application/json
Content-Type: application/json
}
body:json {
{
"email": "user@example.com",
"password": "password123"
}
}
script:post-response {
if (res.body.token) {
bru.setEnvVar("authToken", res.body.token);
}
}
docs {
Authenticate user and receive access token.
On successful login, the token is automatically saved
to the authToken environment variable.
}
リクエスト前後のスクリプト
script:pre-request {
// Set dynamic values before request
const timestamp = Date.now();
bru.setVar("requestId", `req-${timestamp}`);
}
script:post-response {
// Extract values from response
if (res.body.token) {
bru.setEnvVar("authToken", res.body.token);
}
if (res.body.id) {
bru.setEnvVar("userId", res.body.id);
}
// Log response info
console.log(`Status: ${res.status}`);
console.log(`Response time: ${res.responseTime}ms`);
}
Bruno のテスト
tests {
test("should return 200", function() {
expect(res.status).to.equal(200);
});
test("should return array of users", function() {
expect(res.body.data).to.be.an("array");
});
test("should include pagination", function() {
expect(res.body.meta).to.have.property("page");
expect(res.body.meta).to.have.property("total");
});
}
CLI スクリプト
#!/usr/bin/env node
// scripts/bruno-gen.ts
import * as fs from "fs";
import { program } from "commander";
program
.name("bruno-gen")
.description("Generate Bruno collection from API routes")
.option("-f, --framework <type>", "Framework type", "express")
.option("-s, --source <path>", "Source directory", "./src")
.option("-o, --output <path>", "Output directory", "./bruno-collection")
.option("-n, --name <name>", "Collection name", "My API")
.option("-b, --base-url <url>", "Base URL", "http://localhost:3000/api")
.option("-a, --auth <type>", "Auth type (bearer|basic|apikey)")
.parse();
const options = program.opts();
async function main() {
const routes = await scanRoutes(options.framework, options.source);
generateBrunoCollection(routes, {
collectionName: options.name,
outputDir: options.output,
baseUrl: options.baseUrl,
authType: options.auth,
});
console.log(`Generated Bruno collection in ${options.output}`);
console.log(`Open with: bruno run ${options.output}`);
}
main();
ベストプラクティス
- Git フレンドリー: Bruno はすべてをプレーンテキストファイルとして保存
- 環境を使用: URL とトークンを環境ファイルに保存
- シークレット変数: 機密情報は
vars:secretでマーク - ドキュメント追加: docs ブロックで各リクエストを記述
- 前後スクリプト: トークン抽出とセットアップを自動化
- テスト追加: test ブロックにアサーションを含める
- フォルダを整理: 関連するリクエストをグループ化
- シーケンス番号:
seqで論理的な順序を設定
出力チェックリスト
- bruno.json マニフェスト作成済み
- dev/staging/prod 用の環境ファイル
- リソース別フォルダ構造
- 各フォルダの folder.bru
- 正しい構文のリクエスト .bru ファイル
- パスパラメータが
{{param}}構文を使用 - query ブロック内のクエリパラメータ
- body:json ブロック内のリクエストボディ
- 認証設定済み
- docs ブロックに記述されたドキュメント
- トークンハンドリング用の前後スクリプト
ライセンス: MIT(寛容ライセンスのため全文を引用しています) · 原本リポジトリ
詳細情報
- 作者
- patricio0312rev
- ライセンス
- MIT
- 最終更新
- 不明
Source: https://github.com/patricio0312rev/skills / ライセンス: MIT
関連スキル
doubt-driven-development
重要な判断はすべて、本番環境への展開前に新しい視点から対抗的レビューを実施します。速度より正確性が重要な場合、不慣れなコードを扱う場合、本番環境・セキュリティに関わるロジック・取り消し不可の操作など影響度が高い場合、または後でバグを修正するよりも今検証する方が効率的な場合に活用してください。
apprun-skills
TypeScriptを使用したAppRunアプリケーションのMVU設計に関する総合的なガイダンスが得られます。コンポーネントパターン、イベントハンドリング、状態管理(非同期ジェネレータを含む)、パラメータと保護機能を備えたルーティング・ナビゲーション、vistestを使用したテストに対応しています。AppRunコンポーネントの設計・レビュー、ルートの配線、状態フローの管理、AppRunテストの作成時に活用してください。
desloppify
コードベースのヘルスチェックと技術負債の追跡ツールです。コード品質、技術負債、デッドコード、大規模ファイル、ゴッドクラス、重複関数、コードスメル、命名規則の問題、インポートサイクル、結合度の問題についてユーザーが質問した場合に使用してください。また、ヘルススコアの確認、次の改善項目の提案、クリーンアップ計画の作成をリクエストされた際にも対応します。29言語に対応しています。
debugging-and-error-recovery
テストが失敗したり、ビルドが壊れたり、動作が期待と異なったり、予期しないエラーが発生したりした場合に、体系的な根本原因デバッグをガイドします。推測ではなく、根本原因を見つけて修正するための体系的なアプローチが必要な場合に使用してください。
test-driven-development
テスト駆動開発により実装を進めます。ロジックの実装、バグの修正、動作の変更など、あらゆる場面で活用できます。コードが正常に動作することを証明する必要がある場合、バグ報告を受けた場合、既存機能を修正する予定がある場合に使用してください。
incremental-implementation
変更を段階的に実施します。複数のファイルに影響する機能や変更を実装する場合に使用してください。大量のコードを一度に書こうとしている場合や、タスクが一度では完結できないほど大きい場合に活用します。