|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + |
| 7 | + arazzoCmd "github.com/speakeasy-api/openapi/arazzo/cmd" |
| 8 | + openapiCmd "github.com/speakeasy-api/openapi/openapi/cmd" |
| 9 | + overlayCmd "github.com/speakeasy-api/openapi/overlay/cmd" |
| 10 | + "github.com/spf13/cobra" |
| 11 | +) |
| 12 | + |
| 13 | +var ( |
| 14 | + version = "dev" |
| 15 | +) |
| 16 | + |
| 17 | +var rootCmd = &cobra.Command{ |
| 18 | + Use: "openapi", |
| 19 | + Short: "OpenAPI toolkit for working with OpenAPI specifications, overlays, and Arazzo workflows", |
| 20 | + Long: `A comprehensive toolkit for working with OpenAPI specifications and Arazzo workflows. |
| 21 | +
|
| 22 | +This CLI provides tools for: |
| 23 | +
|
| 24 | +OpenAPI Specifications: |
| 25 | +- Validate OpenAPI specification documents for compliance |
| 26 | +- Upgrade OpenAPI specs to the latest supported version (3.1.1) |
| 27 | +- Inline all references to create self-contained documents |
| 28 | +- Bundle external references into components section while preserving structure |
| 29 | +
|
| 30 | +Arazzo Workflows: |
| 31 | +- Validate Arazzo workflow documents for compliance |
| 32 | +
|
| 33 | +OpenAPI Overlays: |
| 34 | +- Apply overlays to modify OpenAPI specifications |
| 35 | +- Compare two specifications and generate overlays |
| 36 | +- Validate overlay files for correctness |
| 37 | +
|
| 38 | +Each command group provides specialized functionality for working with different |
| 39 | +aspects of the OpenAPI ecosystem, from basic validation to advanced document |
| 40 | +transformation and workflow management.`, |
| 41 | + Version: version, |
| 42 | +} |
| 43 | + |
| 44 | +var overlayCmds = &cobra.Command{ |
| 45 | + Use: "overlay", |
| 46 | + Short: "Work with OpenAPI Overlays", |
| 47 | + Long: `Commands for working with OpenAPI Overlays. |
| 48 | +
|
| 49 | +OpenAPI Overlays provide a way to modify OpenAPI and Arazzo specifications |
| 50 | +without directly editing the original files. This is useful for: |
| 51 | +- Adding vendor-specific extensions |
| 52 | +- Modifying specifications for different environments |
| 53 | +- Applying transformations to third-party APIs`, |
| 54 | +} |
| 55 | + |
| 56 | +var openapiCmds = &cobra.Command{ |
| 57 | + Use: "openapi", |
| 58 | + Short: "Work with OpenAPI specifications", |
| 59 | + Long: `Commands for working with OpenAPI specifications. |
| 60 | +
|
| 61 | +OpenAPI specifications define REST APIs in a standard format. |
| 62 | +These commands help you validate and work with OpenAPI documents.`, |
| 63 | +} |
| 64 | + |
| 65 | +var arazzoCmds = &cobra.Command{ |
| 66 | + Use: "arazzo", |
| 67 | + Short: "Work with Arazzo workflow documents", |
| 68 | + Long: `Commands for working with Arazzo workflow documents. |
| 69 | +
|
| 70 | +Arazzo workflows describe sequences of API calls and their dependencies. |
| 71 | +These commands help you validate and work with Arazzo documents.`, |
| 72 | +} |
| 73 | + |
| 74 | +func init() { |
| 75 | + // Set version template |
| 76 | + rootCmd.SetVersionTemplate(`{{printf "%s" .Version}}`) |
| 77 | + |
| 78 | + // Add OpenAPI spec validation command |
| 79 | + openapiCmd.Apply(openapiCmds) |
| 80 | + |
| 81 | + // Add Arazzo workflow validation command |
| 82 | + arazzoCmd.Apply(arazzoCmds) |
| 83 | + |
| 84 | + // Add overlay subcommands using the Apply function |
| 85 | + overlayCmd.Apply(overlayCmds) |
| 86 | + |
| 87 | + // Add all commands to root |
| 88 | + rootCmd.AddCommand(openapiCmds) |
| 89 | + rootCmd.AddCommand(arazzoCmds) |
| 90 | + rootCmd.AddCommand(overlayCmds) |
| 91 | + |
| 92 | + // Global flags |
| 93 | + rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output") |
| 94 | +} |
| 95 | + |
| 96 | +func main() { |
| 97 | + if err := rootCmd.Execute(); err != nil { |
| 98 | + fmt.Fprintf(os.Stderr, "Error: %v\n", err) |
| 99 | + os.Exit(1) |
| 100 | + } |
| 101 | +} |
0 commit comments