-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathsdk.go
More file actions
212 lines (184 loc) · 6.51 KB
/
Copy pathsdk.go
File metadata and controls
212 lines (184 loc) · 6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package generate
import (
"context"
"fmt"
"strings"
"github.com/speakeasy-api/speakeasy-core/events"
"github.com/speakeasy-api/speakeasy/internal/config"
"github.com/speakeasy-api/speakeasy/internal/model"
"github.com/speakeasy-api/speakeasy/internal/model/flag"
"github.com/speakeasy-api/speakeasy/internal/sdkgen"
)
type GenerateFlags struct {
Lang string `json:"lang"`
SchemaPath string `json:"schema"`
OutDir string `json:"out"`
Header string `json:"header"`
Token string `json:"token"`
Debug bool `json:"debug"`
Verbose bool `json:"verbose"`
AutoYes bool `json:"auto-yes"`
InstallationURL string `json:"installationURL"`
Published bool `json:"published"`
Repo string `json:"repo"`
RepoSubdir string `json:"repo-subdir"`
OutputTests bool `json:"output-tests"`
Force bool `json:"force"`
}
var genSDKCmd = &model.ExecutableCommand[GenerateFlags]{
Usage: "sdk",
Short: fmt.Sprintf("One-off SDK generation from OpenAPI specs (%s)", strings.Join(GeneratorSupportedTargetNames(), ", ")),
Long: generateLongDesc,
Run: genSDKs,
RequiresAuth: true,
OfflineCapable: true,
Flags: []flag.Flag{
flag.EnumFlag{
Name: "lang",
Shorthand: "l",
Required: true,
AllowedValues: GeneratorSupportedTargetNames(),
Description: fmt.Sprintf("language to generate sdk for (available options: [%s])", strings.Join(GeneratorSupportedTargetNames(), ", ")),
},
schemaFlag,
outFlag,
headerFlag,
tokenFlag,
debugFlag,
flag.BooleanFlag{
Name: "verbose",
DefaultValue: false,
Description: "Verbose output",
},
autoYesFlag,
flag.StringFlag{
Name: "installationURL",
Shorthand: "i",
Description: "the language specific installation URL for installation instructions if the SDK is not published to a package manager",
},
flag.BooleanFlag{
Name: "published",
Shorthand: "p",
Description: "whether the SDK is published to a package manager or not, determines the type of installation instructions to generate",
},
repoFlag,
repoSubdirFlag,
flag.BooleanFlag{
Name: "output-tests",
Shorthand: "t",
Description: "output internal tests for internal speakeasy use cases",
Hidden: true,
},
flag.BooleanFlag{
Name: "force",
Description: "Force generation of SDKs even when no changes are present",
Deprecated: true,
DeprecationMessage: "as it is now the default behavior and will be removed in a future version",
},
},
NonInteractiveSubcommands: []model.Command{genSDKVersionCmd, genSDKChangelogCmd},
}
func genSDKs(ctx context.Context, flags GenerateFlags) error {
_, err := sdkgen.Generate(
ctx,
sdkgen.GenerateOptions{
CustomerID: config.GetCustomerID(),
WorkspaceID: config.GetWorkspaceID(),
Language: flags.Lang,
SchemaPath: flags.SchemaPath,
Header: flags.Header,
Token: flags.Token,
OutDir: flags.OutDir,
CLIVersion: events.GetSpeakeasyVersionFromContext(ctx),
InstallationURL: flags.InstallationURL,
Debug: flags.Debug,
AutoYes: flags.AutoYes,
Published: flags.Published,
OutputTests: flags.OutputTests,
Repo: flags.Repo,
RepoSubDir: flags.RepoSubdir,
Verbose: flags.Verbose,
Compile: false,
TargetName: "",
SkipVersioning: false,
},
)
return err
}
var generateLongDesc = fmt.Sprintf(`RECOMMENDED: If your project has a .speakeasy/workflow.yaml file, use "speakeasy run" instead.
Workflow files provide reproducible generation with versioning, multi-target support, and CI/CD integration.
AI AGENTS: Run "speakeasy agent context" for structured documentation and guided workflows before generating.
Learn about workflow files: "speakeasy agent context plans/sdk-generation"
---
Using the "speakeasy generate sdk" command you can generate client SDK packages for various languages
that are ready to use and publish to your favorite package registry.
The following languages are currently supported:
- %s
By default the command will generate a Go SDK, but you can specify a different language using the --lang flag.
It will also use generic defaults for things such as package name (openapi), etc.
# Configuration
To configure the package of the generated SDKs you can config a "gen.yaml" file in the root of the output directory.
Example gen.yaml file for Go SDK:
`+"```"+`
go:
packageName: github.com/speakeasy-api/speakeasy-client-sdk-go
version: 0.1.0
generate:
# baseServerUrl is optional, if not specified it will use the server URL from the OpenAPI document
baseServerUrl: https://api.speakeasy.com
`+"```"+`
Example gen.yaml file for Python SDK:
`+"```"+`
python:
packageName: speakeasy-client-sdk-python
version: 0.1.0
description: Speakeasy API Client SDK for Python
author: Speakeasy API
generate:
# baseServerUrl is optional, if not specified it will use the server URL from the OpenAPI document
baseServerUrl: https://api.speakeasy.com
`+"```"+`
Example gen.yaml file for Typescript SDK:
`+"```"+`
typescript:
packageName: speakeasy-client-sdk-typescript
version: 0.1.0
author: Speakeasy API
generate:
# baseServerUrl is optional, if not specified it will use the server URL from the OpenAPI document
baseServerUrl: https://api.speakeasy.com
`+"```"+`
Example gen.yaml file for Java SDK:
`+"```"+`
java:
groupID: dev.speakeasyapi
artifactID: javasdk
projectName: speakeasy-client-sdk-java
version: 0.1.0
generate:
# baseServerUrl is optional, if not specified it will use the server URL from the OpenAPI document
baseServerUrl: https://api.speakeasy.com
`+"```"+`
Example gen.yaml file for PHP SDK:
`+"```"+`
php:
packageName: speakeasy-client-sdk-php
namespace: "speakeasyapi\\sdk"
version: 0.1.0
generate:
# baseServerUrl is optional, if not specified it will use the server URL from the OpenAPI document
baseServerUrl: https://api.speakeasy.com
`+"```"+`
Example gen.yaml file for C# SDK:
`+"```"+`
csharp:
version: 0.1.0
author: Speakeasy
maxMethodParams: 0
packageName: SpeakeasySDK
generate:
# baseServerUrl is optional, if not specified it will use the server URL from the OpenAPI document
baseServerUrl: https://api.speakeasy.com
`+"```"+`
For additional documentation visit: https://speakeasy.com/docs/using-speakeasy/create-client-sdks/intro
`, strings.Join(GeneratorSupportedTargetNames(), "\n - "))