npm package: @gyeonghokim/bruno-to-openapi
Description: Convert Bruno API collections to OpenAPI 3.0 specification
Author: GyeongHo Kim
Latest version: 1.2.0

# Bruno to OpenAPI

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.

## Installation

Install the package using npm:

```bash
npm install @gyeonghokim/bruno-to-openapi
```

## Get Started

Once 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.

### JSON Export (Async)

```javascript
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();
```

### YAML Export (Async)

To export as YAML, you can use the `js-yaml` library along with this package:

```bash
npm install js-yaml
```

```javascript
import { 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();
```

### JSON Export (Sync)

```javascript
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();
```

### YAML Export (Sync)

```javascript
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();
```

## Features

- 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

## API Reference

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.

## Contributing

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.

## License

This project is licensed under the MIT License.