Skip to content

Commit 905343c

Browse files
authored
Expose experimental methods. (#379)
For parity with oxide.rs, expose experimental methods from the api, prefixing paths with "Experimental" to indicate to users that the methods may change. Note: we could also indicate methods as being experimental by putting them into a different package, or a different client, or just in their docs. This seemed like the simplest approach that would still make the intention clear to sdk users.
1 parent 30fa749 commit 905343c

File tree

3 files changed

+1990
-96
lines changed

3 files changed

+1990
-96
lines changed

internal/generate/paths.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/http"
1111
"os"
12+
"slices"
1213
"sort"
1314
"strconv"
1415
"strings"
@@ -36,6 +37,7 @@ type methodTemplate struct {
3637
HasBody bool
3738
HasSummary bool
3839
IsAppJSON bool
40+
IsExperimental bool
3941
}
4042

4143
type paramsInfo struct {
@@ -141,22 +143,24 @@ func buildMethod(
141143
return nil
142144
}
143145

144-
if o.Tags[0] == "experimental" {
145-
fmt.Printf("[WARN] TODO: skipping operation %q, since it is experimental\n", o.OperationID)
146-
return nil
147-
}
148-
149-
if o.Tags[0] == "console-auth" {
146+
if slices.Contains(o.Tags, "console-auth") {
150147
fmt.Printf(
151148
"[WARN] TODO: skipping operation %q, since it is for console authentication\n",
152149
o.OperationID,
153150
)
154151
return nil
155152
}
156153

154+
isExperimental := slices.Contains(o.Tags, "experimental")
155+
157156
methodName := strcase.ToCamel(o.OperationID)
158157
pInfo := buildParams(o, methodName)
159158

159+
// Prefix experimental operations so callers know the API may change.
160+
if isExperimental {
161+
methodName = "Experimental" + methodName
162+
}
163+
160164
// Adapt for ListAll methods
161165

162166
if isGetAllPages {
@@ -206,6 +210,7 @@ func buildMethod(
206210
HasParams: pInfo.paramsString != "",
207211
HasSummary: o.Summary != "",
208212
HasDescription: o.Description != "",
213+
IsExperimental: isExperimental,
209214
}
210215

211216
// TODO: Handle other content types
@@ -426,7 +431,11 @@ func buildPathOrQueryParams(
426431
fmt.Sprintf("%q: %s.Format(time.RFC3339),", name, n),
427432
)
428433
default:
429-
pathParams = append(pathParams, fmt.Sprintf("%q: string(%s),", name, n))
434+
if p.Schema.Value != nil && p.Schema.Value.Type.Is("integer") {
435+
pathParams = append(pathParams, fmt.Sprintf("%q: fmt.Sprint(%s),", name, n))
436+
} else {
437+
pathParams = append(pathParams, fmt.Sprintf("%q: string(%s),", name, n))
438+
}
430439
}
431440
}
432441
}

internal/generate/templates/description.go.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
{{define "description"}}// {{.FunctionName}}{{if .HasSummary}}: {{.Summary}}{{end}}{{if .HasDescription}}
1+
{{define "description"}}{{if .IsExperimental}}// EXPERIMENTAL: This operation is not yet stable and may change or be removed without notice.
2+
//
3+
{{end}}// {{.FunctionName}}{{if .HasSummary}}: {{.Summary}}{{end}}{{if .HasDescription}}
24
// {{.Description}}{{end}}{{if .IsListAll}}
35
//
46
// This method is a wrapper around the `{{.WrappedFunction}}` method.

0 commit comments

Comments
 (0)