Skip to content

Commit 9f908f1

Browse files
feat: sdkjson generation API
1 parent 79e1b7f commit 9f908f1

File tree

3 files changed

+85
-4
lines changed

3 files changed

+85
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 15
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/stainless%2Fstainless-v0-2b3066c21238e834fda5197e6afbbfaaf41e189a1cc9b3c14a892b90d5a209ba.yml
3-
openapi_spec_hash: 96d0b5cd724b242a0943129fdc79bdca
4-
config_hash: 6ae0d102d10842637680db3e63e42c51
1+
configured_endpoints: 16
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/stainless%2Fstainless-v0-345f2d483473fda78e89643698c6084bbd6fe9b565044aa79ad1b21e6bdf4e09.yml
3+
openapi_spec_hash: 6780cb3fbff80ca1791cac9f073019ca
4+
config_hash: c58db8da40317675e32d76f495a132e2

pkg/cmd/cmd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ var Command = cli.Command{
8282
&orgsList,
8383
},
8484
},
85+
86+
{
87+
Name: "generate",
88+
Commands: []*cli.Command{
89+
&generateCreateSpec,
90+
},
91+
},
8592
},
8693
EnableShellCompletion: true,
8794
HideHelpCommand: true,

pkg/cmd/generate.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package cmd
4+
5+
import (
6+
"context"
7+
"fmt"
8+
"os"
9+
10+
"github.com/stainless-api/stainless-api-cli/pkg/jsonflag"
11+
"github.com/stainless-api/stainless-api-go"
12+
"github.com/stainless-api/stainless-api-go/option"
13+
"github.com/urfave/cli/v3"
14+
)
15+
16+
var generateCreateSpec = cli.Command{
17+
Name: "create_spec",
18+
Usage: "Perform create_spec operation",
19+
Flags: []cli.Flag{
20+
&jsonflag.JSONStringFlag{
21+
Name: "project",
22+
Config: jsonflag.JSONConfig{
23+
Kind: jsonflag.Body,
24+
Path: "project",
25+
},
26+
},
27+
&jsonflag.JSONStringFlag{
28+
Name: "source.revision",
29+
Config: jsonflag.JSONConfig{
30+
Kind: jsonflag.Body,
31+
Path: "source.revision",
32+
},
33+
},
34+
&jsonflag.JSONStringFlag{
35+
Name: "source.type",
36+
Config: jsonflag.JSONConfig{
37+
Kind: jsonflag.Body,
38+
Path: "source.type",
39+
},
40+
},
41+
&jsonflag.JSONStringFlag{
42+
Name: "source.openapi_spec",
43+
Config: jsonflag.JSONConfig{
44+
Kind: jsonflag.Body,
45+
Path: "source.openapi_spec",
46+
},
47+
},
48+
&jsonflag.JSONStringFlag{
49+
Name: "source.stainless_config",
50+
Config: jsonflag.JSONConfig{
51+
Kind: jsonflag.Body,
52+
Path: "source.stainless_config",
53+
},
54+
},
55+
},
56+
Action: handleGenerateCreateSpec,
57+
HideHelpCommand: true,
58+
}
59+
60+
func handleGenerateCreateSpec(ctx context.Context, cmd *cli.Command) error {
61+
cc := getAPICommandContext(cmd)
62+
params := stainlessv0.GenerateNewSpecParams{}
63+
res, err := cc.client.Generate.NewSpec(
64+
context.TODO(),
65+
params,
66+
option.WithMiddleware(cc.AsMiddleware()),
67+
)
68+
if err != nil {
69+
return err
70+
}
71+
72+
fmt.Printf("%s\n", ColorizeJSON(res.RawJSON(), os.Stdout))
73+
return nil
74+
}

0 commit comments

Comments
 (0)