Skip to content

Commit 02237b7

Browse files
committed
Support clibase.struct
1 parent 2744539 commit 02237b7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

scripts/apitypings/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,11 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
830830
// We would need to add more logic to determine this, but for now
831831
// just hard code them.
832832
switch n.String() {
833+
case "github.com/coder/coder/v2/cli/clibase.HostPort":
834+
// Custom marshal json to be a string
835+
return TypescriptType{ValueType: "string"}, nil
836+
case "github.com/coder/coder/v2/cli/clibase.StringArray":
837+
return TypescriptType{ValueType: "string[]"}, nil
833838
case "github.com/coder/coder/v2/cli/clibase.String":
834839
return TypescriptType{ValueType: "string"}, nil
835840
case "github.com/coder/coder/v2/cli/clibase.YAMLConfigPath":
@@ -863,6 +868,17 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
863868
return TypescriptType{ValueType: "string"}, nil
864869
}
865870

871+
// Some hard codes are a bit trickier.
872+
switch {
873+
// Struct is a generic, so the type has generic constraints in the string.
874+
case regexp.MustCompile(`github.com/coder/coder/v2/cli/clibase.Struct\[.*\]`).MatchString(n.String()):
875+
// The marshal json just marshals the underlying value.
876+
str, ok := ty.Underlying().(*types.Struct)
877+
if ok {
878+
return g.typescriptType(str.Field(0).Type())
879+
}
880+
}
881+
866882
// Then see if the type is defined elsewhere. If it is, we can just
867883
// put the objName as it will be defined in the typescript codeblock
868884
// we generate.

0 commit comments

Comments
 (0)