mrapids 0.1.7

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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
use clap::{Parser, Subcommand};
use std::path::PathBuf;

/// Global flags available to all commands
#[derive(Parser, Debug, Clone)]
pub struct GlobalOpts {
    /// Path to OpenAPI specification file or URL
    #[arg(long, global = true)]
    pub spec: Option<String>,
    
    /// Environment name (dev, staging, prod)
    #[arg(long, global = true)]
    pub env: Option<String>,
    
    /// Authentication profile name
    #[arg(long, global = true)]
    pub profile: Option<String>,
    
    /// Output format
    #[arg(long, global = true, value_enum)]
    pub output: Option<OutputFormat>,
    
    /// JSONPath expression to filter output
    #[arg(long, global = true)]
    pub select: Option<String>,
    
    /// Disable colored output
    #[arg(long, global = true)]
    pub no_color: bool,
    
    /// Suppress all output except errors
    #[arg(long, short, global = true)]
    pub quiet: bool,
    
    /// Enable verbose output
    #[arg(long, short, global = true)]
    pub verbose: bool,
    
    /// Enable trace output (includes HTTP requests/responses)
    #[arg(long, global = true)]
    pub trace: bool,
    
    /// Automatic yes to prompts
    #[arg(long, short, global = true)]
    pub yes: bool,
}

#[derive(Clone, Debug, PartialEq, Eq, clap::ValueEnum)]
pub enum OutputFormat {
    /// JSON output
    Json,
    /// YAML output
    Yaml,
    /// Table output
    Table,
    /// Human-readable output
    Pretty,
}

/// Exit codes for consistent scripting
pub mod exit_codes {
    pub const SUCCESS: i32 = 0;
    pub const UNKNOWN_ERROR: i32 = 1;
    pub const USAGE_ERROR: i32 = 2;
    pub const AUTH_ERROR: i32 = 3;
    pub const NETWORK_ERROR: i32 = 4;
    pub const RATE_LIMIT_ERROR: i32 = 5;
    pub const SERVER_ERROR: i32 = 6;
    pub const VALIDATION_ERROR: i32 = 7;
    pub const BREAKING_CHANGE: i32 = 8;
}

#[derive(Parser)]
#[command(name = "mrapids")]
#[command(about = "Your OpenAPI, but executable", long_about = None)]
#[command(version)]
pub struct Args {
    #[command(subcommand)]
    pub command: Commands,
    
    #[command(flatten)]
    pub global: GlobalOpts,
}

#[derive(Subcommand)]
pub enum Commands {
    /// Initialize a new MicroRapid project from an OpenAPI spec
    Init(InitCommand),
    
    /// Manage CLI configuration (create, view, edit)
    Config(ConfigCommand),
    
    /// Remove temporary files and test artifacts
    Cleanup(CleanupCommand),
    
    /// Validate an OpenAPI spec and lint for best practices
    Validate(ValidateCommand),
    
    /// Bundle/dereference a spec by resolving all $ref values
    Resolve(ResolveCommand),
    
    /// Compare two specs and report breaking changes
    Diff(DiffCommand),
    
    /// List operations, schemas, or components
    List(ListCommand),
    
    /// Show details for an operation or component
    Show(ShowCommand),
    
    /// Find operations, schemas, or examples by keyword
    Search(SearchCommand),
    
    /// Execute an API operation from the spec
    Run(RunCommand),
    
    /// Run contract tests derived from the spec
    Test(TestCommand),
    
    /// Test suite management
    Tests(TestsCommand),
    
    /// Generate code and artifacts
    Gen(GenCommand),
    
    /// Manage OAuth authentication
    Auth(AuthCommand),
    
    /// Show help for commands and topics
    Help(HelpCommand),
}

// Projects Commands

#[derive(Parser)]
pub struct InitCommand {
    /// Project name
    #[arg(default_value = "my-api-project")]
    pub name: String,
    
    /// Initialize from URL
    #[arg(long, value_name = "URL", conflicts_with = "from_file")]
    pub from: Option<String>,
    
    /// Initialize from local file
    #[arg(long, value_name = "FILE", conflicts_with = "from")]
    pub from_file: Option<String>,
    
    /// Project template
    #[arg(long, default_value = "rest")]
    pub template: String,
    
    /// Force overwrite
    #[arg(long)]
    pub force: bool,
}

#[derive(Parser)]
pub struct ConfigCommand {
    #[command(subcommand)]
    pub action: Option<ConfigAction>,
}

