Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit15584e6

Browse files
authored
chore: fixup typegen for preview types (#17339)
Preview types override the json marshal behavior.
1 parent7b0422b commit15584e6

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+
typeFriendlyDiagnostic= 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+
typeNullHCLString= 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
iferr!=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+
returnbindings.Reference(bindings.Identifier{
96+
Name:"FriendlyDiagnostic",
97+
Package:nil,
98+
Prefix:"",
99+
})
100+
},
101+
"github.com/coder/preview/types.HCLString":func() bindings.ExpressionType {
102+
returnbindings.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 aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp