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
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
Add support for bool and number
  • Loading branch information
f0ssel committed Apr 18, 2022
commit 670e7b7b2e1b3767c1bf350dcc1a6c95a46dba07
7 changes: 7 additions & 0 deletions coderts/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func writeStruct(typeSpec *ast.TypeSpec) (string, error) {
continue
}
fieldType := i.Name
switch fieldType {
case "bool":
fieldType = "boolean"
case "uint64", "uint32", "float64":
fieldType = "number"
}

fieldName := ""
if field.Tag != nil && field.Tag.Value != "" {
for _, pair := range strings.Split(field.Tag.Value, " ") {
Expand Down
16 changes: 8 additions & 8 deletions coderts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface ProvisionerJobLog {

export interface Template {
name: string
workspace_owner_count: uint32
workspace_owner_count: number
}

export interface TemplateVersion {
Expand Down Expand Up @@ -130,11 +130,11 @@ export interface WorkspaceAgent {
}

export interface WorkspaceAgentResourceMetadata {
memory_total: uint64
disk_total: uint64
cpu_cores: uint64
memory_total: number
disk_total: number
cpu_cores: number
cpu_model: string
cpu_mhz: float64
cpu_mhz: number
}

export interface WorkspaceAgentInstanceMetadata {
Expand All @@ -146,20 +146,20 @@ export interface WorkspaceAgentInstanceMetadata {
kernel_architecture: string
cloud: string
jail: string
vnc: bool
vnc: boolean
}

export interface Workspace {
template_name: string
latest_build: WorkspaceBuild
outdated: bool
outdated: boolean
name: string
autostart_schedule: string
autostop_schedule: string
}

export interface CreateWorkspaceBuildRequest {
dry_run: bool
dry_run: boolean
}

export interface UpdateWorkspaceAutostartRequest {
Expand Down