#[derive(Subcommand)]
pub enum ConfigAction {
    /// Set a configuration value
    Set {
        key: String,
        value: String,
        #[arg(long)]
        env: Option<String>,
    },
    /// Get a configuration value
    Get {
        key: String,
        #[arg(long)]
        env: Option<String>,
    },
    /// List all configuration
    List,
    /// Edit configuration interactively
    Edit {
        #[arg(long)]
        env: Option<String>,
    },
}

#[derive(Parser)]
pub struct CleanupCommand {
    /// Clean cache files
    #[arg(long)]
    pub cache: bool,
    
    /// Clean log files
    #[arg(long)]
    pub logs: bool,
    
    /// Clean all (except config)
    #[arg(long)]
    pub all: bool,
    
    /// Keep configuration files
    #[arg(long)]
    pub keep_config: bool,
    
    /// Preview what will be deleted
    #[arg(long)]
    pub dry_run: bool,
}

// Specs Commands

#[derive(Parser)]
pub struct ValidateCommand {
    /// Path to OpenAPI specification
    pub spec: Option<PathBuf>,
    
    /// Strict mode - treat warnings as errors
    #[arg(long)]
    pub strict: bool,
    
    /// Enable linting rules
    #[arg(long)]
    pub lint: bool,
    
    /// Custom rules file
    #[arg(long)]
    pub rules: Option<PathBuf>,
    
    /// Output format
    #[arg(long, value_enum)]
    pub format: Option<ValidateFormat>,
    
    /// Fail on level (warning, error)
    #[arg(long)]
    pub fail_on: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Eq, clap::ValueEnum)]
pub enum ValidateFormat {
    Text,
    Json,
}

#[derive(Parser)]
pub struct ResolveCommand {
    /// Input specification
    pub spec: Option<PathBuf>,
    
    /// Bundle into single file
    #[arg(long)]
    pub bundle: bool,
    
    /// Only resolve external references
    #[arg(long)]
    pub external_only: bool,
    
    /// Output file
    #[arg(long, short)]
    pub output: Option<PathBuf>,
    
    /// Specific path to resolve
    #[arg(long)]
    pub path: Option<String>,
    
    /// Validate after resolving
    #[arg(long)]
    pub validate: bool,
}

#[derive(Parser)]
pub struct DiffCommand {
    /// First specification (old/base)
    pub spec1: PathBuf,
    
    /// Second specification (new)
    pub spec2: PathBuf,
    
    /// Only show breaking changes
    #[arg(long)]
    pub breaking: bool,
    
    /// Output format
    #[arg(long, value_enum)]
    pub format: Option<DiffFormat>,
    
    /// Ignore description changes
    #[arg(long)]
    pub ignore_descriptions: bool,
    
    /// Fail on level
    #[arg(long)]
    pub fail_on: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Eq, clap::ValueEnum)]
pub enum DiffFormat {
    Text,
    Json,
    Markdown,
}

// Discoverability Commands

#[derive(Parser)]
pub struct ListCommand {
    #[command(subcommand)]
    pub resource: ListResource,
}

#[derive(Subcommand)]
pub enum ListResource {
    /// List operations
    Operations {
        spec: Option<PathBuf>,
        #[arg(long)]
        filter: Vec<String>,
    },
    /// List schemas
    Schemas {
        spec: Option<PathBuf>,
        #[arg(long)]
        filter: Vec<String>,
    },
    /// List examples
    Examples {
        spec: Option<PathBuf>,
    },
    /// List saved requests
    Requests,
}

#[derive(Parser)]
pub struct ShowCommand {
    /// Name of operation or component
    pub name: String,
    
    /// Specification file
    pub spec: Option<PathBuf>,
    
    /// Type of resource (operation, schema, example)
    #[arg(long, default_value = "operation")]
    pub r#type: String,
    
    /// Include examples
    #[arg(long)]
    pub examples: bool,
    
    /// Verbose output
    #[arg(long)]
    pub verbose: bool,
}

#[derive(Parser)]
pub struct SearchCommand {
    /// Search keyword
    pub keyword: String,
    
    /// Specification file
    pub spec: Option<PathBuf>,
    
    /// Search in descriptions
    #[arg(long)]
    pub in_descriptions: bool,
    
    /// Case sensitive search
    #[arg(long)]
    pub case_sensitive: bool,
    
    /// Search in specific areas
    #[arg(long, value_delimiter = ',')]
    pub r#in: Vec<String>,
}

// Execution Commands

#[derive(Parser)]
pub struct RunCommand {
    /// Specification file
    pub spec: Option<PathBuf>,
    
    /// Operation ID
    #[arg(long, group = "operation_select")]
    pub op_id: Option<String>,
    
