@@ -39,7 +39,6 @@ func main() {
39
39
log .Fatal (ctx , err .Error ())
40
40
}
41
41
42
- log .Info (ctx , "just generated" , slog .F ("basedir" , baseDir ))
43
42
// Just cat the output to a file to capture it
44
43
_ , _ = fmt .Println (output )
45
44
}
@@ -287,6 +286,7 @@ type Maps struct {
287
286
AllowedTypes map [string ]struct {}
288
287
}
289
288
289
+ // objName prepends the package name of a type if it is outside of codersdk.
290
290
func objName (obj types.Object ) string {
291
291
if pkgName := obj .Pkg ().Name (); pkgName != "codersdk" {
292
292
return cases .Title (language .English ).String (pkgName ) + obj .Name ()
@@ -367,7 +367,7 @@ func (g *Generator) generateOne(m *Maps, obj types.Object) error {
367
367
})
368
368
}
369
369
370
- block , err := g .buildUnion (m , obj , union )
370
+ block , err := g .buildUnion (obj , union )
371
371
if err != nil {
372
372
return xerrors .Errorf ("generate union %q: %w" , objName , err )
373
373
}
@@ -400,11 +400,11 @@ func (g *Generator) generateOne(m *Maps, obj types.Object) error {
400
400
func (g * Generator ) posLine (obj types.Object ) string {
401
401
file := g .pkg .Fset .File (obj .Pos ())
402
402
// Do not use filepath, as that changes behavior based on OS
403
- return fmt .Sprintf ("// From %s\n " , path .Join ("codersdk" , filepath .Base (file .Name ())))
403
+ return fmt .Sprintf ("// From %s\n " , path .Join (obj . Pkg (). Name () , filepath .Base (file .Name ())))
404
404
}
405
405
406
406
// buildStruct just prints the typescript def for a type.
407
- func (g * Generator ) buildUnion (m * Maps , obj types.Object , st * types.Union ) (string , error ) {
407
+ func (g * Generator ) buildUnion (obj types.Object , st * types.Union ) (string , error ) {
408
408
var s strings.Builder
409
409
_ , _ = s .WriteString (g .posLine (obj ))
410
410
@@ -784,10 +784,7 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
784
784
// Then see if the type is defined elsewhere. If it is, we can just
785
785
// put the objName as it will be defined in the typescript codeblock
786
786
// we generate.
787
- objName := n .Obj ().Name ()
788
- if pkgName := n .Obj ().Pkg ().Name (); pkgName != "codersdk" {
789
- objName = cases .Title (language .English ).String (pkgName ) + objName
790
- }
787
+ objName := objName (n .Obj ())
791
788
genericName := ""
792
789
genericTypes := make (map [string ]string )
793
790
if obj := g .pkg .Types .Scope ().Lookup (n .Obj ().Name ()); obj != nil {
0 commit comments