Skip to content

Commit 4654fa9

Browse files
author
Bruce Hill
committed
Make sure we actually download OAS
1 parent 53b731a commit 4654fa9

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

pkg/cmd/init.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"io/fs"
87
"os"
@@ -505,6 +504,7 @@ func downloadConfigFiles(ctx context.Context, client stainless.Client, config Wo
505504
group := Info("Downloading Stainless config...")
506505
params := stainless.ProjectConfigGetParams{
507506
Project: stainless.String(config.Project),
507+
Include: stainless.String("openapi"),
508508
}
509509

510510
configRes, err := client.Projects.Configs.Get(ctx, params)
@@ -542,29 +542,25 @@ func downloadConfigFiles(ctx context.Context, client stainless.Client, config Wo
542542
}
543543

544544
{
545-
response, err := client.Spec.GetDecoratedSpec(
546-
ctx,
547-
config.Project,
548-
stainless.SpecGetDecoratedSpecParams{
549-
ClientID: defaultClientID,
550-
},
551-
)
552-
if err != nil {
553-
return err
554-
}
555-
556-
bytes, err := json.Marshal(response)
557-
if err != nil {
558-
return err
545+
var specContent []byte
546+
if try, ok := (*configRes)["openapi.json"]; ok {
547+
specContent = []byte(try.Content)
548+
} else if try, ok := (*configRes)["openapi.yml"]; ok {
549+
specContent = []byte(try.Content)
550+
} else if try, ok := (*configRes)["openapi.yaml"]; ok {
551+
specContent = []byte(try.Content)
552+
} else {
553+
return fmt.Errorf("could not find OpenAPI specification in response")
559554
}
555+
fmt.Printf("OAS:\n%s\n\n", string(specContent))
560556

561557
// Create parent directories if they don't exist
562558
dir := filepath.Dir(config.OpenAPISpec)
563559
if err := os.MkdirAll(dir, 0755); err != nil {
564560
return fmt.Errorf("failed to create directory for config file: %w", err)
565561
}
566562

567-
err = os.WriteFile(config.OpenAPISpec, bytes, 0644)
563+
err = os.WriteFile(config.OpenAPISpec, specContent, 0644)
568564
if err != nil {
569565
group.Error("Failed to save project config to %s: %v", config.OpenAPISpec, err)
570566
return fmt.Errorf("OpenAPI specification could not write to file: %v", err)

0 commit comments

Comments
 (0)