Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
259 commits
Select commit Hold shift + click to select a range
ce628cd
codegen metadata
stainless-app[bot] Jun 20, 2025
7a8b39f
feat(api): api update
stainless-app[bot] Jun 20, 2025
0926610
codegen metadata
stainless-app[bot] Jun 20, 2025
d89e98a
feat(api): api update
stainless-app[bot] Jun 20, 2025
b323450
feat(api): api update
stainless-app[bot] Jun 21, 2025
ff649ef
feat(api): api update
stainless-app[bot] Jun 21, 2025
75d20f0
codegen metadata
stainless-app[bot] Jun 21, 2025
204c9ec
feat(client): add escape hatch for null slice & maps
stainless-app[bot] Jun 21, 2025
884e0ef
chore: fix documentation of null map
stainless-app[bot] Jun 21, 2025
811a539
feat(api): api update
stainless-app[bot] Jun 22, 2025
6c46b16
feat(api): api update
stainless-app[bot] Jun 22, 2025
193edf7
feat(api): api update
stainless-app[bot] Jun 22, 2025
5dd0b0d
feat(api): api update
stainless-app[bot] Jun 22, 2025
0f42d7b
feat(api): api update
stainless-app[bot] Jun 22, 2025
01006de
codegen metadata
stainless-app[bot] Jun 23, 2025
a877ba7
feat(api): api update
stainless-app[bot] Jun 23, 2025
53fd9dd
feat(api): api update
stainless-app[bot] Jun 23, 2025
bedf50c
feat(api): api update
stainless-app[bot] Jun 23, 2025
1d484ca
chore(internal): codegen related update
stainless-app[bot] Jun 24, 2025
a45c3f6
feat(api): api update
stainless-app[bot] Jun 24, 2025
e5c94c1
feat(api): api update
stainless-app[bot] Jun 24, 2025
2451e69
feat(api): api update
stainless-app[bot] Jun 24, 2025
f5abb13
feat(api): api update
stainless-app[bot] Jun 24, 2025
c938da7
feat(api): api update
stainless-app[bot] Jun 24, 2025
e9e63a0
feat(api): api update
stainless-app[bot] Jun 24, 2025
1b0bd9d
feat(api): api update
stainless-app[bot] Jun 24, 2025
8328360
feat(api): api update
stainless-app[bot] Jun 24, 2025
52eba4f
feat(api): api update
stainless-app[bot] Jun 25, 2025
40790fd
feat(api): api update
stainless-app[bot] Jun 25, 2025
e176fa4
feat(api): api update
stainless-app[bot] Jun 25, 2025
929d096
feat(api): api update
stainless-app[bot] Jun 25, 2025
145e7fd
feat(api): api update
stainless-app[bot] Jun 25, 2025
af13ffe
feat(api): api update
stainless-app[bot] Jun 25, 2025
fe2799a
feat(api): api update
stainless-app[bot] Jun 25, 2025
b80fda0
feat(api): api update
stainless-app[bot] Jun 25, 2025
9a7cfa0
codegen metadata
stainless-app[bot] Jun 25, 2025
5807ced
codegen metadata
stainless-app[bot] Jun 25, 2025
5e97111
feat(api): api update
stainless-app[bot] Jun 25, 2025
69b9630
feat(api): api update
stainless-app[bot] Jun 25, 2025
f123f79
feat(api): api update
stainless-app[bot] Jun 25, 2025
b2f57bc
feat(api): api update
stainless-app[bot] Jun 25, 2025
b6cff81
feat(api): api update
stainless-app[bot] Jun 25, 2025
69f838f
codegen metadata
stainless-app[bot] Jun 25, 2025
14ef783
codegen metadata
stainless-app[bot] Jun 26, 2025
30e14d1
feat(api): api update
stainless-app[bot] Jun 26, 2025
3922807
feat(api): api update
stainless-app[bot] Jun 26, 2025
081873f
feat(api): api update
stainless-app[bot] Jun 26, 2025
58f628f
feat(api): api update
stainless-app[bot] Jun 26, 2025
e1534c3
feat(api): api update
stainless-app[bot] Jun 27, 2025
f202de1
feat(api): api update
stainless-app[bot] Jun 27, 2025
15f30db
feat(api): api update
stainless-app[bot] Jun 27, 2025
7e98f6a
codegen metadata
stainless-app[bot] Jun 27, 2025
3f1df17
codegen metadata
stainless-app[bot] Jun 27, 2025
7392eb9
fix: don't try to deserialize as json when ResponseBodyInto is []byte
stainless-app[bot] Jun 28, 2025
d0c4c89
chore(ci): only run for pushes and fork pull requests
stainless-app[bot] Jun 28, 2025
e50f936
feat(api): api update
stainless-app[bot] Jun 28, 2025
80e2430
feat(api): api update
stainless-app[bot] Jun 29, 2025
223c187
feat(api): api update
stainless-app[bot] Jun 29, 2025
ef96bfc
codegen metadata
stainless-app[bot] Jun 29, 2025
48a2aca
feat(api): api update
stainless-app[bot] Jun 29, 2025
bef6544
feat(api): api update
stainless-app[bot] Jul 1, 2025
1116f45
feat(api): api update
stainless-app[bot] Jul 1, 2025
1b0ee97
feat(api): api update
stainless-app[bot] Jul 4, 2025
414c940
feat(api): api update
stainless-app[bot] Jul 7, 2025
95e0a89
feat(api): api update
stainless-app[bot] Jul 7, 2025
2c0130c
feat(api): api update
stainless-app[bot] Jul 7, 2025
8058b07
chore: lint tests
stainless-app[bot] Jul 8, 2025
020b223
codegen metadata
stainless-app[bot] Jul 8, 2025
62d164a
feat(api): api update
stainless-app[bot] Jul 8, 2025
f63b38e
codegen metadata
stainless-app[bot] Jul 8, 2025
2c9d806
chore(internal): fix lint script for tests
stainless-app[bot] Jul 9, 2025
8b56e81
codegen metadata
stainless-app[bot] Jul 10, 2025
f57e709
feat(api): api update
stainless-app[bot] Jul 10, 2025
2e77e66
feat(api): api update
stainless-app[bot] Jul 10, 2025
7407836
feat(api): api update
stainless-app[bot] Jul 11, 2025
2a1e27d
feat(api): api update
stainless-app[bot] Jul 11, 2025
f1ee098
chore: lint tests in subpackages
stainless-app[bot] Jul 11, 2025
c500de8
feat(api): api update
stainless-app[bot] Jul 11, 2025
c433877
chore(internal): codegen related update
stainless-app[bot] Jul 12, 2025
8c5c727
codegen metadata
stainless-app[bot] Jul 14, 2025
cdd28ef
feat(api): api update
stainless-app[bot] Jul 14, 2025
397e63a
feat(api): api update
stainless-app[bot] Jul 14, 2025
b816e2e
feat(api): api update
stainless-app[bot] Jul 15, 2025
dfcbc31
feat(api): api update
stainless-app[bot] Jul 15, 2025
6d174a0
feat(api): api update
stainless-app[bot] Jul 16, 2025
b92812f
codegen metadata
stainless-app[bot] Jul 16, 2025
55a288b
feat(api): api update
stainless-app[bot] Jul 17, 2025
ed9eb13
feat(api): api update
stainless-app[bot] Jul 17, 2025
8c8ffbc
codegen metadata
stainless-app[bot] Jul 17, 2025
26b41a8
feat(api): api update
stainless-app[bot] Jul 17, 2025
0c5d6f3
feat(api): api update
stainless-app[bot] Jul 18, 2025
b0a7507
feat(api): api update
stainless-app[bot] Jul 18, 2025
dba3e6e
feat(api): api update
stainless-app[bot] Jul 18, 2025
8923b10
codegen metadata
stainless-app[bot] Jul 21, 2025
e3141cc
codegen metadata
stainless-app[bot] Jul 21, 2025
33333ea
codegen metadata
stainless-app[bot] Jul 21, 2025
be9dd83
feat(api): api update
stainless-app[bot] Jul 21, 2025
07571d3
fix(client): process custom base url ahead of time
stainless-app[bot] Jul 22, 2025
34b1efb
feat(api): api update
stainless-app[bot] Jul 22, 2025
3dcaa59
feat(api): api update
stainless-app[bot] Jul 22, 2025
5969b26
feat(api): api update
stainless-app[bot] Jul 24, 2025
760bd90
feat(api): api update
stainless-app[bot] Jul 25, 2025
ff175da
feat(api): api update
stainless-app[bot] Jul 26, 2025
7c3e649
feat(api): api update
stainless-app[bot] Jul 28, 2025
be7202d
codegen metadata
stainless-app[bot] Jul 29, 2025
2b3bc86
feat(api): api update
stainless-app[bot] Jul 29, 2025
c4687d8
feat(api): api update
stainless-app[bot] Jul 29, 2025
cd5b656
feat(api): api update
stainless-app[bot] Jul 29, 2025
d978c4f
feat(api): api update
stainless-app[bot] Jul 29, 2025
17e4527
feat(api): api update
stainless-app[bot] Aug 1, 2025
1e8a588
feat(api): api update
stainless-app[bot] Aug 4, 2025
50bc839
feat(api): api update
stainless-app[bot] Aug 6, 2025
088c63b
codegen metadata
stainless-app[bot] Aug 6, 2025
9d20249
feat(api): api update
stainless-app[bot] Aug 6, 2025
422bd21
feat(api): api update
stainless-app[bot] Aug 6, 2025
375ee28
feat(api): api update
stainless-app[bot] Aug 6, 2025
bc1540c
feat(api): api update
stainless-app[bot] Aug 6, 2025
73f66ae
feat(api): api update
stainless-app[bot] Aug 6, 2025
1b5ae1a
feat(api): api update
stainless-app[bot] Aug 6, 2025
0032527
feat(api): api update
stainless-app[bot] Aug 6, 2025
83f80ad
feat(api): api update
stainless-app[bot] Aug 7, 2025
7f1e5b6
feat(client): support optional json html escaping
stainless-app[bot] Aug 7, 2025
a601fcd
feat(api): api update
stainless-app[bot] Aug 7, 2025
7add675
codegen metadata
stainless-app[bot] Aug 7, 2025
54122ef
codegen metadata
stainless-app[bot] Aug 8, 2025
7958ec0
feat(api): api update
stainless-app[bot] Aug 8, 2025
37e0e8c
chore: update @stainless-api/prism-cli to v5.15.0
stainless-app[bot] Aug 9, 2025
7c882fb
chore(internal): update comment in script
stainless-app[bot] Aug 9, 2025
e7aa140
codegen metadata
stainless-app[bot] Aug 11, 2025
fa2f136
chore(internal): codegen related update
stainless-app[bot] Aug 12, 2025
d64c149
feat(api): api update
stainless-app[bot] Aug 12, 2025
b2b4a15
feat(api): api update
stainless-app[bot] Aug 13, 2025
dcad514
feat(api): api update
stainless-app[bot] Aug 13, 2025
d3b2ac2
feat(api): api update
stainless-app[bot] Aug 13, 2025
1808191
codegen metadata
stainless-app[bot] Aug 13, 2025
939453a
feat(api): api update
stainless-app[bot] Aug 14, 2025
249a620
feat(api): api update
stainless-app[bot] Aug 15, 2025
0cc8792
feat(api): api update
stainless-app[bot] Aug 18, 2025
ae9612a
feat(api): api update
stainless-app[bot] Aug 18, 2025
8f7cc17
feat(api): api update
stainless-app[bot] Aug 18, 2025
740c11c
feat(api): api update
stainless-app[bot] Aug 19, 2025
ddaaf11
feat(api): api update
stainless-app[bot] Aug 19, 2025
d9553b9
feat(api): api update
stainless-app[bot] Aug 20, 2025
b0192ac
feat(api): api update
stainless-app[bot] Aug 20, 2025
ac501e4
feat(api): api update
stainless-app[bot] Aug 21, 2025
6de2a16
codegen metadata
stainless-app[bot] Aug 21, 2025
4274f90
feat(api): api update
stainless-app[bot] Aug 21, 2025
d598423
codegen metadata
stainless-app[bot] Aug 22, 2025
3d1a3ac
feat(api): api update
stainless-app[bot] Aug 22, 2025
b40ae34
feat(api): api update
stainless-app[bot] Aug 25, 2025
f148589
feat(api): api update
stainless-app[bot] Aug 25, 2025
b29f0c8
feat(api): api update
stainless-app[bot] Aug 25, 2025
4310952
feat(api): api update
stainless-app[bot] Aug 26, 2025
50aaf59
feat(api): api update
stainless-app[bot] Aug 26, 2025
264925b
feat(api): api update
stainless-app[bot] Aug 26, 2025
211a0c2
feat(api): api update
stainless-app[bot] Aug 26, 2025
7b06cd6
feat(api): api update
stainless-app[bot] Aug 26, 2025
9a86a38
feat(api): api update
stainless-app[bot] Aug 26, 2025
656247e
feat(api): api update
stainless-app[bot] Aug 27, 2025
86f15cf
feat(api): api update
stainless-app[bot] Aug 27, 2025
4e841d6
feat(api): api update
stainless-app[bot] Aug 27, 2025
5e975a0
feat(api): api update
stainless-app[bot] Aug 27, 2025
f28690b
feat(api): api update
stainless-app[bot] Aug 27, 2025
9cdfdca
feat(api): api update
stainless-app[bot] Aug 27, 2025
e88f717
feat(api): api update
stainless-app[bot] Aug 28, 2025
bc472dc
feat(api): api update
stainless-app[bot] Aug 28, 2025
3bf2721
feat(api): api update
stainless-app[bot] Aug 28, 2025
2f3cf42
codegen metadata
stainless-app[bot] Aug 28, 2025
c9a21f6
feat(api): api update
stainless-app[bot] Aug 28, 2025
7d639fe
feat(api): api update
stainless-app[bot] Aug 28, 2025
418a2fd
fix: close body before retrying
stainless-app[bot] Aug 29, 2025
6beb16b
feat(api): api update
stainless-app[bot] Aug 29, 2025
f0e26ff
feat(api): api update
stainless-app[bot] Sep 1, 2025
3c18f23
codegen metadata
stainless-app[bot] Sep 1, 2025
d79af73
chore(internal): codegen related update
stainless-app[bot] Sep 3, 2025
b88a3a6
feat(api): api update
stainless-app[bot] Sep 4, 2025
da4c6df
feat(api): api update
stainless-app[bot] Sep 4, 2025
80691e8
codegen metadata
stainless-app[bot] Sep 4, 2025
e101472
codegen metadata
stainless-app[bot] Sep 5, 2025
7ebf9aa
codegen metadata
stainless-app[bot] Sep 5, 2025
9fa322f
codegen metadata
stainless-app[bot] Sep 5, 2025
d14c253
codegen metadata
stainless-app[bot] Sep 5, 2025
47c3b40
codegen metadata
stainless-app[bot] Sep 5, 2025
0731ef4
codegen metadata
stainless-app[bot] Sep 5, 2025
bd23f4e
fix(internal): unmarshal correctly when there are multiple discrimina…
stainless-app[bot] Sep 6, 2025
87bf509
codegen metadata
stainless-app[bot] Sep 8, 2025
34c5ae2
codegen metadata
stainless-app[bot] Sep 8, 2025
d673178
feat(api): api update
stainless-app[bot] Sep 8, 2025
76670ad
codegen metadata
stainless-app[bot] Sep 8, 2025
d06487e
codegen metadata
stainless-app[bot] Sep 8, 2025
5b05410
codegen metadata
stainless-app[bot] Sep 8, 2025
e6b2c6c
codegen metadata
stainless-app[bot] Sep 8, 2025
2ce0ac9
codegen metadata
stainless-app[bot] Sep 8, 2025
14ea9dd
codegen metadata
stainless-app[bot] Sep 8, 2025
8f9ed61
feat(api): api update
stainless-app[bot] Sep 8, 2025
c43bb6f
codegen metadata
stainless-app[bot] Sep 9, 2025
dd10cf7
codegen metadata
stainless-app[bot] Sep 9, 2025
1cf44d4
codegen metadata
stainless-app[bot] Sep 9, 2025
3950ec7
codegen metadata
stainless-app[bot] Sep 9, 2025
343a56f
codegen metadata
stainless-app[bot] Sep 9, 2025
0ea7080
codegen metadata
stainless-app[bot] Sep 9, 2025
c091701
codegen metadata
stainless-app[bot] Sep 9, 2025
a5420fb
feat(api): api update
stainless-app[bot] Sep 9, 2025
7e6440f
codegen metadata
stainless-app[bot] Sep 10, 2025
040356a
feat(api): api update
stainless-app[bot] Sep 10, 2025
3cfbeac
codegen metadata
stainless-app[bot] Sep 10, 2025
a15e311
codegen metadata
stainless-app[bot] Sep 10, 2025
8a9f712
codegen metadata
stainless-app[bot] Sep 11, 2025
e49ef15
codegen metadata
stainless-app[bot] Sep 11, 2025
57a09d1
codegen metadata
stainless-app[bot] Sep 11, 2025
38f5d15
feat(api): api update
stainless-app[bot] Sep 11, 2025
c7a500f
feat(api): api update
stainless-app[bot] Sep 12, 2025
aab6d86
feat(api): api update
stainless-app[bot] Sep 16, 2025
711b6c7
feat(api): api update
stainless-app[bot] Sep 17, 2025
fddf9b3
feat(api): api update
stainless-app[bot] Sep 18, 2025
9775338
feat(api): api update
stainless-app[bot] Sep 19, 2025
222f4db
feat(api): api update
stainless-app[bot] Sep 19, 2025
2d0d0d3
chore: bump minimum go version to 1.22
stainless-app[bot] Sep 20, 2025
628c1b8
chore: update more docs for 1.22
stainless-app[bot] Sep 20, 2025
4119eef
fix: use slices.Concat instead of sometimes modifying r.Options
stainless-app[bot] Sep 20, 2025
216e759
chore: do not install brew dependencies in ./scripts/bootstrap by def…
stainless-app[bot] Sep 20, 2025
1d41a5c
feat(api): api update
stainless-app[bot] Sep 24, 2025
bb36ff4
feat(api): api update
stainless-app[bot] Sep 24, 2025
35133f1
feat(api): api update
stainless-app[bot] Sep 24, 2025
c655f46
codegen metadata
stainless-app[bot] Sep 24, 2025
8fccae7
feat(api): api update
stainless-app[bot] Sep 25, 2025
57ed3f9
feat(api): api update
stainless-app[bot] Sep 25, 2025
80022d0
feat(api): api update
stainless-app[bot] Sep 25, 2025
1ac238f
fix: bugfix for setting JSON keys with special characters
stainless-app[bot] Sep 26, 2025
bb77800
feat(api): api update
stainless-app[bot] Sep 26, 2025
a308c5a
feat(api): api update
stainless-app[bot] Sep 26, 2025
cd407f1
codegen metadata
stainless-app[bot] Sep 26, 2025
236605f
feat(api): api update
stainless-app[bot] Sep 28, 2025
8e6a054
feat(api): api update
stainless-app[bot] Sep 30, 2025
69d865a
feat(api): api update
stainless-app[bot] Oct 10, 2025
66d33b4
feat(api): api update
stainless-app[bot] Oct 11, 2025
9940e48
feat(api): api update
stainless-app[bot] Oct 14, 2025
ba3b2da
feat(api): api update
stainless-app[bot] Oct 15, 2025
a5eb026
codegen metadata
stainless-app[bot] Oct 15, 2025
a4ab731
feat(api): api update
stainless-app[bot] Oct 15, 2025
15bca04
codegen metadata
stainless-app[bot] Oct 15, 2025
6a608f3
feat(api): api update
stainless-app[bot] Oct 15, 2025
cf882cd
feat(api): api update
stainless-app[bot] Oct 16, 2025
01a8d4f
feat(api): api update
stainless-app[bot] Oct 17, 2025
baad7ff
fix(client): marshal nested multipart body
stainless-app[bot] Oct 22, 2025
13f2cfb
feat(api): api update
stainless-app[bot] Oct 22, 2025
1968da8
feat(api): api update
stainless-app[bot] Oct 22, 2025
103f112
codegen metadata
stainless-app[bot] Oct 23, 2025
f6625c3
feat(api): api update
stainless-app[bot] Oct 24, 2025
70f8bf4
release: 0.1.0-alpha.4
stainless-app[bot] Oct 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
timeout-minutes: 10
name: lint
runs-on: ${{ github.repository == 'stainless-sdks/gbox-sdk-go' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork

steps:
- uses: actions/checkout@v4
Expand All @@ -32,6 +33,7 @@ jobs:
timeout-minutes: 10
name: test
runs-on: ${{ github.repository == 'stainless-sdks/gbox-sdk-go' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.3"
".": "0.1.0-alpha.4"
}
8 changes: 4 additions & 4 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 38
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gbox%2Fgbox-sdk-21b86f090470f516255171dcb8e840c5cde51529f50fe1cf91d8f3d5e299588d.yml
openapi_spec_hash: fcc2bd33fc48cb903008804b908deceb
config_hash: a5110c90220411b677136bb0447870d8
configured_endpoints: 93
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gbox%2Fgbox-sdk-f635173eacab4cd113f0f0d93fbe7c54cfc8878da547f2569fd2347deac8d1eb.yml
openapi_spec_hash: 45881a4a8bcb3ee80eba3b99148e4edc
config_hash: 09531a3b47b37eecfb541e383d99e62c
208 changes: 208 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $ ./scripts/lint

This will install all the required dependencies and build the SDK.

You can also [install go 1.18+ manually](https://go.dev/doc/install).
You can also [install go 1.22+ manually](https://go.dev/doc/install).

## Modifying/Adding code

Expand Down
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Gbox Client Go API Library

<!-- x-release-please-start-version -->

<a href="https://pkg.go.dev/github.com/babelcloud/gbox-sdk-go"><img src="https://pkg.go.dev/badge/github.com/babelcloud/gbox-sdk-go.svg" alt="Go Reference"></a>

<!-- x-release-please-end -->

The Gbox Client Go library provides convenient access to the Gbox Client REST API
from applications written in Go.

Expand All @@ -24,14 +28,14 @@ Or to pin the version:
<!-- x-release-please-start-version -->

```sh
go get -u 'github.com/babelcloud/[email protected].3'
go get -u 'github.com/babelcloud/[email protected].4'
```

<!-- x-release-please-end -->

## Requirements

This library requires Go 1.18+.
This library requires Go 1.22+.

## Usage

Expand All @@ -50,8 +54,8 @@ import (

func main() {
client := gboxsdk.NewClient(
option.WithAPIKey("My API Key"), // defaults to os.LookupEnv("GBOX_API_KEY")
option.WithEnvironmentSelfHost(), // defaults to option.WithEnvironmentProduction()
option.WithAPIKey("My API Key"), // defaults to os.LookupEnv("GBOX_API_KEY")
option.WithEnvironmentSelfHosting(), // or option.WithEnvironmentProduction() | option.WithEnvironmentInternal(); defaults to option.WithEnvironmentProduction()
)
androidBox, err := client.V1.Boxes.NewAndroid(context.TODO(), gboxsdk.V1BoxNewAndroidParams{
CreateAndroidBox: gboxsdk.CreateAndroidBoxParam{},
Expand Down Expand Up @@ -350,24 +354,27 @@ which can be used to wrap any `io.Reader` with the appropriate file name and con
```go
// A file from the file system
file, err := os.Open("/path/to/file")
gboxsdk.V1BoxAndroidInstallParamsInstallAndroidAppByFile{
Apk: file,
gboxsdk.V1BoxFWriteParamsWriteFileByBinary{
Content: file,
Path: "/home/user/documents/output.txt",
}

// A file from a string
gboxsdk.V1BoxAndroidInstallParamsInstallAndroidAppByFile{
Apk: strings.NewReader("my file contents"),
gboxsdk.V1BoxFWriteParamsWriteFileByBinary{
Content: strings.NewReader("my file contents"),
Path: "/home/user/documents/output.txt",
}

// With a custom filename and contentType
gboxsdk.V1BoxAndroidInstallParamsInstallAndroidAppByFile{
Apk: gboxsdk.File(strings.NewReader(`{"hello": "foo"}`), "file.go", "application/json"),
gboxsdk.V1BoxFWriteParamsWriteFileByBinary{
Content: gboxsdk.File(strings.NewReader(`{"hello": "foo"}`), "file.go", "application/json"),
Path: "/home/user/documents/output.txt",
}
```

### Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
Certain errors will be automatically retried 0 times by default, with a short exponential backoff.
We retry by default all connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit,
and >=500 Internal errors.

Expand Down
218 changes: 178 additions & 40 deletions api.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"net/http"
"os"
"slices"

"github.com/babelcloud/gbox-sdk-go/internal/requestconfig"
"github.com/babelcloud/gbox-sdk-go/option"
Expand Down Expand Up @@ -78,7 +79,7 @@ func NewClient(opts ...option.RequestOption) (r Client) {
// For even greater flexibility, see [option.WithResponseInto] and
// [option.WithResponseBodyInto].
func (r *Client) Execute(ctx context.Context, method string, path string, params any, res any, opts ...option.RequestOption) error {
opts = append(r.Options, opts...)
opts = slices.Concat(r.Options, opts)
return requestconfig.ExecuteNewRequest(ctx, method, path, params, res, opts...)
}

Expand Down
12 changes: 6 additions & 6 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func TestRetryAfter(t *testing.T) {
}

attempts := len(retryCountHeaders)
if attempts != 3 {
t.Errorf("Expected %d attempts, got %d", 3, attempts)
if attempts != 1 {
t.Errorf("Expected %d attempts, got %d", 1, attempts)
}

expectedRetryCountHeaders := []string{"0", "1", "2"}
expectedRetryCountHeaders := []string{"0"}
if !reflect.DeepEqual(retryCountHeaders, expectedRetryCountHeaders) {
t.Errorf("Expected %v retry count headers, got %v", expectedRetryCountHeaders, retryCountHeaders)
}
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestDeleteRetryCountHeader(t *testing.T) {
t.Error("Expected there to be a cancel error")
}

expectedRetryCountHeaders := []string{"", "", ""}
expectedRetryCountHeaders := []string{""}
if !reflect.DeepEqual(retryCountHeaders, expectedRetryCountHeaders) {
t.Errorf("Expected %v retry count headers, got %v", expectedRetryCountHeaders, retryCountHeaders)
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestOverwriteRetryCountHeader(t *testing.T) {
t.Error("Expected there to be a cancel error")
}

expectedRetryCountHeaders := []string{"42", "42", "42"}
expectedRetryCountHeaders := []string{"42"}
if !reflect.DeepEqual(retryCountHeaders, expectedRetryCountHeaders) {
t.Errorf("Expected %v retry count headers, got %v", expectedRetryCountHeaders, retryCountHeaders)
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestRetryAfterMs(t *testing.T) {
if err == nil {
t.Error("Expected there to be a cancel error")
}
if want := 3; attempts != want {
if want := 1; attempts != want {
t.Errorf("Expected %d attempts, got %d", want, attempts)
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/babelcloud/gbox-sdk-go

go 1.21
go 1.22

require (
github.com/tidwall/gjson v1.14.4
Expand Down
88 changes: 88 additions & 0 deletions internal/apijson/decodeparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,36 @@ func init() {
})
}

type FooVariant struct {
Type string `json:"type,required"`
Value string `json:"value,required"`
}

type BarVariant struct {
Type string `json:"type,required"`
Enable bool `json:"enable,required"`
}

type MultiDiscriminatorUnion struct {
OfFoo *FooVariant `json:",inline"`
OfBar *BarVariant `json:",inline"`

paramUnion
}

func init() {
apijson.RegisterDiscriminatedUnion[MultiDiscriminatorUnion]("type", map[string]reflect.Type{
"foo": reflect.TypeOf(FooVariant{}),
"foo_v2": reflect.TypeOf(FooVariant{}),
"bar": reflect.TypeOf(BarVariant{}),
"bar_legacy": reflect.TypeOf(BarVariant{}),
})
}

func (m *MultiDiscriminatorUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, m)
}

func (d *DiscriminatedUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, d)
}
Expand Down Expand Up @@ -408,3 +438,61 @@ func TestDiscriminatedUnion(t *testing.T) {
})
}
}

func TestMultiDiscriminatorUnion(t *testing.T) {
tests := map[string]struct {
raw string
target MultiDiscriminatorUnion
shouldFail bool
}{
"foo_variant": {
raw: `{"type":"foo","value":"test"}`,
target: MultiDiscriminatorUnion{OfFoo: &FooVariant{
Type: "foo",
Value: "test",
}},
},
"foo_v2_variant": {
raw: `{"type":"foo_v2","value":"test_v2"}`,
target: MultiDiscriminatorUnion{OfFoo: &FooVariant{
Type: "foo_v2",
Value: "test_v2",
}},
},
"bar_variant": {
raw: `{"type":"bar","enable":true}`,
target: MultiDiscriminatorUnion{OfBar: &BarVariant{
Type: "bar",
Enable: true,
}},
},
"bar_legacy_variant": {
raw: `{"type":"bar_legacy","enable":false}`,
target: MultiDiscriminatorUnion{OfBar: &BarVariant{
Type: "bar_legacy",
Enable: false,
}},
},
"invalid_type": {
raw: `{"type":"unknown","value":"test"}`,
target: MultiDiscriminatorUnion{},
shouldFail: true,
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
var dst MultiDiscriminatorUnion
err := json.Unmarshal([]byte(test.raw), &dst)
if err != nil && !test.shouldFail {
t.Fatalf("failed unmarshal with err: %v", err)
}
if err == nil && test.shouldFail {
t.Fatalf("expected unmarshal to fail but it succeeded")
}
if !reflect.DeepEqual(dst, test.target) {
t.Fatalf("failed equality, got %#v but expected %#v", dst, test.target)
}
})
}
}
14 changes: 7 additions & 7 deletions internal/apijson/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (

var encoders sync.Map // map[encoderEntry]encoderFunc

// If we want to set a literal key value into JSON using sjson, we need to make sure it doesn't have
// special characters that sjson interprets as a path.
var EscapeSJSONKey = strings.NewReplacer("\\", "\\\\", "|", "\\|", "#", "\\#", "@", "\\@", "*", "\\*", ".", "\\.", ":", "\\:", "?", "\\?").Replace

func Marshal(value any) ([]byte, error) {
e := &encoder{dateFormat: time.RFC3339}
return e.marshal(value)
Expand Down Expand Up @@ -270,7 +274,7 @@ func (e *encoder) newStructTypeEncoder(t reflect.Type) encoderFunc {
if encoded == nil {
continue
}
json, err = sjson.SetRawBytes(json, ef.tag.name, encoded)
json, err = sjson.SetRawBytes(json, EscapeSJSONKey(ef.tag.name), encoded)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -348,7 +352,7 @@ func (e *encoder) encodeMapEntries(json []byte, v reflect.Value) ([]byte, error)
}
encodedKeyString = string(encodedKeyBytes)
}
encodedKey := []byte(sjsonReplacer.Replace(encodedKeyString))
encodedKey := []byte(encodedKeyString)
pairs = append(pairs, mapPair{key: encodedKey, value: iter.Value()})
}

Expand All @@ -366,7 +370,7 @@ func (e *encoder) encodeMapEntries(json []byte, v reflect.Value) ([]byte, error)
if len(encodedValue) == 0 {
continue
}
json, err = sjson.SetRawBytes(json, string(p.key), encodedValue)
json, err = sjson.SetRawBytes(json, EscapeSJSONKey(string(p.key)), encodedValue)
if err != nil {
return nil, err
}
Expand All @@ -386,7 +390,3 @@ func (e *encoder) newMapEncoder(_ reflect.Type) encoderFunc {
return json, nil
}
}

// If we want to set a literal key value into JSON using sjson, we need to make sure it doesn't have
// special characters that sjson interprets as a path.
var sjsonReplacer *strings.Replacer = strings.NewReplacer(".", "\\.", ":", "\\:", "*", "\\*")
Loading
Loading