    /// Operation path
    #[arg(long, requires = "method", group = "operation_select")]
    pub path: Option<String>,
    
    /// HTTP method
    #[arg(long, requires = "path")]
    pub method: Option<String>,
    
    /// Parameters as key=value
    #[arg(long = "param", value_name = "KEY=VALUE")]
    pub params: Vec<String>,
    
    /// Request body file
    #[arg(long)]
    pub body: Option<PathBuf>,
    
    /// Preview without executing
    #[arg(long)]
    pub dry_run: bool,
    
    /// Show as curl command
    #[arg(long)]
    pub curl_output: bool,
}

#[derive(Parser)]
pub struct TestCommand {
    /// Specification file
    pub spec: Option<PathBuf>,
    
    /// Operation ID to test
    #[arg(long)]
    pub op_id: Option<String>,
    
    /// Test all operations
    #[arg(long)]
    pub all: bool,
    
    /// Test from file
    #[arg(long)]
    pub from: Option<PathBuf>,
    
    /// Validate responses
    #[arg(long)]
    pub validate: bool,
    
    /// Load test iterations
    #[arg(long)]
    pub load: Option<u32>,
    
    /// Concurrent requests
    #[arg(long)]
    pub concurrent: Option<u32>,
    
    /// Test report output
    #[arg(long)]
    pub report: Option<PathBuf>,
    
    /// Output format
    #[arg(long)]
    pub format: Option<TestFormat>,
    
    /// Fail on level
    #[arg(long)]
    pub fail_on: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Eq, clap::ValueEnum)]
pub enum TestFormat {
    Text,
    Json,
    Junit,
}

#[derive(Parser)]
pub struct TestsCommand {
    #[command(subcommand)]
    pub action: TestsAction,
}

#[derive(Subcommand)]
pub enum TestsAction {
    /// Scaffold a test suite from the spec
    Init {
        spec: Option<PathBuf>,
        #[arg(long)]
        framework: Option<String>,
        #[arg(long)]
        with_ci: Option<String>,
        #[arg(long, short)]
        output: Option<PathBuf>,
    },
}

// Generation Commands

#[derive(Parser)]
pub struct GenCommand {
    #[command(subcommand)]
    pub target: GenTarget,
}

#[derive(Subcommand)]
pub enum GenTarget {
    /// Generate example requests and payloads
    Snippets {
        spec: Option<PathBuf>,
        #[arg(long)]
        op_id: Option<String>,
        #[arg(long, value_enum)]
        format: Option<SnippetFormat>,
        #[arg(long, short)]
        output: Option<PathBuf>,
    },
    /// Generate an SDK in the selected language
    Sdk {
        spec: Option<PathBuf>,
        #[arg(long, value_delimiter = ',')]
        lang: Vec<String>,
        #[arg(long)]
        package: Option<String>,
        #[arg(long)]
        with_docs: bool,
        #[arg(long)]
        template: Option<PathBuf>,
    },
    /// Generate server stubs
    Stubs {
        spec: Option<PathBuf>,
        #[arg(long)]
        framework: String,
        #[arg(long)]
        with_tests: bool,
        #[arg(long, short)]
        output: Option<PathBuf>,
    },
    /// Generate sample requests/responses as files
    Fixtures {
        spec: Option<PathBuf>,
        #[arg(long)]
        schema: Vec<String>,
        #[arg(long)]
        count: Option<u32>,
        #[arg(long)]
        seed: Option<u64>,
        #[arg(long, value_enum)]
        format: Option<FixtureFormat>,
    },
}

#[derive(Clone, Debug, PartialEq, Eq, clap::ValueEnum)]
pub enum SnippetFormat {
    Curl,
    Httpie,
    Fetch,
    Axios,
    Requests,
}

#[derive(Clone, Debug, PartialEq, Eq, clap::ValueEnum)]
pub enum FixtureFormat {
    Json,
    Yaml,
}

// Auth Commands

#[derive(Parser)]
pub struct AuthCommand {
    #[command(subcommand)]
    pub action: AuthAction,
}

#[derive(Subcommand)]
pub enum AuthAction {
    /// OAuth login flow
    Login {
        provider: String,
        #[arg(long)]
        scopes: Option<String>,
        #[arg(long)]
        auth_url: Option<String>,
    },
    /// Remove credentials
    Logout {
        provider: Option<String>,
        #[arg(long)]
        all: bool,
        #[arg(long)]
        force: bool,
    },
    /// Show auth status
    Status {
        provider: Option<String>,
        #[arg(long)]
        test: bool,
    },
}

#[derive(Parser)]
pub struct HelpCommand {
    /// Command to show help for
    pub command: Option<String>,
}