@@ -29,6 +29,7 @@ import (
2929 "time"
3030
3131 "github.com/getkin/kin-openapi/openapi3"
32+ "github.com/mongodb/mongodb-atlas-cli/atlascli/tools/internal/metadatatypes"
3233 "github.com/spf13/cobra"
3334)
3435
@@ -91,25 +92,29 @@ func run(ctx context.Context, specPath string, outputType OutputType, w io.Write
9192 defer specFile .Close ()
9293 }
9394
95+ now := time .Now ()
96+
9497 switch outputType {
9598 case Commands :
96- return convertSpecToAPICommands (ctx , spec , w )
99+ return convertSpecToAPICommands (ctx , now , spec , w )
97100 case Metadata :
98- return convertSpecToMetadata (ctx , spec , w )
101+ return convertSpecToMetadata (ctx , now , spec , w )
99102 default :
100103 return fmt .Errorf ("'%s' is not a valid outputType" , outputType )
101104 }
102105}
103106
104- func convertSpecToAPICommands (ctx context.Context , r io.Reader , w io.Writer ) error {
105- return convertSpec (ctx , r , w , specToCommands , commandsTemplateContent )
107+ func convertSpecToAPICommands (ctx context.Context , now time. Time , r io.Reader , w io.Writer ) error {
108+ return convertSpec (ctx , now , r , w , specToCommands , commandsTemplateContent )
106109}
107110
108- func convertSpecToMetadata (ctx context.Context , r io.Reader , w io.Writer ) error {
109- return convertSpec (ctx , r , w , specToMetadata , metadataTemplateContent )
111+ func convertSpecToMetadata (ctx context.Context , now time.Time , r io.Reader , w io.Writer ) error {
112+ return convertSpec (ctx , now , r , w , func (_ time.Time , spec * openapi3.T ) (metadatatypes.Metadata , error ) {
113+ return specToMetadata (spec )
114+ }, metadataTemplateContent )
110115}
111116
112- func convertSpec [T any ](ctx context.Context , r io.Reader , w io.Writer , mapper func (spec * openapi3.T ) (T , error ), templateContent string ) error {
117+ func convertSpec [T any ](ctx context.Context , now time. Time , r io.Reader , w io.Writer , mapper func (now time. Time , spec * openapi3.T ) (T , error ), templateContent string ) error {
113118 spec , err := loadSpec (r )
114119 if err != nil {
115120 return fmt .Errorf ("failed to load spec, error: %w" , err )
@@ -121,7 +126,7 @@ func convertSpec[T any](ctx context.Context, r io.Reader, w io.Writer, mapper fu
121126 }
122127 }
123128
124- commands , err := mapper (spec )
129+ commands , err := mapper (now , spec )
125130 if err != nil {
126131 return fmt .Errorf ("failed convert spec to api commands: %w" , err )
127132 }
0 commit comments