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

Skip to content
Merged
Show file tree
Hide file tree
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
feat: Support map types for codersdk typescript gen
  • Loading branch information
Emyrk committed May 12, 2022
commit 9f3e8e4fe181498f0db81dfff22966d76ff83f59
22 changes: 22 additions & 0 deletions scripts/apitypings/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,28 @@ func (g *Generator) generateAll() (*TypescriptTypes, error) {
// type <Name> string
// These are enums. Store to expand later.
enums[obj.Name()] = obj
case *types.Map:
// Declared maps that are not structs are still valid codersdk objects.
// Handle them custom by calling 'typescriptType' directly instead of
// iterating through each struct field.
// These types support no json/typescript tags.
// These are **NOT** enums, as a map in Go would never be used for an enum.
ts, err := g.typescriptType(obj.Type().Underlying())
if err != nil {
return nil, xerrors.Errorf("(map) generate %q: %w", obj.Name(), err)
}

var str strings.Builder
_, _ = str.WriteString(g.posLine(obj))
if ts.AboveTypeLine != "" {
str.WriteString(ts.AboveTypeLine)
str.WriteRune('\n')
}
// Use similar output syntax to enums.
str.WriteString(fmt.Sprintf("export type %s = %s\n", obj.Name(), ts.ValueType))
structs[obj.Name()] = str.String()
case *types.Array, *types.Slice:
// TODO: @emyrk if you need this, follow the same design as "*types.Map" case.
}
case *types.Var:
// TODO: Are any enums var declarations? This is also codersdk.Me.
Expand Down
3 changes: 3 additions & 0 deletions site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ export interface UserPermissionCheckRequest {
readonly checks: Record<string, UserPermissionCheck>
}

// From codersdk/users.go:79:6
export type UserPermissionCheckResponse = Record<string, boolean>

// From codersdk/users.go:74:6
export interface UserRoles {
readonly roles: string[]
Expand Down