Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09c77d3

Browse files
committed
chore: fixup typegen for preview types
Preview types override the json marshal behavior. Guts should get some upstream changes to make this work more natively.
1 parent a451ea7 commit 09c77d3

File tree

3 files changed

+95
-48
lines changed

3 files changed

+95
-48
lines changed

codersdk/templateversions.go

+8
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

+19-6
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

+68-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)