Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf0be885

Browse files
committed
feat: Add support for json omitempty to apitypings
1 parent13fc406 commitf0be885

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

‎codersdk/pagination.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ type Pagination struct {
1414
// Offset for better performance. To use it as an alternative,
1515
// set AfterID to the last UUID returned by the previous
1616
// request.
17-
AfterID uuid.UUID`json:"after_id"`
17+
AfterID uuid.UUID`json:"after_id,omitempty"`
1818
// Limit sets the maximum number of users to be returned
1919
// in a single page. If the limit is <= 0, there is no limit
2020
// and all users are returned.
21-
Limitint`json:"limit"`
21+
Limitint`json:"limit,omitempty"`
2222
// Offset is used to indicate which page to return. An offset of 0
2323
// returns the first 'limit' number of users.
2424
// To get the next page, use offset=<limit>*<page_number>.
2525
// Offset is 0 indexed, so the first record sits at offset 0.
26-
Offsetint`json:"offset"`
26+
Offsetint`json:"offset,omitempty"`
2727
}
2828

2929
// asRequestOption returns a function that can be used in (*Client).request.

‎scripts/apitypings/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
251251
ifjsonName=="" {
252252
jsonName=field.Name()
253253
}
254+
jsonOptional:=false
255+
iflen(arr)>1&&arr[1]=="omitempty" {
256+
jsonOptional=true
257+
}
254258

255259
vartsTypeTypescriptType
256260
// If a `typescript:"string"` exists, we take this, and do not try to infer.
@@ -273,7 +277,7 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
273277
_,_=s.WriteRune('\n')
274278
}
275279
optional:=""
276-
iftsType.Optional {
280+
ifjsonOptional||tsType.Optional {
277281
optional="?"
278282
}
279283
_,_=s.WriteString(fmt.Sprintf("%sreadonly %s%s: %s\n",indent,jsonName,optional,tsType.ValueType))

‎site/src/api/typesGenerated.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface CreateWorkspaceBuildRequest {
9191
// This is likely an enum in an external package ("github.com/coder/coder/coderd/database.WorkspaceTransition")
9292
readonlytransition:string
9393
readonlydry_run:boolean
94-
readonlystate:string
94+
readonlystate?:string
9595
}
9696

9797
// From codersdk/organizations.go:52:6
@@ -149,9 +149,9 @@ export interface OrganizationMember {
149149

150150
// From codersdk/pagination.go:11:6
151151
exportinterfacePagination{
152-
readonlyafter_id:string
153-
readonlylimit:number
154-
readonlyoffset:number
152+
readonlyafter_id?:string
153+
readonlylimit?:number
154+
readonlyoffset?:number
155155
}
156156

157157
// From codersdk/parameters.go:26:6
@@ -185,7 +185,7 @@ export interface ProvisionerJob {
185185
readonlycreated_at:string
186186
readonlystarted_at?:string
187187
readonlycompleted_at?:string
188-
readonlyerror:string
188+
readonlyerror?:string
189189
readonlystatus:ProvisionerJobStatus
190190
readonlyworker_id?:string
191191
}
@@ -355,12 +355,12 @@ export interface WorkspaceAgent {
355355
readonlystatus:WorkspaceAgentStatus
356356
readonlyname:string
357357
readonlyresource_id:string
358-
readonlyinstance_id:string
358+
readonlyinstance_id?:string
359359
readonlyarchitecture:string
360360
readonlyenvironment_variables:Record<string,string>
361361
readonlyoperating_system:string
362-
readonlystartup_script:string
363-
readonlydirectory:string
362+
readonlystartup_script?:string
363+
readonlydirectory?:string
364364
}
365365

366366
// From codersdk/workspaceagents.go:47:6
@@ -415,7 +415,7 @@ export interface WorkspaceResource {
415415
readonlyworkspace_transition:string
416416
readonlytype:string
417417
readonlyname:string
418-
readonlyagents:WorkspaceAgent[]
418+
readonlyagents?:WorkspaceAgent[]
419419
}
420420

421421
// From codersdk/parameters.go:16:6

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp