mrapids 0.1.31

Your OpenAPI, but executable
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# Init-Config Command Guide

The `init-config` command creates environment-specific configuration files with authentication, headers, and API settings.

## Quick Start

```bash
# Create development config
mrapids init-config

# Create production config with safety checks
mrapids init-config --env production

# Pre-configured for Stripe API
mrapids init-config --env production --api stripe
```

## What It Creates

```
config/
├── development.yaml    # Environment config
├── .env               # Environment variables (git-ignored)
└── .env.example       # Template for version control
```

## Basic Usage

### Default Development Config

```bash
mrapids init-config
```

Creates `config/development.yaml`:
```yaml
name: development

defaults:
  timeout: 30
  retry:
    enabled: true
    max_attempts: 3
    backoff: exponential

headers:
  User-Agent: "MicroRapid/1.0 (Development)"
  X-Environment: "development"

# Authentication section with examples for:
# - Bearer token
# - Basic auth  
# - API key
# - OAuth2
```

### Production Config

```bash
mrapids init-config --env production
```

Adds production-specific features:
```yaml
safety:
  require_confirmation: true    # Confirm destructive operations
  audit_log: true              # Log all requests
  dry_run_default: false

rate_limit:
  requests_per_second: 10
  burst: 20

monitoring:
  trace_id_header: X-Trace-ID
  log_requests: true
  log_responses: false         # Don't log sensitive data
```

## Pre-Configured APIs

### Stripe
```bash
mrapids init-config --env development --api stripe
```

Creates config with:
```yaml
apis:
  stripe:
    base_url: https://api.stripe.com/v1
    auth:
      type: bearer
      token: ${STRIPE_TEST_KEY}
    content_type: application/x-www-form-urlencoded
    timeout: 30
```

### GitHub
```bash
mrapids init-config --env production --api github
```

```yaml
apis:
  github:
    base_url: https://api.github.com
    auth:
      type: bearer
      token: ${GITHUB_TOKEN}
    headers:
      Accept: application/vnd.github.v3+json
```

### OpenAI
```bash
mrapids init-config --api openai
```

```yaml
apis:
  openai:
    base_url: https://api.openai.com/v1
    auth:
      type: bearer
      token: ${OPENAI_API_KEY}
    timeout: 60
```

### Custom API
```bash
mrapids init-config --api myapi
```

Creates generic template:
```yaml
apis:
  myapi:
    base_url: ${MYAPI_BASE_URL}
    auth:
      type: bearer
      token: ${MYAPI_API_KEY}
    content_type: application/json
```

## Command Options

### --env / -e
Environment name (affects defaults and safety settings):
```bash
mrapids init-config --env staging
mrapids init-config --env production
mrapids init-config --env test
```

### --api / -a
Pre-configure for specific API:
```bash
mrapids init-config --api stripe
mrapids init-config --api github
mrapids init-config --api openai
mrapids init-config --api custom-name
```

### --output / -o
Custom output path:
```bash
# Different directory
mrapids init-config --output ~/configs/prod.yaml --env production

# Different filename
mrapids init-config --output config/prod-stripe.yaml --env production --api stripe
```

### --force / -f
Overwrite existing config:
```bash
mrapids init-config --env development --force
```

## Environment Variables

### Created .env File

```bash
# Development environment
STRIPE_TEST_KEY=sk_test_...
GITHUB_TOKEN=ghp_...
API_USERNAME=your_username
API_PASSWORD=your_password
```

### .env.example Template

```bash
# Stripe Test Key (development/staging)
STRIPE_TEST_KEY=sk_test_...

# GitHub Personal Access Token
GITHUB_TOKEN=ghp_... or ghs_...

# Add more environment variables as needed
```

## Configuration Sections

### 1. Defaults
Global settings for all requests:
```yaml
defaults:
  timeout: 30                  # Request timeout in seconds
  output: pretty               # Output format
  retry:
    enabled: true
    max_attempts: 3
    backoff: exponential       # exponential, linear, constant
```

### 2. Headers
Applied to all requests:
```yaml
headers:
  User-Agent: "MicroRapid/1.0"
  X-Environment: "development"
  X-Request-ID: "${REQUEST_ID:auto}"
```

### 3. Authentication
Global auth (can be overridden per API):

#### Bearer Token
```yaml
auth:
  type: bearer
  token: ${API_TOKEN}
```

#### Basic Auth
```yaml
auth:
  type: basic
  username: ${API_USERNAME}
  password: ${API_PASSWORD}
```

#### API Key
```yaml
auth:
  type: api_key
  header: X-API-Key
  key: ${API_KEY}
```

#### OAuth2
```yaml
auth:
  type: oauth2
  client_id: ${CLIENT_ID}
  client_secret: ${CLIENT_SECRET}
  token_url: https://oauth.provider.com/token
```

### 4. Safety (Production)
```yaml
safety:
  require_confirmation: true    # Confirm DELETE, PUT, PATCH
  audit_log: true              # Log all operations
  dry_run_default: false
```

### 5. Rate Limiting
```yaml
rate_limit:
  requests_per_second: 10
  burst: 20                    # Allow bursts up to 20
```

### 6. Monitoring
```yaml
monitoring:
  trace_id_header: X-Trace-ID
  log_requests: true
  log_responses: false         # Careful with sensitive data
```

### 7. API-Specific Overrides
```yaml
apis:
  stripe:
    base_url: https://api.stripe.com/v1
    auth:
      type: bearer
      token: ${STRIPE_KEY}
    
  internal:
    base_url: https://api.internal.com
    auth:
      type: basic
      username: ${INTERNAL_USER}
      password: ${INTERNAL_PASS}
    headers:
      X-Internal-Version: "2.0"
```

## Usage Examples

### Multi-Environment Setup

```bash
# Create configs for each environment
mrapids init-config --env development --api stripe
mrapids init-config --env staging --api stripe
mrapids init-config --env production --api stripe --force

# Use different environments
mrapids run GetBalance --env development
mrapids run GetBalance --env staging
mrapids run GetBalance --env production
```

### Project Organization

```
project/
├── config/
│   ├── development.yaml
│   ├── staging.yaml
│   ├── production.yaml
│   ├── .env              # Local secrets (git-ignored)
│   └── .env.example      # Template for team
├── specs/
│   └── api.yaml
└── .gitignore            # Contains: config/.env
```

### Team Collaboration

1. Create configs:
```bash
mrapids init-config --env development
mrapids init-config --env staging
mrapids init-config --env production
```

2. Commit templates:
```bash
git add config/*.yaml config/.env.example
git commit -m "Add environment configs"
```

3. Team members copy and fill:
```bash
cp config/.env.example config/.env
# Edit .env with real values
```

## Advanced Configuration

### Multiple APIs per Environment

```yaml
name: development

# Global defaults
defaults:
  timeout: 30

# Different APIs with different auth
apis:
  stripe:
    base_url: https://api.stripe.com/v1
    auth:
      type: bearer
      token: ${STRIPE_TEST_KEY}
  
  github:
    base_url: https://api.github.com
    auth:
      type: bearer
      token: ${GITHUB_TOKEN}
  
  internal:
    base_url: http://localhost:8080
    auth:
      type: api_key
      header: X-API-Key
      key: ${INTERNAL_API_KEY}
```

### Environment-Specific Features

```yaml
# Development - verbose, no limits
name: development
defaults:
  timeout: 60
monitoring:
  log_requests: true
  log_responses: true

# Production - strict, monitored
name: production
safety:
  require_confirmation: true
rate_limit:
  requests_per_second: 10
monitoring:
  log_requests: true
  log_responses: false
```

### Dynamic Values

```yaml
headers:
  # Auto-generated request ID
  X-Request-ID: "${REQUEST_ID:auto}"
  
  # Timestamp
  X-Timestamp: "${TIMESTAMP:now}"
  
  # With defaults
  X-Client-Version: "${CLIENT_VERSION:1.0.0}"
```

## Best Practices

### 1. Security
- Never commit `.env` files
- Use environment-specific keys
- Rotate keys regularly
- Use read-only keys in development

### 2. Organization
```bash
# Clear naming
config/dev-stripe.yaml
config/prod-stripe.yaml
config/test-integration.yaml
```

### 3. Environment Variables
```bash
# Prefix by environment
STRIPE_TEST_KEY=sk_test_...
STRIPE_LIVE_KEY=sk_live_...

# Or by purpose
DEV_STRIPE_KEY=sk_test_...
PROD_STRIPE_KEY=sk_live_...
```

## Troubleshooting

### Config not found
```bash
# Check current directory
pwd
ls config/

# Specify path explicitly
mrapids run GetBalance --env development --config ./config/dev.yaml
```

### Environment variables not loading
```bash
# Check .env file exists
ls -la config/.env

# Debug mode
MRAPIDS_DEBUG=1 mrapids run GetBalance --env development

# Manual export
export STRIPE_TEST_KEY=sk_test_...
mrapids run GetBalance --env development
```

### Wrong config loaded
```bash
# Be explicit about environment
mrapids run GetBalance --env production

# Check which config is loaded
mrapids run GetBalance --env development --verbose
```