Convert Bruno collections to OpenAPI specifications with ease. This library provides a simple way to transform Bruno collection directories into standardized OpenAPI 3.x specifications.
Install the package using npm:
npm install @gyeonghokim/bruno-to-openapiOnce installed, you can use the library to convert your Bruno collections to OpenAPI specifications. Below are examples showing how to export to both JSON and YAML formats.
import { convertBrunoCollectionToOpenAPI } from '@gyeonghokim/bruno-to-openapi';
import fs from 'fs';
async function convertCollection() {
// Convert Bruno collection directory to OpenAPI specification
const result = await convertBrunoCollectionToOpenAPI('./path-to-your-bruno-collection-directory');
// Save as JSON file
fs.writeFileSync('openapi-spec.json', JSON.stringify(result.spec, null, 2));
console.log('OpenAPI specification saved as openapi-spec.json');
}
convertCollection();To export as YAML, you can use the js-yaml library along with this package:
npm install js-yamlimport { convertBrunoCollectionToOpenAPI } from '@gyeonghokim/bruno-to-openapi';
import yaml from 'js-yaml';
import fs from 'fs';
async function convertCollection() {
// Convert Bruno collection directory to OpenAPI specification
const result = await convertBrunoCollectionToOpenAPI('./path-to-your-bruno-collection-directory');
// Convert to YAML and save
const yamlString = yaml.dump(result.spec, { indent: 2 });
fs.writeFileSync('openapi-spec.yaml', yamlString);
console.log('OpenAPI specification saved as openapi-spec.yaml');
}
convertCollection();import { convertBrunoCollectionToOpenAPISync } from '@gyeonghokim/bruno-to-openapi';
import fs from 'fs';
function convertCollection() {
// Convert Bruno collection directory to OpenAPI specification synchronously
const result = convertBrunoCollectionToOpenAPISync('./path-to-your-bruno-collection-directory');
// Save as JSON file
fs.writeFileSync('openapi-spec.json', JSON.stringify(result.spec, null, 2));
console.log('OpenAPI specification saved as openapi-spec.json');
}
convertCollection();import { convertBrunoCollectionToOpenAPISync } from '@gyeonghokim/bruno-to-openapi';
import yaml from 'js-yaml';
import fs from 'fs';
function convertCollection() {
// Convert Bruno collection directory to OpenAPI specification synchronously
const result = convertBrunoCollectionToOpenAPISync('./path-to-your-bruno-collection-directory');
// Convert to YAML and save
const yamlString = yaml.dump(result.spec, { indent: 2 });
fs.writeFileSync('openapi-spec.yaml', yamlString);
console.log('OpenAPI specification saved as openapi-spec.yaml');
}
convertCollection();- Converts Bruno collections to OpenAPI 3.x specifications
- Supports all common HTTP methods and parameters
- Handles authentication configurations
- Preserves request/response examples
- Maintains folder structures as tags
- Supports both JSON and YAML output formats
- Provides synchronous and asynchronous conversion options
- Includes collection validation utilities
The library exports the following functions:
convertBrunoCollectionToOpenAPI(collectionPath): Asynchronously takes a Bruno collection directory path and returns a Promise resolving to the conversion result containing the OpenAPI specification.convertBrunoCollectionToOpenAPISync(collectionPath): Synchronously takes a Bruno collection directory path and returns the conversion result containing the OpenAPI specification (Note: The full synchronous implementation has limitations and it's recommended to use the async version).isValidBrunoCollection(collectionPath): Asynchronously validates if a given path contains a valid Bruno collection and returns a Promise resolving to true if valid.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License.