Skip to content

Commit 15584e6

Browse files
authored
chore: fixup typegen for preview types (#17339)
Preview types override the json marshal behavior.
1 parent 7b0422b commit 15584e6

File tree

3 files changed

+95
-48
lines changed

3 files changed

+95
-48
lines changed

codersdk/templateversions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ type DynamicParametersResponse struct {
141141
// TODO: Workspace tags
142142
}
143143

144+
// FriendlyDiagnostic is included to guarantee it is generated in the output
145+
// types. This is used as the type override for `previewtypes.Diagnostic`.
146+
type FriendlyDiagnostic = previewtypes.FriendlyDiagnostic
147+
148+
// NullHCLString is included to guarantee it is generated in the output
149+
// types. This is used as the type override for `previewtypes.HCLString`.
150+
type NullHCLString = previewtypes.NullHCLString
151+
144152
func (c *Client) TemplateVersionDynamicParameters(ctx context.Context, version uuid.UUID) (*wsjson.Stream[DynamicParametersResponse, DynamicParametersRequest], error) {
145153
conn, err := c.Dial(ctx, fmt.Sprintf("/api/v2/templateversions/%s/dynamic-parameters", version), nil)
146154
if err != nil {

scripts/apitypings/main.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ func main() {
3232
// Serpent has some types referenced in the codersdk.
3333
// We want the referenced types generated.
3434
referencePackages := map[string]string{
35-
"github.com/coder/preview": "",
36-
"github.com/coder/serpent": "Serpent",
37-
"github.com/hashicorp/hcl/v2": "Hcl",
38-
"tailscale.com/derp": "",
35+
"github.com/coder/preview/types": "Preview",
36+
"github.com/coder/serpent": "Serpent",
37+
"tailscale.com/derp": "",
3938
// Conflicting name "DERPRegion"
4039
"tailscale.com/tailcfg": "Tail",
4140
"tailscale.com/net/netcheck": "Netcheck",
@@ -90,8 +89,22 @@ func TypeMappings(gen *guts.GoParser) error {
9089
gen.IncludeCustomDeclaration(map[string]guts.TypeOverride{
9190
"github.com/coder/coder/v2/codersdk.NullTime": config.OverrideNullable(config.OverrideLiteral(bindings.KeywordString)),
9291
// opt.Bool can return 'null' if unset
93-
"tailscale.com/types/opt.Bool": config.OverrideNullable(config.OverrideLiteral(bindings.KeywordBoolean)),
94-
"github.com/hashicorp/hcl/v2.Expression": config.OverrideLiteral(bindings.KeywordUnknown),
92+
"tailscale.com/types/opt.Bool": config.OverrideNullable(config.OverrideLiteral(bindings.KeywordBoolean)),
93+
// hcl diagnostics should be cast to `preview.FriendlyDiagnostic`
94+
"github.com/hashicorp/hcl/v2.Diagnostic": func() bindings.ExpressionType {
95+
return bindings.Reference(bindings.Identifier{
96+
Name: "FriendlyDiagnostic",
97+
Package: nil,
98+
Prefix: "",
99+
})
100+
},
101+
"github.com/coder/preview/types.HCLString": func() bindings.ExpressionType {
102+
return bindings.Reference(bindings.Identifier{
103+
Name: "NullHCLString",
104+
Package: nil,
105+
Prefix: "",
106+
})
107+
},
95108
})
96109

97110
err := gen.IncludeCustom(map[string]string{

site/src/api/typesGenerated.ts

Lines changed: 68 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy