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
# Analyze Command Guide

The `analyze` command examines your OpenAPI specification and generates example request configurations and data files.

## Quick Start

```bash
# Analyze default spec (specs/api.yaml)
mrapids analyze

# Analyze and generate all examples
mrapids analyze --all

# Analyze specific operation
mrapids analyze --operation CreateCustomer
```

## What It Does

1. **Parses** your OpenAPI/Swagger specification
2. **Validates** the spec structure
3. **Generates** example request configs in `requests/examples/`
4. **Creates** sample data files in `data/`
5. **Reports** statistics about your API

## Generated Files

### Request Configurations
`requests/examples/{operation-id}.yaml`

```yaml
# Auto-generated from specs/api.yaml
operation: CreateCustomer
method: POST
path: /v1/customers
description: Create a new customer
headers:
  Content-Type: application/json
  Accept: application/json
body: data/create-customer.json
expect:
  status: 200
```

### Data Files
`data/{operation-id}.json`

```json
{
  "email": "user@example.com",
  "name": "Jenny Rosen",
  "description": "Premium customer",
  "metadata": {
    "order_id": "order_123"
  }
}
```

## Command Options

### --operation / -o
Analyze specific operation only:
```bash
mrapids analyze --operation CreatePaymentIntent
mrapids analyze -o GetCustomer
```

### --output / -d
Custom output directory:
```bash
mrapids analyze --output ./generated
mrapids analyze -d /tmp/api-examples
```

### --all
Generate examples for all operations:
```bash
mrapids analyze --all
```
Without this flag, analyze shows statistics only.

### --skip-data
Skip generating data files:
```bash
mrapids analyze --all --skip-data
```
Useful when you only want request configs.

### --force / -f
Overwrite existing files:
```bash
mrapids analyze --all --force
```

### --cleanup-backups
Clean up backup directories (default: true):
```bash
mrapids analyze --all --cleanup-backups=false
```

## Examples

### Basic Analysis

```bash
mrapids analyze
```

Output:
```
🔍 Analyzing API specification...
📊 API: Stripe API (v1)
📁 Base URL: https://api.stripe.com

📈 Statistics:
  Total operations: 500
  GET:    250 operations
  POST:   200 operations  
  DELETE: 50 operations

✅ Ready to generate examples. Use --all or --operation <name>
```

### Generate All Examples

```bash
mrapids analyze --all
```

Output:
```
🔍 Analyzing API specification...
✨ Generating examples...

  ✅ Generated: requests/examples/get-balance.yaml
  ✅ Generated: requests/examples/create-customer.yaml
  ✅ Generated: requests/examples/update-customer.yaml
  ... 

📊 Summary:
  Generated 500 request examples
  Created 200 data files
  Skipped 0 (already exist)

Next steps:
  1. Review generated examples in requests/examples/
  2. Run an example: mrapids run requests/examples/create-customer.yaml
  3. Or use direct: mrapids run CreateCustomer
```

### Selective Generation

```bash
# Single operation
mrapids analyze --operation CreateSubscription

# Multiple operations
for op in CreateCustomer CreateSubscription CreateInvoice; do
  mrapids analyze --operation $op
done

# Pattern matching
mrapids list operations --filter payment --format simple | \
  cut -d' ' -f1 | \
  xargs -I {} mrapids analyze --operation {}
```

## Smart Example Generation

The analyzer generates realistic examples based on field names:

| Field Name | Generated Example |
|------------|------------------|
| `email` | `"user@example.com"` |
| `phone` | `"+14155551234"` |
| `name` | `"Jenny Rosen"` |
| `amount` | `2000` |
| `currency` | `"usd"` |
| `created` | `1640995200` |
| `url` | `"https://example.com/webhook"` |
| `description` | `"Premium subscription"` |

## Working with Generated Files

### Request Configurations

Execute directly:
```bash
mrapids run requests/examples/create-customer.yaml
```

Customize before running:
```bash
# Edit the generated file
vim requests/examples/create-customer.yaml

# Add custom headers, change data, etc.
mrapids run requests/examples/create-customer.yaml --env production
```

### Data Files

