Skip to content

feat: generate typescript types from codersdk structs #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Apr 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
f0ssel committed Apr 18, 2022
commit fdedb035c7c37ea3de59780991db79a99e8f3d0b
29 changes: 16 additions & 13 deletions scripts/apitypings/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,31 @@ func run() error {
astFiles = append(astFiles, astFile)
}

// TypeSpec case for structs and type alias
loopSpecs(astFiles, func(spec ast.Spec) {
pos := fset.Position(spec.Pos())
switch s := spec.(type) {
// TypeSpec case for structs and type alias
case *ast.TypeSpec:
out, err := handleTypeSpec(s, pos, enums)
if err != nil {
break
}

_, _ = fmt.Printf(out)
s, ok := spec.(*ast.TypeSpec)
if !ok {
return
}
out, err := handleTypeSpec(s, pos, enums)
if err != nil {
return
}

_, _ = fmt.Printf(out)
})

// ValueSpec case for loading type alias values into the enum map
loopSpecs(astFiles, func(spec ast.Spec) {
switch s := spec.(type) {
// ValueSpec case for const "enums"
case *ast.ValueSpec:
handleValueSpec(s, enums)
s, ok := spec.(*ast.ValueSpec)
if !ok {
return
}
handleValueSpec(s, enums)
})

// write each type alias declaration with possible values
for _, v := range enums {
_, _ = fmt.Printf("%s\n", v)
}
Expand Down