@apollo-deploy/tesseract 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +218 -110
- package/dist/adapters/csharp/index.d.ts +5 -8
- package/dist/adapters/csharp/index.d.ts.map +1 -1
- package/dist/adapters/csharp/index.js +314 -74
- package/dist/adapters/csharp/index.js.map +1 -1
- package/dist/adapters/documentation.d.ts +17 -0
- package/dist/adapters/documentation.d.ts.map +1 -0
- package/dist/adapters/documentation.js +268 -0
- package/dist/adapters/documentation.js.map +1 -0
- package/dist/adapters/go/index.d.ts +5 -8
- package/dist/adapters/go/index.d.ts.map +1 -1
- package/dist/adapters/go/index.js +197 -101
- package/dist/adapters/go/index.js.map +1 -1
- package/dist/adapters/kotlin/index.d.ts +5 -9
- package/dist/adapters/kotlin/index.d.ts.map +1 -1
- package/dist/adapters/kotlin/index.js +280 -212
- package/dist/adapters/kotlin/index.js.map +1 -1
- package/dist/adapters/php/index.d.ts +5 -15
- package/dist/adapters/php/index.d.ts.map +1 -1
- package/dist/adapters/php/index.js +362 -90
- package/dist/adapters/php/index.js.map +1 -1
- package/dist/adapters/python/index.d.ts +5 -8
- package/dist/adapters/python/index.d.ts.map +1 -1
- package/dist/adapters/python/index.js +240 -109
- package/dist/adapters/python/index.js.map +1 -1
- package/dist/adapters/ruby/index.d.ts +3 -3
- package/dist/adapters/ruby/index.d.ts.map +1 -1
- package/dist/adapters/ruby/index.js +235 -46
- package/dist/adapters/ruby/index.js.map +1 -1
- package/dist/adapters/rust/index.d.ts +5 -9
- package/dist/adapters/rust/index.d.ts.map +1 -1
- package/dist/adapters/rust/index.js +237 -169
- package/dist/adapters/rust/index.js.map +1 -1
- package/dist/adapters/shared.d.ts +7 -0
- package/dist/adapters/shared.d.ts.map +1 -0
- package/dist/adapters/shared.js +68 -0
- package/dist/adapters/shared.js.map +1 -0
- package/dist/adapters/type-utils.d.ts +13 -0
- package/dist/adapters/type-utils.d.ts.map +1 -0
- package/dist/adapters/type-utils.js +105 -0
- package/dist/adapters/type-utils.js.map +1 -0
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/typescript/emitter/emitSchema.d.ts +2 -2
- package/dist/adapters/typescript/emitter/emitSchema.js +39 -27
- package/dist/adapters/typescript/emitter/emitSchema.js.map +1 -1
- package/dist/adapters/typescript/emitter/emitTypeScriptModels.d.ts +2 -2
- package/dist/adapters/typescript/emitter/emitTypeScriptModels.js +15 -15
- package/dist/adapters/typescript/emitter/importCollector.d.ts +2 -4
- package/dist/adapters/typescript/emitter/importCollector.d.ts.map +1 -1
- package/dist/adapters/typescript/emitter/importCollector.js +40 -50
- package/dist/adapters/typescript/emitter/importCollector.js.map +1 -1
- package/dist/adapters/typescript/emitter/parsers.d.ts +1 -1
- package/dist/adapters/typescript/emitter/parsers.js +13 -13
- package/dist/adapters/typescript/emitter/typeHoister.d.ts +1 -1
- package/dist/adapters/typescript/emitter/typeHoister.d.ts.map +1 -1
- package/dist/adapters/typescript/emitter/typeHoister.js +12 -20
- package/dist/adapters/typescript/emitter/typeHoister.js.map +1 -1
- package/dist/adapters/typescript/index.d.ts +3 -3
- package/dist/adapters/typescript/index.d.ts.map +1 -1
- package/dist/adapters/typescript/index.js +148 -166
- package/dist/adapters/typescript/index.js.map +1 -1
- package/dist/adapters/typescript/shared.d.ts +2 -2
- package/dist/adapters/typescript/shared.js +12 -12
- package/dist/cli.js +50 -37
- package/dist/cli.js.map +1 -1
- package/dist/collector.d.ts +13 -3
- package/dist/collector.d.ts.map +1 -1
- package/dist/collector.js +69 -32
- package/dist/collector.js.map +1 -1
- package/dist/elysia.js +2 -2
- package/dist/elysia.js.map +1 -1
- package/dist/express.d.ts.map +1 -1
- package/dist/express.js.map +1 -1
- package/dist/fastify.d.ts +7 -0
- package/dist/fastify.d.ts.map +1 -1
- package/dist/fastify.js +39 -20
- package/dist/fastify.js.map +1 -1
- package/dist/helpers/handlebars.d.ts +7 -16
- package/dist/helpers/handlebars.d.ts.map +1 -1
- package/dist/helpers/handlebars.js +127 -177
- package/dist/helpers/handlebars.js.map +1 -1
- package/dist/hono.d.ts.map +1 -1
- package/dist/hono.js.map +1 -1
- package/dist/index.d.ts +14 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -30
- package/dist/index.js.map +1 -1
- package/dist/koa.d.ts.map +1 -1
- package/dist/koa.js.map +1 -1
- package/dist/nestjs.d.ts.map +1 -1
- package/dist/nestjs.js +41 -14
- package/dist/nestjs.js.map +1 -1
- package/dist/pipeline/enrich.d.ts +2 -13
- package/dist/pipeline/enrich.d.ts.map +1 -1
- package/dist/pipeline/enrich.js +157 -212
- package/dist/pipeline/enrich.js.map +1 -1
- package/dist/pipeline/intake.d.ts +3 -3
- package/dist/pipeline/intake.d.ts.map +1 -1
- package/dist/pipeline/intake.js +342 -238
- package/dist/pipeline/intake.js.map +1 -1
- package/dist/pipeline/write.d.ts +1 -14
- package/dist/pipeline/write.d.ts.map +1 -1
- package/dist/pipeline/write.js +73 -113
- package/dist/pipeline/write.js.map +1 -1
- package/dist/types/config.d.ts +14 -26
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +16 -12
- package/dist/types/config.js.map +1 -1
- package/dist/types/ir.d.ts +12 -8
- package/dist/types/ir.d.ts.map +1 -1
- package/dist/types/manifest.d.ts +10 -11
- package/dist/types/manifest.d.ts.map +1 -1
- package/dist/types/manifest.js +54 -14
- package/dist/types/manifest.js.map +1 -1
- package/dist/types/sdk-module.d.ts +2 -2
- package/dist/types/sdk-module.js +1 -1
- package/dist/utils/format.d.ts +1 -3
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +3 -10
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/naming.d.ts.map +1 -1
- package/dist/utils/naming.js +174 -184
- package/dist/utils/naming.js.map +1 -1
- package/dist/utils/npm-token.d.ts +1 -17
- package/dist/utils/npm-token.d.ts.map +1 -1
- package/dist/utils/npm-token.js +27 -76
- package/dist/utils/npm-token.js.map +1 -1
- package/dist/utils/version.d.ts +14 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +60 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +4 -3
- package/templates/csharp/client.hbs +26 -49
- package/templates/csharp/csproj.hbs +7 -0
- package/templates/csharp/domain.hbs +48 -130
- package/templates/csharp/errors.hbs +17 -25
- package/templates/csharp/readme.hbs +31 -44
- package/templates/csharp/transport.hbs +238 -136
- package/templates/csharp/types.hbs +30 -76
- package/templates/go/client.hbs +44 -109
- package/templates/go/domain.hbs +83 -25
- package/templates/go/go-mod.hbs +1 -4
- package/templates/go/readme.hbs +32 -29
- package/templates/go/transport.hbs +174 -173
- package/templates/go/types.hbs +17 -53
- package/templates/go/utils.hbs +3 -2
- package/templates/kotlin/build-gradle.hbs +1 -1
- package/templates/kotlin/client.hbs +18 -15
- package/templates/kotlin/domain.hbs +54 -51
- package/templates/kotlin/errors.hbs +1 -1
- package/templates/kotlin/readme.hbs +35 -137
- package/templates/kotlin/transport.hbs +140 -123
- package/templates/kotlin/types.hbs +30 -81
- package/templates/php/client.hbs +8 -46
- package/templates/php/composer.hbs +2 -1
- package/templates/php/domain.hbs +86 -117
- package/templates/php/errors.hbs +1 -1
- package/templates/php/readme.hbs +42 -49
- package/templates/php/transport.hbs +192 -145
- package/templates/php/types.hbs +63 -60
- package/templates/python/client.hbs +15 -2
- package/templates/python/domain.hbs +50 -108
- package/templates/python/pyproject.hbs +5 -0
- package/templates/python/readme.hbs +47 -30
- package/templates/python/resources-init.hbs +1 -1
- package/templates/python/transport.hbs +167 -53
- package/templates/python/types.hbs +22 -58
- package/templates/ruby/client.hbs +10 -6
- package/templates/ruby/domain.hbs +48 -67
- package/templates/ruby/errors.hbs +3 -3
- package/templates/ruby/gemspec.hbs +3 -10
- package/templates/ruby/index.hbs +3 -3
- package/templates/ruby/readme.hbs +33 -70
- package/templates/ruby/transport.hbs +129 -103
- package/templates/ruby/types.hbs +11 -16
- package/templates/ruby/version.hbs +1 -1
- package/templates/rust/cargo.hbs +2 -0
- package/templates/rust/client.hbs +10 -1
- package/templates/rust/domain.hbs +69 -52
- package/templates/rust/error.hbs +3 -1
- package/templates/rust/lib.hbs +4 -5
- package/templates/rust/readme.hbs +33 -46
- package/templates/rust/transport.hbs +170 -159
- package/templates/rust/types.hbs +34 -111
- package/templates/typescript/domain-class.hbs +14 -6
- package/templates/typescript/domain.hbs +13 -5
- package/templates/typescript/package-json.hbs +3 -1
- package/templates/typescript/readme.hbs +42 -42
- package/templates/typescript/transport.hbs +46 -8
- package/templates/typescript/types-errors.hbs +1 -1
- package/dist/adapters/typescript/model-emitter.d.ts +0 -13
- package/dist/adapters/typescript/model-emitter.d.ts.map +0 -1
- package/dist/adapters/typescript/model-emitter.js +0 -415
- package/dist/adapters/typescript/model-emitter.js.map +0 -1
package/templates/go/client.hbs
CHANGED
|
@@ -1,93 +1,75 @@
|
|
|
1
1
|
package {{pkgName}}
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
{{#if hasSSE}}
|
|
4
5
|
"context"
|
|
6
|
+
{{/if}}
|
|
5
7
|
"time"
|
|
6
8
|
)
|
|
7
9
|
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
// ClientConfig holds all configuration for the API client.
|
|
10
|
+
// ClientConfig configures the API client.
|
|
11
11
|
type ClientConfig struct {
|
|
12
|
-
BaseURL
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
BaseURL string
|
|
13
|
+
{{#each securitySchemes}}
|
|
14
|
+
{{pascalCase configKey}} string
|
|
15
|
+
{{/each}}
|
|
16
|
+
Timeout time.Duration
|
|
17
|
+
MaxRetries int
|
|
18
|
+
RetryUnsafeRequests bool
|
|
19
|
+
DefaultHeaders map[string]string
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
// ClientOption is a functional option for configuring the client.
|
|
19
22
|
type ClientOption func(*ClientConfig)
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
func
|
|
23
|
-
|
|
24
|
+
func WithBaseURL(url string) ClientOption { return func(c *ClientConfig) { c.BaseURL = url } }
|
|
25
|
+
func WithTimeout(timeout time.Duration) ClientOption { return func(c *ClientConfig) { c.Timeout = timeout } }
|
|
26
|
+
func WithMaxRetries(retries int) ClientOption { return func(c *ClientConfig) { c.MaxRetries = retries } }
|
|
27
|
+
func WithUnsafeRetries(enabled bool) ClientOption {
|
|
28
|
+
return func(c *ClientConfig) { c.RetryUnsafeRequests = enabled }
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
// WithTimeout sets the request timeout.
|
|
27
|
-
func WithTimeout(d time.Duration) ClientOption {
|
|
28
|
-
return func(c *ClientConfig) { c.Timeout = d }
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// WithMaxRetries sets the maximum number of retry attempts.
|
|
32
|
-
func WithMaxRetries(n int) ClientOption {
|
|
33
|
-
return func(c *ClientConfig) { c.MaxRetries = n }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// WithDefaultHeader adds a default header sent with every request.
|
|
37
30
|
func WithDefaultHeader(key, value string) ClientOption {
|
|
38
31
|
return func(c *ClientConfig) {
|
|
39
|
-
if c.DefaultHeaders == nil {
|
|
40
|
-
c.DefaultHeaders = make(map[string]string)
|
|
41
|
-
}
|
|
32
|
+
if c.DefaultHeaders == nil { c.DefaultHeaders = make(map[string]string) }
|
|
42
33
|
c.DefaultHeaders[key] = value
|
|
43
34
|
}
|
|
44
35
|
}
|
|
36
|
+
{{#each securitySchemes}}
|
|
37
|
+
func With{{pascalCase configKey}}(value string) ClientOption {
|
|
38
|
+
return func(c *ClientConfig) { c.{{pascalCase configKey}} = value }
|
|
39
|
+
}
|
|
40
|
+
{{/each}}
|
|
45
41
|
|
|
46
|
-
// DefaultConfig returns a ClientConfig populated with sensible defaults.
|
|
47
42
|
func DefaultConfig() ClientConfig {
|
|
48
43
|
return ClientConfig{
|
|
49
|
-
BaseURL:
|
|
50
|
-
Timeout: 15 * time.Second,
|
|
51
|
-
MaxRetries: 3,
|
|
44
|
+
BaseURL: "{{baseUrl}}", Timeout: 15 * time.Second, MaxRetries: 3,
|
|
52
45
|
}
|
|
53
46
|
}
|
|
54
47
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
// Client is the primary API client for {{title}}.
|
|
58
|
-
// It is safe for concurrent use by multiple goroutines.
|
|
48
|
+
// Client is safe for concurrent use by multiple goroutines.
|
|
59
49
|
type Client struct {
|
|
60
|
-
config
|
|
50
|
+
config ClientConfig
|
|
61
51
|
transport *Transport
|
|
62
52
|
{{#each groups}}
|
|
63
53
|
{{pascalCase name}} *{{interfaceName}}
|
|
64
54
|
{{/each}}
|
|
65
55
|
}
|
|
66
56
|
|
|
67
|
-
// NewClient creates a new {{title}} API client with the given options.
|
|
68
|
-
//
|
|
69
|
-
// Example:
|
|
70
|
-
//
|
|
71
|
-
// client := petshop.NewClient(
|
|
72
|
-
// petshop.WithBaseURL("https://api.example.com"),
|
|
73
|
-
// petshop.WithTimeout(30*time.Second),
|
|
74
|
-
// )
|
|
75
|
-
// pets, err := client.Pets.List(ctx, nil)
|
|
76
57
|
func NewClient(opts ...ClientOption) *Client {
|
|
77
58
|
cfg := DefaultConfig()
|
|
78
|
-
for _,
|
|
79
|
-
opt(&cfg)
|
|
80
|
-
}
|
|
81
|
-
|
|
59
|
+
for _, option := range opts { option(&cfg) }
|
|
82
60
|
t := NewTransport(TransportConfig{
|
|
83
|
-
BaseURL:
|
|
84
|
-
|
|
61
|
+
BaseURL: cfg.BaseURL,
|
|
62
|
+
{{#each securitySchemes}}
|
|
63
|
+
{{pascalCase configKey}}: cfg.{{pascalCase configKey}},
|
|
64
|
+
{{/each}}
|
|
65
|
+
Timeout: cfg.Timeout,
|
|
85
66
|
MaxRetries: cfg.MaxRetries,
|
|
86
|
-
|
|
67
|
+
RetryUnsafeRequests: cfg.RetryUnsafeRequests,
|
|
68
|
+
Headers: cfg.DefaultHeaders,
|
|
69
|
+
UserAgent: "{{pkgName}}-go-sdk/{{packageVersion}}",
|
|
87
70
|
})
|
|
88
|
-
|
|
89
71
|
return &Client{
|
|
90
|
-
config:
|
|
72
|
+
config: cfg,
|
|
91
73
|
transport: t,
|
|
92
74
|
{{#each groups}}
|
|
93
75
|
{{pascalCase name}}: &{{interfaceName}}{transport: t},
|
|
@@ -95,64 +77,17 @@ func NewClient(opts ...ClientOption) *Client {
|
|
|
95
77
|
}
|
|
96
78
|
}
|
|
97
79
|
|
|
98
|
-
|
|
99
|
-
func (c *Client)
|
|
100
|
-
return c.transport
|
|
101
|
-
}
|
|
80
|
+
func (c *Client) Transport() *Transport { return c.transport }
|
|
81
|
+
func (c *Client) CloseIdleConnections() { c.transport.CloseIdleConnections() }
|
|
102
82
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
type RequestOptions struct {
|
|
107
|
-
// Timeout overrides the client-level timeout for this request.
|
|
108
|
-
Timeout time.Duration
|
|
109
|
-
// Headers are additional headers merged into the request.
|
|
110
|
-
Headers map[string]string
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// ListParams is embedded by list operation parameter types to provide
|
|
114
|
-
// common pagination and filtering fields.
|
|
115
|
-
type ListParams struct {
|
|
116
|
-
Page *int `json:"page,omitempty"`
|
|
117
|
-
Limit *int `json:"limit,omitempty"`
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Int returns a pointer to the given int value. Useful for optional
|
|
121
|
-
// parameters in request structs.
|
|
122
|
-
func Int(v int) *int { return &v }
|
|
123
|
-
|
|
124
|
-
// String returns a pointer to the given string value.
|
|
125
|
-
func String(v string) *string { return &v }
|
|
126
|
-
|
|
127
|
-
// Bool returns a pointer to the given bool value.
|
|
128
|
-
func Bool(v bool) *bool { return &v }
|
|
83
|
+
func Int(value int) *int { return &value }
|
|
84
|
+
func String(value string) *string { return &value }
|
|
85
|
+
func Bool(value bool) *bool { return &value }
|
|
129
86
|
|
|
130
87
|
{{#if hasSSE}}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// SSEEvent represents a parsed Server-Sent Event.
|
|
134
|
-
type SSEEvent struct {
|
|
135
|
-
Event string
|
|
136
|
-
Data string
|
|
137
|
-
ID string
|
|
138
|
-
Retry int
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// SSEOption configures an SSE stream subscription.
|
|
88
|
+
type SSEEvent struct { Event, Data, ID string; Retry int }
|
|
142
89
|
type SSEOption func(*sseConfig)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
eventTypes []string
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// WithSSESignal sets a context for cancellation of the SSE stream.
|
|
150
|
-
func WithSSESignal(ctx context.Context) SSEOption {
|
|
151
|
-
return func(c *sseConfig) { c.signal = ctx }
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// WithSSEEventTypes filters the stream to specific event types.
|
|
155
|
-
func WithSSEEventTypes(types ...string) SSEOption {
|
|
156
|
-
return func(c *sseConfig) { c.eventTypes = types }
|
|
157
|
-
}
|
|
90
|
+
type sseConfig struct { signal context.Context; eventTypes []string }
|
|
91
|
+
func WithSSESignal(ctx context.Context) SSEOption { return func(c *sseConfig) { c.signal = ctx } }
|
|
92
|
+
func WithSSEEventTypes(types ...string) SSEOption { return func(c *sseConfig) { c.eventTypes = types } }
|
|
158
93
|
{{/if}}
|
package/templates/go/domain.hbs
CHANGED
|
@@ -4,6 +4,12 @@ import (
|
|
|
4
4
|
{{#if hasSSE}}
|
|
5
5
|
"bufio"
|
|
6
6
|
"strings"
|
|
7
|
+
{{/if}}
|
|
8
|
+
{{#if needsFormatting}}
|
|
9
|
+
"fmt"
|
|
10
|
+
{{/if}}
|
|
11
|
+
{{#if hasQueryParams}}
|
|
12
|
+
"net/url"
|
|
7
13
|
{{/if}}
|
|
8
14
|
"context"
|
|
9
15
|
)
|
|
@@ -15,22 +21,53 @@ type {{interfaceName}} struct {
|
|
|
15
21
|
|
|
16
22
|
{{#each operations}}
|
|
17
23
|
{{#if isEventStream}}
|
|
18
|
-
func (api *{{../interfaceName}}) {{pascalCase name}}
|
|
24
|
+
func (api *{{../interfaceName}}) {{pascalCase name}}(
|
|
19
25
|
ctx context.Context,
|
|
20
26
|
{{#each pathParams}}
|
|
21
|
-
{{name}}
|
|
27
|
+
{{name}} {{targetType}},
|
|
22
28
|
{{/each}}
|
|
23
|
-
{{#if
|
|
24
|
-
|
|
29
|
+
{{#if requestBody}}
|
|
30
|
+
body {{requestBody.inputType}},
|
|
25
31
|
{{/if}}
|
|
32
|
+
{{#each queryParams}}
|
|
33
|
+
{{name}} {{inputType}},
|
|
34
|
+
{{/each}}
|
|
35
|
+
{{#each headerParams}}
|
|
36
|
+
{{name}} {{inputType}},
|
|
37
|
+
{{/each}}
|
|
26
38
|
) (<-chan SSEEvent, <-chan error) {
|
|
27
39
|
eventCh := make(chan SSEEvent)
|
|
28
40
|
errCh := make(chan error, 1)
|
|
29
41
|
go func() {
|
|
30
42
|
defer close(eventCh)
|
|
31
43
|
defer close(errCh)
|
|
32
|
-
reqPath := buildPath("{{path}}"{{#each pathParams}}, "{{
|
|
33
|
-
|
|
44
|
+
reqPath := buildPath("{{path}}"{{#each pathParams}}, "{{name}}", {{name}}{{/each}})
|
|
45
|
+
{{#if hasQueryParams}}
|
|
46
|
+
query := url.Values{}
|
|
47
|
+
{{#each queryParams}}
|
|
48
|
+
{{#if required}}
|
|
49
|
+
query.Set("{{originalName}}", fmt.Sprint({{name}}))
|
|
50
|
+
{{else}}
|
|
51
|
+
if {{name}} != nil { query.Set("{{originalName}}", fmt.Sprint(*{{name}})) }
|
|
52
|
+
{{/if}}
|
|
53
|
+
{{/each}}
|
|
54
|
+
{{/if}}
|
|
55
|
+
{{#if hasHeaderParams}}
|
|
56
|
+
headers := map[string]string{}
|
|
57
|
+
{{#each headerParams}}
|
|
58
|
+
{{#if required}}
|
|
59
|
+
headers["{{originalName}}"] = fmt.Sprint({{name}})
|
|
60
|
+
{{else}}
|
|
61
|
+
if {{name}} != nil { headers["{{originalName}}"] = fmt.Sprint(*{{name}}) }
|
|
62
|
+
{{/if}}
|
|
63
|
+
{{/each}}
|
|
64
|
+
{{/if}}
|
|
65
|
+
resp, err := api.transport.Stream(ctx, request{
|
|
66
|
+
Method: "{{httpMethod}}", Path: reqPath,
|
|
67
|
+
{{#if hasQueryParams}} Query: query,{{/if}}
|
|
68
|
+
{{#if requestBody}} Body: body, ContentType: "{{requestBody.contentType}}",{{/if}}
|
|
69
|
+
{{#if hasHeaderParams}} Headers: headers,{{/if}}
|
|
70
|
+
})
|
|
34
71
|
if err != nil { errCh <- err; return }
|
|
35
72
|
defer resp.Body.Close()
|
|
36
73
|
scanner := bufio.NewScanner(resp.Body)
|
|
@@ -49,6 +86,8 @@ func (api *{{../interfaceName}}) {{pascalCase name}}Stream(
|
|
|
49
86
|
if strings.HasPrefix(line, "data:") { if current.Data != "" { current.Data += "\n" }; current.Data += strings.TrimSpace(line[5:]) }
|
|
50
87
|
if strings.HasPrefix(line, "id:") { current.ID = strings.TrimSpace(line[3:]) }
|
|
51
88
|
}
|
|
89
|
+
if current.Data != "" { eventCh <- current }
|
|
90
|
+
if err := scanner.Err(); err != nil { errCh <- err }
|
|
52
91
|
}()
|
|
53
92
|
return eventCh, errCh
|
|
54
93
|
}
|
|
@@ -57,31 +96,50 @@ func (api *{{../interfaceName}}) {{pascalCase name}}Stream(
|
|
|
57
96
|
func (api *{{../interfaceName}}) {{pascalCase name}}(
|
|
58
97
|
ctx context.Context,
|
|
59
98
|
{{#each pathParams}}
|
|
60
|
-
{{name}}
|
|
99
|
+
{{name}} {{targetType}},
|
|
61
100
|
{{/each}}
|
|
62
101
|
{{#if requestBody}}
|
|
63
|
-
body
|
|
102
|
+
body {{requestBody.inputType}},
|
|
64
103
|
{{/if}}
|
|
65
|
-
{{#
|
|
66
|
-
|
|
104
|
+
{{#each queryParams}}
|
|
105
|
+
{{name}} {{inputType}},
|
|
106
|
+
{{/each}}
|
|
107
|
+
{{#each headerParams}}
|
|
108
|
+
{{name}} {{inputType}},
|
|
109
|
+
{{/each}}
|
|
110
|
+
) {{#if (eq responseType "void")}}error{{else}}(*{{goResponseType}}, error){{/if}} {
|
|
111
|
+
reqPath := buildPath("{{path}}"{{#each pathParams}}, "{{name}}", {{name}}{{/each}})
|
|
112
|
+
{{#if hasQueryParams}}
|
|
113
|
+
query := url.Values{}
|
|
114
|
+
{{#each queryParams}}
|
|
115
|
+
{{#if required}}
|
|
116
|
+
query.Set("{{originalName}}", fmt.Sprint({{name}}))
|
|
117
|
+
{{else}}
|
|
118
|
+
if {{name}} != nil { query.Set("{{originalName}}", fmt.Sprint(*{{name}})) }
|
|
67
119
|
{{/if}}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
{{
|
|
75
|
-
{{#if requestBody}} Body: body,{{/if}}
|
|
76
|
-
}, nil)
|
|
120
|
+
{{/each}}
|
|
121
|
+
{{/if}}
|
|
122
|
+
{{#if hasHeaderParams}}
|
|
123
|
+
headers := map[string]string{}
|
|
124
|
+
{{#each headerParams}}
|
|
125
|
+
{{#if required}}
|
|
126
|
+
headers["{{originalName}}"] = fmt.Sprint({{name}})
|
|
77
127
|
{{else}}
|
|
78
|
-
|
|
79
|
-
|
|
128
|
+
if {{name}} != nil { headers["{{originalName}}"] = fmt.Sprint(*{{name}}) }
|
|
129
|
+
{{/if}}
|
|
130
|
+
{{/each}}
|
|
131
|
+
{{/if}}
|
|
132
|
+
req := request{
|
|
80
133
|
Method: "{{httpMethod}}", Path: reqPath,
|
|
81
|
-
{{#if
|
|
82
|
-
{{#if requestBody}} Body: body,{{/if}}
|
|
83
|
-
|
|
84
|
-
|
|
134
|
+
{{#if hasQueryParams}} Query: query,{{/if}}
|
|
135
|
+
{{#if requestBody}} Body: body, ContentType: "{{requestBody.contentType}}",{{/if}}
|
|
136
|
+
{{#if hasHeaderParams}} Headers: headers,{{/if}}
|
|
137
|
+
}
|
|
138
|
+
{{#if (eq responseType "void")}}
|
|
139
|
+
return api.transport.Execute(ctx, req, nil)
|
|
140
|
+
{{else}}
|
|
141
|
+
var result {{goResponseType}}
|
|
142
|
+
if err := api.transport.Execute(ctx, req, &result); err != nil { return nil, err }
|
|
85
143
|
return &result, nil
|
|
86
144
|
{{/if}}
|
|
87
145
|
}
|
package/templates/go/go-mod.hbs
CHANGED
package/templates/go/readme.hbs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# {{title}} Go SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
{{#if description}}{{description}}{{else}}Go client for the {{title}} API.{{/if}}
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> Generated by Tesseract. Generated source files should not be edited manually.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -10,57 +10,60 @@ The official Go SDK for {{#if description}}{{description}}{{else}}the {{title}}
|
|
|
10
10
|
go get {{packageName}}
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
## Quick
|
|
13
|
+
## Quick start
|
|
14
14
|
|
|
15
15
|
```go
|
|
16
16
|
package main
|
|
17
17
|
|
|
18
18
|
import (
|
|
19
19
|
"context"
|
|
20
|
-
"
|
|
21
|
-
"log"
|
|
20
|
+
"time"
|
|
22
21
|
|
|
23
22
|
"{{packageName}}"
|
|
24
23
|
)
|
|
25
24
|
|
|
26
25
|
func main() {
|
|
27
|
-
client := {{pkgName}}.NewClient(
|
|
28
|
-
{{
|
|
29
|
-
{{pascalCase configKey}}: "your-bearer-token",{{/if}}
|
|
30
|
-
{{/each}}
|
|
26
|
+
client := {{pkgName}}.NewClient(
|
|
27
|
+
{{pkgName}}.WithTimeout(15*time.Second),
|
|
31
28
|
)
|
|
32
29
|
|
|
33
30
|
ctx := context.Background()
|
|
34
|
-
|
|
35
|
-
{{#
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if err != nil {
|
|
39
|
-
log.Fatal(err)
|
|
40
|
-
}
|
|
41
|
-
fmt.Printf("%+v\n", result)
|
|
42
|
-
{{/with}}
|
|
43
|
-
{{/each}}
|
|
31
|
+
_ = ctx
|
|
32
|
+
{{#if groups.length}}
|
|
33
|
+
_ = client.{{pascalCase groups.[0].name}}
|
|
34
|
+
{{/if}}
|
|
44
35
|
}
|
|
45
36
|
```
|
|
46
37
|
|
|
47
|
-
##
|
|
38
|
+
## Configuration and reliability
|
|
39
|
+
|
|
40
|
+
The client is safe for concurrent use. Requests use contexts for cancellation, bounded timeouts, exponential-backoff retries, `Retry-After` handling, default headers, and structured `SDKError` values. Unsafe requests are not retried unless an idempotency key is present or unsafe retries are explicitly enabled.
|
|
41
|
+
|
|
42
|
+
```go
|
|
43
|
+
client := {{pkgName}}.NewClient(
|
|
44
|
+
{{pkgName}}.WithTimeout(30*time.Second),
|
|
45
|
+
{{pkgName}}.WithMaxRetries(3),
|
|
46
|
+
{{pkgName}}.WithDefaultHeader("X-Application", "my-service"),
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Documentation
|
|
51
|
+
|
|
52
|
+
- [Documentation index](./docs/README.md)
|
|
53
|
+
- [Generated types](./docs/types.md)
|
|
48
54
|
|
|
49
55
|
| Domain | Description |
|
|
50
|
-
|
|
56
|
+
|---|---|
|
|
51
57
|
{{#each groups}}
|
|
52
|
-
|
|
|
58
|
+
| [{{interfaceName}}](./docs/domains/{{fileName}}.md) | {{#if description}}{{description}}{{else}}{{name}} operations{{/if}} |
|
|
53
59
|
{{/each}}
|
|
54
60
|
|
|
55
|
-
## Error
|
|
56
|
-
|
|
57
|
-
All methods return an `error` as the second return value. Use `errors.As` to inspect SDK-specific errors:
|
|
61
|
+
## Error handling
|
|
58
62
|
|
|
59
63
|
```go
|
|
60
|
-
var sdkErr *SDKError
|
|
64
|
+
var sdkErr *{{pkgName}}.SDKError
|
|
61
65
|
if errors.As(err, &sdkErr) {
|
|
62
|
-
|
|
63
|
-
sdkErr.Status, sdkErr.Code, sdkErr.RequestID)
|
|
66
|
+
log.Printf("status=%d code=%s request=%s", sdkErr.Status, sdkErr.Code, sdkErr.RequestID)
|
|
64
67
|
}
|
|
65
68
|
```
|
|
66
69
|
|
|
@@ -70,4 +73,4 @@ if errors.As(err, &sdkErr) {
|
|
|
70
73
|
|
|
71
74
|
## License
|
|
72
75
|
|
|
73
|
-
|
|
76
|
+
MIT
|