### Install and Run
Source: https://github.com/opencollection-dev/opencollection/blob/main/packages/oc-spec-site/readme.md
Commands to install dependencies and start the development server.
```bash
npm install
npm run dev
```
--------------------------------
### Example: Changing Font Sizes
Source: https://github.com/opencollection-dev/opencollection/blob/main/packages/oc-spec-site/src/theme/README.md
Shows how to adjust font sizes for headings in the theme configuration.
```javascript
// In src/theme/index.js
typography: {
heading: {
h2: 'text-3xl font-bold mb-6', // Larger h2
h3: 'text-xl font-semibold mb-4' // Larger h3
}
}
```
--------------------------------
### Example: Changing Primary Color
Source: https://github.com/opencollection-dev/opencollection/blob/main/packages/oc-spec-site/src/theme/README.md
Demonstrates how to change the primary color configuration in src/theme/index.js.
```javascript
// In src/theme/index.js
primary: {
text: 'text-indigo-600', // Changed from blue to indigo
bg: 'bg-indigo-600',
hover: 'hover:bg-indigo-700',
light: 'bg-indigo-50',
lightText: 'text-indigo-800'
}
```
--------------------------------
### Development Commands
Source: https://github.com/opencollection-dev/opencollection/blob/main/packages/oc-schema-explorer/readme.md
Commands to install dependencies and start the development server.
```bash
npm install
npm run dev
```
--------------------------------
### Example Protobuf Configuration
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
A JSON example demonstrating how to configure Protobuf files and import paths.
```json
{
"protoFiles": [
{
"type": "file",
"path": "./proto/user_service.proto"
},
{
"type": "file",
"path": "./proto/order_service.proto"
}
],
"importPaths": [
{
"path": "./proto",
"disabled": false
},
{
"path": "./third_party/proto",
"disabled": false
}
]
}
```
--------------------------------
### Example Proxy Configuration
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
A JSON example demonstrating how to configure proxy settings.
```json
{
"disabled": false,
"inherit": false,
"config": {
"protocol": "http",
"hostname": "proxy.example.com",
"port": 8080,
"auth": {
"username": "proxyuser",
"password": "proxypass"
},
"bypassProxy": "localhost,127.0.0.1"
}
}
```
--------------------------------
### Example Variable Configuration
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
An example of a simple variable configuration.
```json
{
"name": "userId",
"value": "12345",
"description": "User ID for API calls"
}
```
--------------------------------
### Access theme values
Source: https://github.com/opencollection-dev/opencollection/blob/main/packages/oc-spec-site/src/theme/README.md
Example of accessing theme values like typography, colors, and spacing within a component.
```javascript
function MyComponent() {
const theme = useTheme();
const { typography, colors, spacing } = theme;
return (
My Heading
);
}
```
--------------------------------
### Example Scripts
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
A JSON array showing examples of scripts for different phases like 'before-request', 'after-response', and 'tests'.
```json
[
{
"type": "before-request",
"code": "req.setHeader('X-Request-ID', generateUUID());"
},
{
"type": "after-response",
"code": "res.setVar('token', res.body.data.accessToken);"
},
{
"type": "tests",
"code": "test('Status is 200', () => { expect(res.status).toBe(200); });"
}
]
```
--------------------------------
### Example Assertions
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
JSON array representing example assertions with expression, operator, value, and description.
```json
[{"expression": "res.status", "operator": "eq", "value": "200", "description": "Successful response"}, {"expression": "res.body.data.id", "operator": "gt", "value": "0", "description": "Response contains valid ID"}, {"expression": "res.headers['content-type']", "operator": "contains", "value": "application/json"}]
```
--------------------------------
### Example Actions
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
JSON array demonstrating an example of a 'set-variable' action, specifying its phase, selector, and target variable.
```json
[{"type": "set-variable", "phase": "after-response", "selector": {"expression": "res.body.data.sessionToken", "method": "jsonq"}, "variable": {"name": "sessionToken", "scope": "collection"}}]
```
--------------------------------
### Example Client Certificate Configuration
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
A JSON example for configuring a client certificate using the PEM format.
```json
{
"domain": "api.example.com",
"type": "pem",
"certificateFilePath": "/certs/client-cert.pem",
"privateKeyFilePath": "/certs/client-key.pem",
"passphrase": "certificate_password"
}
```
--------------------------------
### Import the useTheme hook
Source: https://github.com/opencollection-dev/opencollection/blob/main/packages/oc-spec-site/src/theme/README.md
Import the necessary hook from the theme provider.
```javascript
import { useTheme } from '../theme/ThemeProvider'
import { cn } from '../theme'
```
--------------------------------
### Parameter Examples
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
A JSON array demonstrating examples of HTTP request parameters, including query and path types.
```json
[
{ "name": "page", "value": "1", "type": "query", "description": "Page number" },
{ "name": "limit", "value": "10", "type": "query" },
{ "name": "userId", "value": "{{userId}}", "type": "path" }
]
```
--------------------------------
### Example Variable with Variants
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
An example of a variable with multiple named variants.
```json
{
"name": "environment",
"value": [
{
"title": "Development",
"selected": true,
"value": "dev"
},
{
"title": "Staging",
"value": "staging"
},
{
"title": "Production",
"value": "prod"
}
]
}
```
--------------------------------
### Example Inheritance
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
Demonstrates how configuration settings can be inherited at different levels within a collection.
```json
{
"request": {
"auth": {
"type": "bearer",
"token": "{{globalToken}}"
},
"headers": [
{ "name": "X-API-Version", "value": "2.0" }
]
},
"items": [
{
"type": "folder",
"name": "Users",
"request": {
"headers": [
{ "name": "X-Module", "value": "users" }
]
},
"items": [
{
"info": { "name": "Get User" },
"http": {
"method": "GET",
"url": "/users/:id"
},
"settings": {
"timeout": "inherit"
}
}
]
}
]
}
```
--------------------------------
### cn() Helper Function Usage
Source: https://github.com/opencollection-dev/opencollection/blob/main/packages/oc-spec-site/src/theme/README.md
Example of using the cn() utility function for combining CSS class names.
```javascript
```
--------------------------------
### Common Headers Example
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
A JSON array providing examples of common HTTP request headers.
```json
[
{ "name": "Content-Type", "value": "application/json" },
{ "name": "Accept", "value": "application/json" },
{ "name": "Authorization", "value": "Bearer {{token}}" },
{ "name": "User-Agent", "value": "MyApp/1.0" }
]
```
--------------------------------
### Example Secret Variable Configuration
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
An example of a secret variable configuration.
```json
{
"name": "apiKey",
"secret": true,
"type": "string"
}
```
--------------------------------
### Input Schema Example
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/api-reference/converters.md
Provides an example of the expected structure for the `brunoCollection` parameter in the `brunoToOpenCollection` function.
```javascript
{
name: string,
root?: {
docs?: string,
request?: {
url?: string,
method?: string,
headers?: Array<{ name, value, enabled? }>,
params?: Array<{ name, value, type? }>,
body?: BodyObject,
auth?: AuthObject,
vars?: { req?: Array
},
script?: { req?: string, res?: string },
assertions?: Array
}
},
environments?: Array<{
filename: string,
variables?: Array
}>,
items?: Array-
}
Where Item can be:
- HTTP Request: `{ type: 'http-request', name, request: {...} }`
- GraphQL Request: `{ type: 'graphql-request', name, ... }`
- Folder: `{ type: 'folder', name, items: Array
- , ... }`
```
--------------------------------
### HttpRequestExample
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/types.md
Example request/response pair for documentation.
```typescript
interface HttpRequestExample {
name?: string;
description?: Description;
request?: HttpRequestExampleRequest;
response?: HttpRequestExampleResponse;
}
interface HttpRequestExampleRequest {
url?: string;
method?: string;
headers?: HttpRequestHeader[];
params?: HttpRequestParam[];
body?: HttpRequestBody;
}
interface HttpRequestExampleResponse {
status?: number;
statusText?: string;
headers?: HttpResponseHeader[];
body?: HttpRequestExampleResponseBody;
}
interface HttpRequestExampleResponseBody {
type: 'json' | 'text' | 'xml' | 'html' | 'binary';
data: string;
}
```
--------------------------------
### OpenCollection Initialization
Source: https://github.com/opencollection-dev/opencollection/blob/main/examples/standalone-html/index2.html
Initializes OpenCollection within a specified HTML container using a sample collection configuration.
```javascript
const container = document.getElementById('opencollection-container');
new window.OpenCollection({
target: container,
opencollection: sampleCollection,
theme: 'light'
});
```
--------------------------------
### Example Collection Metadata
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
JSON object representing example collection metadata, including name, summary, version, and author details.
```json
{
"name": "My API",
"summary": "Documentation for My API",
"version": "2.1.0",
"authors": [
{
"name": "John Doe",
"email": "john@example.com",
"url": "https://johndoe.com"
}
]
}
```
--------------------------------
### Schema Extension Example
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/api-reference/schema.md
Example of extending the OpenCollection schema with a custom property.
```javascript
const customSchema = {
...OpenCollectionSchema,
properties: {
...OpenCollectionSchema.properties,
"x-custom": { type: "object" }
}
};
```
--------------------------------
### Authentication Inheritance Configuration
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/configuration.md
Example of how to inherit authentication settings from a parent scope.
```typescript
// Inherit authentication from parent scope
auth: 'inherit'
```
--------------------------------
### Authentication Conversion Example
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/api-reference/converters.md
Demonstrates the conversion of Bruno's 'basic' authentication mode to OpenCollection's equivalent.
```javascript
// Bruno basic auth
{
mode: "basic",
basic: {
username: "user@example.com",
password: "mypassword"
}
}
// OpenCollection
{
type: "basic",
username: "user@example.com",
password: "mypassword"
}
```
--------------------------------
### Error Handling Example
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/api-reference/converters.md
Shows how to use a try-catch block to handle potential errors during the `brunoToOpenCollection` conversion process.
```javascript
try {
const result = brunoToOpenCollection(null);
} catch (error) {
console.error(error.message); // "Bruno collection is required"
}
```
--------------------------------
### Sample OpenCollection Configuration
Source: https://github.com/opencollection-dev/opencollection/blob/main/examples/standalone-html/index.html
This YAML defines a sample API collection with various HTTP requests, folders, environments, and variables.
```yaml
name: Sample API Collection
description: A comprehensive OpenCollection demonstration showcasing various API endpoints and configurations
items:
- type: http
name: Get Users
method: GET
url: https://jsonplaceholder.typicode.com/users
docs: Retrieves a list of all users from the JSONPlaceholder API
headers:
- name: Accept
value: application/json
- name: User-Agent
value: OpenCollection-Playground/1.0
params:
- name: limit
value: "10"
type: query
enabled: true
- type: http
name: Create User
method: POST
url: https://jsonplaceholder.typicode.com/users
docs: Creates a new user in the system
headers:
- name: Content-Type
value: application/json
body:
type: json
data: |
{
"name": "John Doe",
"email": "john@example.com",
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org"
}
auth:
type: bearer
token: your-api-token-here
- type: http
name: Update User
method: PUT
url: https://jsonplaceholder.typicode.com/users/1
docs: Updates an existing user by ID
headers:
- name: Content-Type
value: application/json
body:
type: json
data: |
{
"name": "Jane Doe",
"email": "jane@example.com"
}
- type: http
name: Delete User
method: DELETE
url: https://jsonplaceholder.typicode.com/users/1
docs: Deletes a user by ID
- type: folder
name: Posts
items:
- type: http
name: Get All Posts
method: GET
url: https://jsonplaceholder.typicode.com/posts
docs: Retrieves all blog posts
- type: http
name: Get Post by ID
method: GET
url: https://jsonplaceholder.typicode.com/posts/1
docs: Retrieves a specific post by its ID
params:
- name: id
value: "1"
type: path
enabled: true
- type: http
name: Create Post
method: POST
url: https://jsonplaceholder.typicode.com/posts
docs: Creates a new blog post
headers:
- name: Content-Type
value: application/json
body:
type: json
data: |
{
"title": "My New Post",
"body": "This is the content of my new post",
"userId": 1
}
- type: folder
name: People
items:
- type: http
name: Get All Posts
method: GET
url: https://jsonplaceholder.typicode.com/posts
docs: Retrieves all blog posts
- type: http
name: Get Post by ID
method: GET
url: https://jsonplaceholder.typicode.com/posts/1
docs: Retrieves a specific post by its ID
params:
- name: id
value: "1"
type: path
enabled: true
- type: http
name: Create Post
method: POST
url: https://jsonplaceholder.typicode.com/posts
docs: Creates a new blog post
headers:
- name: Content-Type
value: application/json
body:
type: json
data: |
{
"title": "My New Post",
"body": "This is the content of my new post",
"userId": 1
}
environments:
- name: Production
description: Production environment configuration
variables:
- name: baseUrl
value: https://api.example.com
- name: apiKey
value: prod-api-key-here
- name: Development
description: Development environment for testing
variables:
- name: baseUrl
value: http://localhost:3000
- name: apiKey
value: dev-api-key-here
- name: Staging
description: Staging environment for QA testing
variables:
- name: baseUrl
value: https://staging-api.example.com
- name: apiKey
value: staging-api-key-here
base:
headers:
- name: Accept
value: application/json
- name: User-Agent
value: OpenCollection/1.0
variables:
- name: timeout
value: "30000"
docs: This is a sample OpenCollection that demonstrates various features including HTTP requests, folders, scripts, environments, and authentication methods. It uses the JSONPlaceholder API for testing purposes.
```
--------------------------------
### Example Usage of OpenCollection
Source: https://github.com/opencollection-dev/opencollection/blob/main/_autodocs/api-reference/opencollection-types.md
Demonstrates how to create an OpenCollection object with basic information and items.
```typescript
import type { OpenCollection } from '@opencollection/types';
const collection: OpenCollection = {
info: {
name: "My API",
version: "1.0.0"
},
opencollection: "0.9.2",
items: [
{
info: { name: "Get User", type: "http" },
http: {
method: "GET",
url: "https://api.example.com/users/:id"
}
}
]
};
```
--------------------------------
### OpenCollection Standalone HTML Example
Source: https://github.com/opencollection-dev/opencollection/blob/main/examples/standalone-html/index2.html
This code snippet shows a basic HTML structure with embedded OpenCollection data.
```html
OpenCollection Standalone Example