Skip to content

Commit 91d5811

Browse files
committed
Merge branch 'main' into statusbar/presleyp/1032
2 parents 9903c96 + 26b04cc commit 91d5811

File tree

30 files changed

+241
-347
lines changed

30 files changed

+241
-347
lines changed

codersdk/organizations.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ type Organization struct {
2424
// CreateTemplateVersionRequest enables callers to create a new Template Version.
2525
type CreateTemplateVersionRequest struct {
2626
// TemplateID optionally associates a version with a template.
27-
TemplateID uuid.UUID `json:"template_id"`
27+
TemplateID uuid.UUID `json:"template_id,omitempty"`
2828

2929
StorageMethod database.ProvisionerStorageMethod `json:"storage_method" validate:"oneof=file,required"`
3030
StorageSource string `json:"storage_source" validate:"required"`
3131
Provisioner database.ProvisionerType `json:"provisioner" validate:"oneof=terraform echo,required"`
3232
// ParameterValues allows for additional parameters to be provided
3333
// during the dry-run provision stage.
34-
ParameterValues []CreateParameterRequest `json:"parameter_values"`
34+
ParameterValues []CreateParameterRequest `json:"parameter_values,omitempty"`
3535
}
3636

3737
// CreateTemplateRequest provides options when creating a template.
@@ -45,7 +45,7 @@ type CreateTemplateRequest struct {
4545
// template works. There is no reason the data-model cannot support
4646
// empty templates, but it doesn't make sense for users.
4747
VersionID uuid.UUID `json:"template_version_id" validate:"required"`
48-
ParameterValues []CreateParameterRequest `json:"parameter_values"`
48+
ParameterValues []CreateParameterRequest `json:"parameter_values,omitempty"`
4949
}
5050

5151
// CreateWorkspaceRequest provides options for creating a new workspace.
@@ -54,7 +54,7 @@ type CreateWorkspaceRequest struct {
5454
Name string `json:"name" validate:"username,required"`
5555
// ParameterValues allows for additional parameters to be provided
5656
// during the initial provision.
57-
ParameterValues []CreateParameterRequest `json:"parameter_values"`
57+
ParameterValues []CreateParameterRequest `json:"parameter_values,omitempty"`
5858
}
5959

6060
func (c *Client) Organization(ctx context.Context, id uuid.UUID) (Organization, error) {

codersdk/users.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const (
2121
)
2222

2323
type UsersRequest struct {
24-
Search string `json:"search"`
24+
Search string `json:"search,omitempty"`
2525
// Filter users by status
26-
Status string `json:"status"`
26+
Status string `json:"status,omitempty"`
2727
Pagination
2828
}
2929

codersdk/workspaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ type Workspace struct {
3131

3232
// CreateWorkspaceBuildRequest provides options to update the latest workspace build.
3333
type CreateWorkspaceBuildRequest struct {
34-
TemplateVersionID uuid.UUID `json:"template_version_id"`
34+
TemplateVersionID uuid.UUID `json:"template_version_id,omitempty"`
3535
Transition database.WorkspaceTransition `json:"transition" validate:"oneof=create start stop delete,required"`
36-
DryRun bool `json:"dry_run"`
36+
DryRun bool `json:"dry_run,omitempty"`
3737
ProvisionerState []byte `json:"state,omitempty"`
3838
}
3939

scripts/apitypings/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This main.go generates typescript types from the codersdk types in Go.
55
# Features
66

77
- Supports Go types
8-
- [x] Basics (string/int/etc)
8+
- [x] Basics (string/int/etc)
99
- [x] Maps
1010
- [x] Slices
1111
- [x] Enums
@@ -36,5 +36,4 @@ type InternalType struct {
3636

3737
# Future Ideas
3838

39-
- Should `omitempty` in the `json` tag indicate optional?
4039
- Use a yaml config for overriding certain types

site/src/api/api.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from "axios"
22
import { getApiKey, login, logout } from "./api"
3-
import { APIKeyResponse, LoginResponse } from "./types"
3+
import * as TypesGen from "./typesGenerated"
44

55
// Mock the axios module so that no real network requests are made, but rather
66
// we swap in a resolved or rejected value
@@ -12,7 +12,7 @@ describe("api.ts", () => {
1212
describe("login", () => {
1313
it("should return LoginResponse", async () => {
1414
// given
15-
const loginResponse: LoginResponse = {
15+
const loginResponse: TypesGen.LoginWithPasswordResponse = {
1616
session_token: "abc_123_test",
1717
}
1818
const axiosMockPost = jest.fn().mockImplementationOnce(() => {
@@ -87,7 +87,7 @@ describe("api.ts", () => {
8787
describe("getApiKey", () => {
8888
it("should return APIKeyResponse", async () => {
8989
// given
90-
const apiKeyResponse: APIKeyResponse = {
90+
const apiKeyResponse: TypesGen.GenerateAPIKeyResponse = {
9191
key: "abc_123_test",
9292
}
9393
const axiosMockPost = jest.fn().mockImplementationOnce(() => {

site/src/api/api.ts

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
import axios, { AxiosRequestHeaders } from "axios"
22
import { mutate } from "swr"
3-
import * as Types from "./types"
43
import * as TypesGen from "./typesGenerated"
54

65
const CONTENT_TYPE_JSON: AxiosRequestHeaders = {
76
"Content-Type": "application/json",
87
}
98

10-
export const provisioners: Types.Provisioner[] = [
9+
export const provisioners: TypesGen.ProvisionerDaemon[] = [
1110
{
1211
id: "terraform",
1312
name: "Terraform",
13+
created_at: "",
14+
provisioners: [],
1415
},
1516
{
1617
id: "cdr-basic",
1718
name: "Basic",
19+
created_at: "",
20+
provisioners: [],
1821
},
1922
]
2023

2124
export namespace Workspace {
22-
export const create = async (request: Types.CreateWorkspaceRequest): Promise<Types.Workspace> => {
23-
const response = await fetch(`/api/v2/organizations/${request.organization_id}/workspaces`, {
25+
export const create = async (
26+
organizationId: string,
27+
request: TypesGen.CreateWorkspaceRequest,
28+
): Promise<TypesGen.Workspace> => {
29+
const response = await fetch(`/api/v2/organizations/${organizationId}/workspaces`, {
2430
method: "POST",
2531
headers: {
2632
"Content-Type": "application/json",
@@ -43,13 +49,13 @@ export namespace Workspace {
4349
}
4450
}
4551

46-
export const login = async (email: string, password: string): Promise<Types.LoginResponse> => {
52+
export const login = async (email: string, password: string): Promise<TypesGen.LoginWithPasswordResponse> => {
4753
const payload = JSON.stringify({
4854
email,
4955
password,
5056
})
5157

52-
const response = await axios.post<Types.LoginResponse>("/api/v2/users/login", payload, {
58+
const response = await axios.post<TypesGen.LoginWithPasswordResponse>("/api/v2/users/login", payload, {
5359
headers: { ...CONTENT_TYPE_JSON },
5460
})
5561

@@ -60,8 +66,8 @@ export const logout = async (): Promise<void> => {
6066
await axios.post("/api/v2/users/logout")
6167
}
6268

63-
export const getUser = async (): Promise<Types.UserResponse> => {
64-
const response = await axios.get<Types.UserResponse>("/api/v2/users/me")
69+
export const getUser = async (): Promise<TypesGen.User> => {
70+
const response = await axios.get<TypesGen.User>("/api/v2/users/me")
6571
return response.data
6672
}
6773

@@ -70,8 +76,8 @@ export const getAuthMethods = async (): Promise<TypesGen.AuthMethods> => {
7076
return response.data
7177
}
7278

73-
export const getApiKey = async (): Promise<Types.APIKeyResponse> => {
74-
const response = await axios.post<Types.APIKeyResponse>("/api/v2/users/me/keys")
79+
export const getApiKey = async (): Promise<TypesGen.GenerateAPIKeyResponse> => {
80+
const response = await axios.post<TypesGen.GenerateAPIKeyResponse>("/api/v2/users/me/keys")
7581
return response.data
7682
}
7783

@@ -80,39 +86,41 @@ export const getUsers = async (): Promise<TypesGen.User[]> => {
8086
return response.data
8187
}
8288

83-
export const getOrganization = async (organizationId: string): Promise<Types.Organization> => {
84-
const response = await axios.get<Types.Organization>(`/api/v2/organizations/${organizationId}`)
89+
export const getOrganization = async (organizationId: string): Promise<TypesGen.Organization> => {
90+
const response = await axios.get<TypesGen.Organization>(`/api/v2/organizations/${organizationId}`)
8591
return response.data
8692
}
8793

88-
export const getOrganizations = async (): Promise<Types.Organization[]> => {
89-
const response = await axios.get<Types.Organization[]>("/api/v2/users/me/organizations")
94+
export const getOrganizations = async (): Promise<TypesGen.Organization[]> => {
95+
const response = await axios.get<TypesGen.Organization[]>("/api/v2/users/me/organizations")
9096
return response.data
9197
}
9298

93-
export const getTemplate = async (templateId: string): Promise<Types.Template> => {
94-
const response = await axios.get<Types.Template>(`/api/v2/templates/${templateId}`)
99+
export const getTemplate = async (templateId: string): Promise<TypesGen.Template> => {
100+
const response = await axios.get<TypesGen.Template>(`/api/v2/templates/${templateId}`)
95101
return response.data
96102
}
97103

98-
export const getWorkspace = async (workspaceId: string): Promise<Types.Workspace> => {
99-
const response = await axios.get<Types.Workspace>(`/api/v2/workspaces/${workspaceId}`)
104+
export const getWorkspace = async (workspaceId: string): Promise<TypesGen.Workspace> => {
105+
const response = await axios.get<TypesGen.Workspace>(`/api/v2/workspaces/${workspaceId}`)
100106
return response.data
101107
}
102108

103109
export const getWorkspaceByOwnerAndName = async (
104110
organizationID: string,
105111
username = "me",
106112
workspaceName: string,
107-
): Promise<Types.Workspace> => {
108-
const response = await axios.get<Types.Workspace>(
113+
): Promise<TypesGen.Workspace> => {
114+
const response = await axios.get<TypesGen.Workspace>(
109115
`/api/v2/organizations/${organizationID}/workspaces/${username}/${workspaceName}`,
110116
)
111117
return response.data
112118
}
113119

114-
export const getWorkspaceResources = async (workspaceBuildID: string): Promise<Types.WorkspaceResource[]> => {
115-
const response = await axios.get<Types.WorkspaceResource[]>(`/api/v2/workspacebuilds/${workspaceBuildID}/resources`)
120+
export const getWorkspaceResources = async (workspaceBuildID: string): Promise<TypesGen.WorkspaceResource[]> => {
121+
const response = await axios.get<TypesGen.WorkspaceResource[]>(
122+
`/api/v2/workspacebuilds/${workspaceBuildID}/resources`,
123+
)
116124
return response.data
117125
}
118126

@@ -131,19 +139,19 @@ export const startWorkspace = postWorkspaceBuild("start")
131139
export const stopWorkspace = postWorkspaceBuild("stop")
132140
export const deleteWorkspace = postWorkspaceBuild("delete")
133141

134-
export const createUser = async (user: Types.CreateUserRequest): Promise<TypesGen.User> => {
142+
export const createUser = async (user: TypesGen.CreateUserRequest): Promise<TypesGen.User> => {
135143
const response = await axios.post<TypesGen.User>("/api/v2/users", user)
136144
return response.data
137145
}
138146

139-
export const getBuildInfo = async (): Promise<Types.BuildInfoResponse> => {
147+
export const getBuildInfo = async (): Promise<TypesGen.BuildInfoResponse> => {
140148
const response = await axios.get("/api/v2/buildinfo")
141149
return response.data
142150
}
143151

144152
export const putWorkspaceAutostart = async (
145153
workspaceID: string,
146-
autostart: Types.WorkspaceAutostartRequest,
154+
autostart: TypesGen.UpdateWorkspaceAutostartRequest,
147155
): Promise<void> => {
148156
const payload = JSON.stringify(autostart)
149157
await axios.put(`/api/v2/workspaces/${workspaceID}/autostart`, payload, {
@@ -153,15 +161,18 @@ export const putWorkspaceAutostart = async (
153161

154162
export const putWorkspaceAutostop = async (
155163
workspaceID: string,
156-
autostop: Types.WorkspaceAutostopRequest,
164+
autostop: TypesGen.UpdateWorkspaceAutostopRequest,
157165
): Promise<void> => {
158166
const payload = JSON.stringify(autostop)
159167
await axios.put(`/api/v2/workspaces/${workspaceID}/autostop`, payload, {
160168
headers: { ...CONTENT_TYPE_JSON },
161169
})
162170
}
163171

164-
export const updateProfile = async (userId: string, data: Types.UpdateProfileRequest): Promise<Types.UserResponse> => {
172+
export const updateProfile = async (
173+
userId: string,
174+
data: TypesGen.UpdateUserProfileRequest,
175+
): Promise<TypesGen.User> => {
165176
const response = await axios.put(`/api/v2/users/${userId}/profile`, data)
166177
return response.data
167178
}

0 commit comments

Comments
 (0)