← back to Cli Printing Press
feat(cli): auto-detect OpenAPI vs internal spec format
600091039e1c28a28c253db682dfa86c8f1f71d1 · 2026-03-23 10:29:24 -0700 · Matt Van Horn
The generate command now reads the file first and checks for 'openapi:'
key to route to the OpenAPI parser or internal YAML parser automatically.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Files touched
Diff
commit 600091039e1c28a28c253db682dfa86c8f1f71d1
Author: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Date: Mon Mar 23 10:29:24 2026 -0700
feat(cli): auto-detect OpenAPI vs internal spec format
The generate command now reads the file first and checks for 'openapi:'
key to route to the OpenAPI parser or internal YAML parser automatically.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---
internal/cli/root.go | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/internal/cli/root.go b/internal/cli/root.go
index 6d45eee1..2bb2f109 100644
--- a/internal/cli/root.go
+++ b/internal/cli/root.go
@@ -6,6 +6,7 @@ import (
"path/filepath"
"github.com/mvanhorn/cli-printing-press/internal/generator"
+ "github.com/mvanhorn/cli-printing-press/internal/openapi"
"github.com/mvanhorn/cli-printing-press/internal/spec"
"github.com/spf13/cobra"
)
@@ -41,7 +42,17 @@ func newGenerateCmd() *cobra.Command {
return fmt.Errorf("--spec is required")
}
- apiSpec, err := spec.Parse(specFile)
+ data, err := os.ReadFile(specFile)
+ if err != nil {
+ return fmt.Errorf("reading spec file: %w", err)
+ }
+
+ var apiSpec *spec.APISpec
+ if openapi.IsOpenAPI(data) {
+ apiSpec, err = openapi.Parse(data)
+ } else {
+ apiSpec, err = spec.ParseBytes(data)
+ }
if err != nil {
return fmt.Errorf("parsing spec: %w", err)
}
@@ -70,7 +81,7 @@ func newGenerateCmd() *cobra.Command {
},
}
- cmd.Flags().StringVar(&specFile, "spec", "", "Path to API spec YAML file (required)")
+ cmd.Flags().StringVar(&specFile, "spec", "", "Path to API spec (internal YAML or OpenAPI 3.0+)")
cmd.Flags().StringVar(&outputDir, "output", "", "Output directory (default: <name>-cli)")
cmd.Flags().BoolVar(&validate, "validate", true, "Run quality gates on the generated project")
← e81fc872 feat(openapi): add OpenAPI 3.0+ parser with kin-openapi
·
back to Cli Printing Press
·
feat(openapi): integration tests + oneline template fix for 6011234c →