Skip to content

Commit 077e594

Browse files
authored
chore: switch to guts for typescript types generation (coder#15801)
switch to guts for typescript type generation omitempty vs null must now be explicit
1 parent 2ec2e8a commit 077e594

36 files changed

+2139
-1698
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,9 @@ vpn/vpn.pb.go: vpn/vpn.proto
640640
./vpn/vpn.proto
641641

642642
site/src/api/typesGenerated.ts: $(wildcard scripts/apitypings/*) $(shell find ./codersdk $(FIND_EXCLUSIONS) -type f -name '*.go')
643-
go run ./scripts/apitypings/ > $@
643+
# -C sets the directory for the go run command
644+
go run -C ./scripts/apitypings main.go > $@
645+
(cd ./site && npx biome format --write ./src/api/typesGenerated.ts)
644646
./scripts/pnpm_install.sh
645647

646648
site/e2e/provisionerGenerated.ts: provisionerd/proto/provisionerd.pb.go provisionersdk/proto/provisioner.pb.go

codersdk/healthsdk/healthsdk.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (r *HealthcheckReport) Summarize(docsURL string) []string {
131131

132132
// BaseReport holds fields common to various health reports.
133133
type BaseReport struct {
134-
Error *string `json:"error"`
134+
Error *string `json:"error,omitempty"`
135135
Severity health.Severity `json:"severity" enums:"ok,warning,error"`
136136
Warnings []health.Message `json:"warnings"`
137137
Dismissed bool `json:"dismissed"`
@@ -185,8 +185,8 @@ type DERPHealthReport struct {
185185
// Healthy is deprecated and left for backward compatibility purposes, use `Severity` instead.
186186
Healthy bool `json:"healthy"`
187187
Regions map[int]*DERPRegionReport `json:"regions"`
188-
Netcheck *netcheck.Report `json:"netcheck"`
189-
NetcheckErr *string `json:"netcheck_err"`
188+
Netcheck *netcheck.Report `json:"netcheck,omitempty"`
189+
NetcheckErr *string `json:"netcheck_err,omitempty"`
190190
NetcheckLogs []string `json:"netcheck_logs"`
191191
}
192192

@@ -196,7 +196,7 @@ type DERPRegionReport struct {
196196
Healthy bool `json:"healthy"`
197197
Severity health.Severity `json:"severity" enums:"ok,warning,error"`
198198
Warnings []health.Message `json:"warnings"`
199-
Error *string `json:"error"`
199+
Error *string `json:"error,omitempty"`
200200
Region *tailcfg.DERPRegion `json:"region"`
201201
NodeReports []*DERPNodeReport `json:"node_reports"`
202202
}
@@ -207,7 +207,7 @@ type DERPNodeReport struct {
207207
Healthy bool `json:"healthy"`
208208
Severity health.Severity `json:"severity" enums:"ok,warning,error"`
209209
Warnings []health.Message `json:"warnings"`
210-
Error *string `json:"error"`
210+
Error *string `json:"error,omitempty"`
211211

212212
Node *tailcfg.DERPNode `json:"node"`
213213

codersdk/organizations.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ type CreateTemplateRequest struct {
157157
// AllowUserAutostart allows users to set a schedule for autostarting their
158158
// workspace. By default this is true. This can only be disabled when using
159159
// an enterprise license.
160-
AllowUserAutostart *bool `json:"allow_user_autostart"`
160+
AllowUserAutostart *bool `json:"allow_user_autostart,omitempty"`
161161

162162
// AllowUserAutostop allows users to set a custom workspace TTL to use in
163163
// place of the template's DefaultTTL field. By default this is true. If
164164
// false, the DefaultTTL will always be used. This can only be disabled when
165165
// using an enterprise license.
166-
AllowUserAutostop *bool `json:"allow_user_autostop"`
166+
AllowUserAutostop *bool `json:"allow_user_autostop,omitempty"`
167167

168168
// FailureTTLMillis allows optionally specifying the max lifetime before Coder
169169
// stops all resources for failed workspaces created from this template.
@@ -202,7 +202,7 @@ type CreateWorkspaceRequest struct {
202202
// TemplateVersionID can be used to specify a specific version of a template for creating the workspace.
203203
TemplateVersionID uuid.UUID `json:"template_version_id,omitempty" validate:"required_without=TemplateID,excluded_with=TemplateID" format:"uuid"`
204204
Name string `json:"name" validate:"workspace_name,required"`
205-
AutostartSchedule *string `json:"autostart_schedule"`
205+
AutostartSchedule *string `json:"autostart_schedule,omitempty"`
206206
TTLMillis *int64 `json:"ttl_ms,omitempty"`
207207
// RichParameterValues allows for additional parameters to be provided
208208
// during the initial provision.

codersdk/templates.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ type UpdateTemplateMeta struct {
242242
// any new workspaces from using this template.
243243
// If passed an empty string, will remove the deprecated message, making
244244
// the template usable for new workspaces again.
245-
DeprecationMessage *string `json:"deprecation_message"`
245+
DeprecationMessage *string `json:"deprecation_message,omitempty"`
246246
// DisableEveryoneGroupAccess allows optionally disabling the default
247247
// behavior of granting the 'everyone' group access to use the template.
248248
// If this is set to true, the template will not be available to all users,
249249
// and must be explicitly granted to users or groups in the permissions settings
250250
// of the template.
251251
DisableEveryoneGroupAccess bool `json:"disable_everyone_group_access"`
252-
MaxPortShareLevel *WorkspaceAgentPortShareLevel `json:"max_port_share_level"`
252+
MaxPortShareLevel *WorkspaceAgentPortShareLevel `json:"max_port_share_level,omitempty"`
253253
}
254254

255255
type TemplateExample struct {

codersdk/workspaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ type UpdateWorkspaceAutostartRequest struct {
260260
// Schedule is expected to be of the form `CRON_TZ=<IANA Timezone> <min> <hour> * * <dow>`
261261
// Example: `CRON_TZ=US/Central 30 9 * * 1-5` represents 0930 in the timezone US/Central
262262
// on weekdays (Mon-Fri). `CRON_TZ` defaults to UTC if not present.
263-
Schedule *string `json:"schedule"`
263+
Schedule *string `json:"schedule,omitempty"`
264264
}
265265

266266
// UpdateWorkspaceAutostart sets the autostart schedule for workspace by id.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ require (
182182
golang.org/x/sync v0.10.0
183183
golang.org/x/sys v0.28.0
184184
golang.org/x/term v0.27.0
185-
golang.org/x/text v0.21.0
185+
golang.org/x/text v0.21.0 // indirect
186186
golang.org/x/tools v0.28.0
187187
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da
188188
google.golang.org/api v0.210.0

scripts/apitypings/README.md

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,4 @@
22

33
This main.go generates typescript types from the codersdk types in Go.
44

5-
# Features
6-
7-
- Supports Go types
8-
- [x] Basics (string/int/etc)
9-
- [x] Maps
10-
- [x] Slices
11-
- [x] Enums
12-
- [x] Pointers
13-
- [ ] External Types (uses `any` atm)
14-
- Some custom external types are hardcoded in (eg: time.Time)
15-
16-
## Type overrides
17-
18-
```golang
19-
type Foo struct {
20-
// Force the typescript type to be a number
21-
CreatedAt time.Duration `json:"created_at" typescript:"number"`
22-
}
23-
```
24-
25-
## Ignore Types
26-
27-
Do not generate ignored types.
28-
29-
```golang
30-
// @typescript-ignore InternalType
31-
type InternalType struct {
32-
// ...
33-
}
34-
```
35-
36-
# Future Ideas
37-
38-
- Use a yaml config for overriding certain types
5+
Uses it's own `go.mod` to exclude goja deps from the main go.mod.

scripts/apitypings/go.mod

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
module github.com/coder/coder/scripts/apitypings
2+
3+
go 1.23.1
4+
5+
toolchain go1.23.3
6+
7+
require (
8+
github.com/coder/coder/v2 v2.0.0-00010101000000-000000000000
9+
github.com/coder/guts v0.0.0-20241209221220-f181da87c0bc
10+
github.com/coder/serpent v0.10.0
11+
github.com/stretchr/testify v1.10.0
12+
)
13+
14+
require (
15+
cdr.dev/slog v1.6.2-0.20241112041820-0ec81e6e67bb // indirect
16+
github.com/DataDog/appsec-internal-go v1.8.0 // indirect
17+
github.com/DataDog/datadog-agent/pkg/obfuscate v0.48.0 // indirect
18+
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.57.0 // indirect
19+
github.com/DataDog/datadog-go/v5 v5.3.0 // indirect
20+
github.com/DataDog/go-libddwaf/v3 v3.4.0 // indirect
21+
github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect
22+
github.com/DataDog/gostackparse v0.7.0 // indirect
23+
github.com/DataDog/sketches-go v1.4.5 // indirect
24+
github.com/Microsoft/go-winio v0.6.2 // indirect
25+
github.com/agext/levenshtein v1.2.3 // indirect
26+
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
27+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
28+
github.com/beorn7/perks v1.0.1 // indirect
29+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
30+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
31+
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 // indirect
32+
github.com/coder/terraform-provider-coder v1.0.2 // indirect
33+
github.com/coreos/go-oidc/v3 v3.11.0 // indirect
34+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
35+
github.com/dlclark/regexp2 v1.11.4 // indirect
36+
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd // indirect
37+
github.com/dustin/go-humanize v1.0.1 // indirect
38+
github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 // indirect
39+
github.com/ebitengine/purego v0.6.0-alpha.5 // indirect
40+
github.com/fatih/color v1.18.0 // indirect
41+
github.com/fatih/structtag v1.2.0 // indirect
42+
github.com/go-chi/chi/v5 v5.1.0 // indirect
43+
github.com/go-jose/go-jose/v4 v4.0.2 // indirect
44+
github.com/go-logr/logr v1.4.2 // indirect
45+
github.com/go-logr/stdr v1.2.2 // indirect
46+
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
47+
github.com/golang/protobuf v1.5.4 // indirect
48+
github.com/google/go-cmp v0.6.0 // indirect
49+
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b // indirect
50+
github.com/google/uuid v1.6.0 // indirect
51+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
52+
github.com/hashicorp/errwrap v1.1.0 // indirect
53+
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
54+
github.com/hashicorp/go-hclog v1.6.3 // indirect
55+
github.com/hashicorp/go-multierror v1.1.1 // indirect
56+
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 // indirect
57+
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
58+
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
59+
github.com/hashicorp/go-uuid v1.0.3 // indirect
60+
github.com/hashicorp/go-version v1.7.0 // indirect
61+
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
62+
github.com/hashicorp/logutils v1.0.0 // indirect
63+
github.com/hashicorp/terraform-plugin-go v0.23.0 // indirect
64+
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
65+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 // indirect
66+
github.com/hashicorp/yamux v0.1.2 // indirect
67+
github.com/klauspost/compress v1.17.9 // indirect
68+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
69+
github.com/mattn/go-colorable v0.1.13 // indirect
70+
github.com/mattn/go-isatty v0.0.20 // indirect
71+
github.com/mitchellh/copystructure v1.2.0 // indirect
72+
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
73+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
74+
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
75+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
76+
github.com/moby/moby v27.3.1+incompatible // indirect
77+
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
78+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
79+
github.com/outcaste-io/ristretto v0.2.3 // indirect
80+
github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986 // indirect
81+
github.com/pion/transport/v2 v2.2.10 // indirect
82+
github.com/pion/udp v0.1.4 // indirect
83+
github.com/pkg/errors v0.9.1 // indirect
84+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
85+
github.com/prometheus/client_golang v1.20.5 // indirect
86+
github.com/prometheus/client_model v0.6.1 // indirect
87+
github.com/prometheus/common v0.61.0 // indirect
88+
github.com/prometheus/procfs v0.15.1 // indirect
89+
github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect
90+
github.com/rivo/uniseg v0.4.7 // indirect
91+
github.com/robfig/cron/v3 v3.0.1 // indirect
92+
github.com/ryanuber/go-glob v1.0.0 // indirect
93+
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
94+
github.com/spaolacci/murmur3 v1.1.0 // indirect
95+
github.com/spf13/pflag v1.0.5 // indirect
96+
github.com/tinylib/msgp v1.2.1 // indirect
97+
github.com/valyala/fasthttp v1.56.0 // indirect
98+
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
99+
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
100+
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
101+
github.com/zclconf/go-cty v1.15.0 // indirect
102+
github.com/zeebo/errs v1.3.0 // indirect
103+
go.nhat.io/otelsql v0.14.0 // indirect
104+
go.opentelemetry.io/otel v1.30.0 // indirect
105+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
106+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 // indirect
107+
go.opentelemetry.io/otel/metric v1.30.0 // indirect
108+
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
109+
go.opentelemetry.io/otel/trace v1.30.0 // indirect
110+
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
111+
go.uber.org/atomic v1.11.0 // indirect
112+
golang.org/x/crypto v0.30.0 // indirect
113+
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
114+
golang.org/x/mod v0.22.0 // indirect
115+
golang.org/x/net v0.32.0 // indirect
116+
golang.org/x/oauth2 v0.24.0 // indirect
117+
golang.org/x/sync v0.10.0 // indirect
118+
golang.org/x/sys v0.28.0 // indirect
119+
golang.org/x/term v0.27.0 // indirect
120+
golang.org/x/text v0.21.0 // indirect
121+
golang.org/x/time v0.8.0 // indirect
122+
golang.org/x/tools v0.28.0 // indirect
123+
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
124+
google.golang.org/appengine v1.6.8 // indirect
125+
google.golang.org/genproto/googleapis/api v0.0.0-20241113202542-65e8d215514f // indirect
126+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697 // indirect
127+
google.golang.org/grpc v1.68.0 // indirect
128+
google.golang.org/protobuf v1.35.2 // indirect
129+
gopkg.in/DataDog/dd-trace-go.v1 v1.69.0 // indirect
130+
gopkg.in/yaml.v3 v3.0.1 // indirect
131+
nhooyr.io/websocket v1.8.7 // indirect
132+
storj.io/drpc v0.0.33 // indirect
133+
)
134+
135+
replace github.com/coder/coder/v2 => ../../

0 commit comments

Comments
 (0)