From 8227cfe6ee9f2a18e68275c10d94ea777747e221 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Fri, 19 Jul 2024 23:10:50 +0100 Subject: [PATCH] CLOUDP-262703: Add x-xgen-sha flag to GenerateAtlasOpenApiSpecTool --- tools/cli/internal/cli/flag/flag.go | 1 + tools/cli/internal/cli/merge/merge.go | 8 ++++++++ tools/cli/internal/cli/usage/usage.go | 1 + 3 files changed, 10 insertions(+) diff --git a/tools/cli/internal/cli/flag/flag.go b/tools/cli/internal/cli/flag/flag.go index b42b20591..007d97a4d 100644 --- a/tools/cli/internal/cli/flag/flag.go +++ b/tools/cli/internal/cli/flag/flag.go @@ -26,4 +26,5 @@ const ( Spec = "spec" SpecShort = "s" Environment = "env" + GitSha = "sha" ) diff --git a/tools/cli/internal/cli/merge/merge.go b/tools/cli/internal/cli/merge/merge.go index d77747569..643b4d332 100644 --- a/tools/cli/internal/cli/merge/merge.go +++ b/tools/cli/internal/cli/merge/merge.go @@ -32,6 +32,7 @@ type Opts struct { basePath string outputPath string format string + gitSha string externalPaths []string } @@ -41,6 +42,12 @@ func (o *Opts) Run() error { return err } + if o.gitSha != "" { + federated.Info.Extensions = map[string]interface{}{ + "x-xgen-sha": o.gitSha, + } + } + federatedBytes, err := json.MarshalIndent(*federated, "", " ") if err != nil { return err @@ -97,6 +104,7 @@ func Builder() *cobra.Command { cmd.Flags().StringVarP(&opts.basePath, flag.Base, flag.BaseShort, "", usage.Base) cmd.Flags().StringArrayVarP(&opts.externalPaths, flag.External, flag.ExternalShort, nil, usage.External) + cmd.Flags().StringVar(&opts.gitSha, flag.GitSha, "", usage.GitSha) cmd.Flags().StringVarP(&opts.outputPath, flag.Output, flag.OutputShort, "", usage.Output) cmd.Flags().StringVarP(&opts.format, flag.Format, flag.FormatShort, "json", usage.Format) diff --git a/tools/cli/internal/cli/usage/usage.go b/tools/cli/internal/cli/usage/usage.go index 3c20b6cd3..19acaaa14 100644 --- a/tools/cli/internal/cli/usage/usage.go +++ b/tools/cli/internal/cli/usage/usage.go @@ -22,4 +22,5 @@ const ( Versions = "Boolean flag that defines wether to split the OAS into multiple versions." Spec = "Path to the OAS file." Environment = "Environment to consider when generating the versioned OAS." + GitSha = "GitSHA to use as identifier (x-xgen-sha) of the generated specification." )