Use generated data:
```bash
# As-is
mrapids run CreateCustomer --file data/create-customer.json

# Modified
cp data/create-customer.json my-customer.json
# Edit my-customer.json
mrapids run CreateCustomer --file my-customer.json
```

## Advanced Usage

### Incremental Generation

```bash
# First, analyze to see what's available
mrapids analyze

# Generate examples for new operations only
mrapids analyze --all

# Force regenerate specific operation
mrapids analyze --operation UpdateCustomer --force
```

### Custom Templates

```bash
# Generate with custom output structure
mrapids analyze --all --output ./custom-examples

# Organize by method
for method in GET POST PUT DELETE; do
  mkdir -p examples/$method
  mrapids list operations --method $method --format simple | \
    cut -d' ' -f1 | \
    xargs -I {} mrapids analyze --operation {} --output examples/$method
done
```

### CI/CD Integration

```bash
#!/bin/bash
# ci-check-examples.sh

# Analyze and check if examples are up to date
mrapids analyze --all --output /tmp/examples

# Compare with committed examples
diff -r requests/examples /tmp/examples/requests/examples
if [ $? -ne 0 ]; then
  echo "Examples are out of date. Run: mrapids analyze --all"
  exit 1
fi
```

## Understanding the Output

### Request Configuration Structure

```yaml
# Auto-generated header
# Shows source and operation details

operation: CreatePaymentIntent    # OpenAPI operation ID
method: POST                     # HTTP method
path: /v1/payment_intents       # URL path
description: Create a payment   # From OpenAPI summary

headers:                        # Required headers
  Content-Type: application/json
  Accept: application/json

params:                         # Query parameters
  expand: ["latest_charge"]

body: data/create-payment-intent.json  # Request body reference

expect:                         # Expected response
  status: 200
  content_type: application/json
```

### Data File Structure

```json
{
  // Required fields with smart examples
  "amount": 2000,
  "currency": "usd",
  
  // Optional fields with realistic data
  "description": "Premium subscription",
  "metadata": {
    "order_id": "order_123"
  },
  
  // Arrays with example items
  "payment_method_types": ["card"]
}
```

## Tips & Best Practices

### 1. Initial Setup
```bash
# Full analysis after init
mrapids init api.yaml my-project
cd my-project
mrapids analyze --all
```

### 2. Keeping Examples Updated
```bash
# After API spec changes
git pull
mrapids analyze --all --force
git add requests/examples data/
git commit -m "Update examples for new API version"
```

### 3. Testing Workflows
```bash
# Generate examples for testing
mrapids analyze --operation CreateCustomer
mrapids run requests/examples/create-customer.yaml --dry-run
# Modify if needed
mrapids run requests/examples/create-customer.yaml --env test
```

### 4. Documentation
```bash
# Generate examples for docs
mrapids analyze --all --output docs/examples
# Include in documentation
```

## Troubleshooting

### No operations found
```bash
# Check spec location
ls specs/
mrapids analyze --spec ./path/to/openapi.yaml

# Validate spec
mrapids validate api.yaml
```

### Examples not generating
```bash
# Check permissions
ls -la requests/examples/

# Force regeneration
mrapids analyze --operation SomeOperation --force

# Check for errors in spec
mrapids analyze --operation SomeOperation --verbose
```

### Data files missing
```bash
# Some operations might not have request bodies
mrapids show OperationName

# Check if skipped
mrapids analyze --operation OperationName
# Look for "No request body" message
```

### Large APIs
```bash
# Generate in batches
mrapids list operations --format simple | \
  head -50 | \
  cut -d' ' -f1 | \
  xargs -I {} mrapids analyze --operation {}
```

## Integration with Other Commands

### Analyze → List → Run
```bash
# 1. Analyze API
mrapids analyze

# 2. List what was generated
mrapids list requests

# 3. Run examples
mrapids run requests/examples/get-balance.yaml
```

### Analyze → Show → Customize
```bash
# 1. Analyze operation
mrapids analyze --operation CreateSubscription

# 2. Understand it better
mrapids show CreateSubscription

# 3. Customize generated example
vim requests/examples/create-subscription.yaml
```