Skip to content

Commit 371aee0

Browse files
maskarbclaude
andcommitted
fix(sdk): sync generator templates with hand-edited SDK output
The generated Go SDK had hand-edits that would be lost on regeneration: - WithInsecureSkipVerify client option (TLS skip for self-signed certs) - Compiled bearerTokenPattern regex (was per-call MustCompile) - Sessions().Delete() method (missing DELETE in OpenAPI spec) - Extra blank lines in type builders (template whitespace) Fix by updating the source templates and OpenAPI spec so regeneration produces identical output (minus timestamp/hash). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ac84355 commit 371aee0

3 files changed

Lines changed: 52 additions & 12 deletions

File tree

components/ambient-api-server/openapi/openapi.sessions.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,37 @@ paths:
177177
application/json:
178178
schema:
179179
$ref: 'openapi.yaml#/components/schemas/Error'
180+
delete:
181+
summary: Delete a session by id
182+
security:
183+
- Bearer: []
184+
responses:
185+
'204':
186+
description: Session deleted successfully
187+
'401':
188+
description: Auth token is invalid
189+
content:
190+
application/json:
191+
schema:
192+
$ref: 'openapi.yaml#/components/schemas/Error'
193+
'403':
194+
description: Unauthorized to perform operation
195+
content:
196+
application/json:
197+
schema:
198+
$ref: 'openapi.yaml#/components/schemas/Error'
199+
'404':
200+
description: No session with specified id exists
201+
content:
202+
application/json:
203+
schema:
204+
$ref: 'openapi.yaml#/components/schemas/Error'
205+
'500':
206+
description: Unexpected error deleting session
207+
content:
208+
application/json:
209+
schema:
210+
$ref: 'openapi.yaml#/components/schemas/Error'
180211
parameters:
181212
- $ref: '#/components/parameters/id'
182213
/api/ambient/v1/sessions/{id}/status:

components/ambient-sdk/generator/templates/go/http_client.go.tmpl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package client
88
import (
99
"bytes"
1010
"context"
11+
"crypto/tls"
1112
"encoding/json"
1213
"fmt"
1314
"io"
@@ -23,12 +24,13 @@ import (
2324
)
2425

2526
type Client struct {
26-
httpClient *http.Client
27-
baseURL string
28-
token string
29-
project string
30-
logger *slog.Logger
31-
userAgent string
27+
httpClient *http.Client
28+
baseURL string
29+
token string
30+
project string
31+
logger *slog.Logger
32+
userAgent string
33+
insecureSkipVerify bool
3234
}
3335

3436
type ClientOption func(*Client)
@@ -39,6 +41,15 @@ func WithTimeout(timeout time.Duration) ClientOption {
3941
}
4042
}
4143

44+
func WithInsecureSkipVerify() ClientOption {
45+
return func(c *Client) {
46+
c.insecureSkipVerify = true
47+
c.httpClient.Transport = &http.Transport{
48+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec
49+
}
50+
}
51+
}
52+
4253
func WithLogger(logger *slog.Logger) ClientOption {
4354
return func(c *Client) {
4455
c.logger = logger
@@ -226,7 +237,8 @@ func validateURL(rawURL string) error {
226237
return nil
227238
}
228239

240+
var bearerTokenPattern = regexp.MustCompile(`([Bb]earer\s+)[a-zA-Z0-9\-_~.+/=]+`)
241+
229242
func sanitizeLogURL(rawURL string) string {
230-
tokenPattern := regexp.MustCompile(`([Bb]earer\s+)[a-zA-Z0-9\-_~.+/=]+`)
231-
return tokenPattern.ReplaceAllString(rawURL, "${1}[REDACTED]")
243+
return bearerTokenPattern.ReplaceAllString(rawURL, "${1}[REDACTED]")
232244
}

components/ambient-sdk/generator/templates/go/types.go.tmpl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ func (b *{{$.Resource.Name}}Builder) {{.GoName}}(v {{.GoType}}) *{{$.Resource.Na
4444
b.resource.{{.GoName}} = v
4545
return b
4646
}
47-
{{end}}{{end}}
48-
47+
{{end}}{{- end}}
4948
func (b *{{.Resource.Name}}Builder) Build() (*{{.Resource.Name}}, error) {
5049
{{- range .Resource.Fields}}
5150
{{- if .Required}}
@@ -78,7 +77,6 @@ func (b *{{$.Resource.Name}}PatchBuilder) {{.GoName}}(v {{.GoType}}) *{{$.Resour
7877
return b
7978
}
8079
{{end}}
81-
8280
func (b *{{.Resource.Name}}PatchBuilder) Build() map[string]any {
8381
return b.patch
8482
}
@@ -97,7 +95,6 @@ func (b *{{$.Resource.Name}}StatusPatchBuilder) {{.GoName}}(v {{.GoType}}) *{{$.
9795
return b
9896
}
9997
{{end}}
100-
10198
func (b *{{.Resource.Name}}StatusPatchBuilder) Build() map[string]any {
10299
return b.patch
103100
}

0 commit comments

Comments
 (0)