Skip to content

Commit b85f702

Browse files
refactor: Use GistFileRequest for gist file inputs
Per review, the gist create/update request files map should not reuse the GistFile response type (which carries read-only fields like size, raw_url, type and language). Introduce GistFileRequest{Content, Filename} for the request file value, mark CreateGistRequest.Files required (drop omitempty), and add field doc comments. The OpenAPI schema confirms the create file value is {content} (content required) and the update file value is {content, filename}.
1 parent 2a65d2f commit b85f702

4 files changed

Lines changed: 62 additions & 13 deletions

File tree

‎github/gists.go‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ func (g Gist) String() string {
3939

4040
// CreateGistRequest represents the input for creating a gist.
4141
type CreateGistRequest struct {
42-
Description *string `json:"description,omitempty"`
43-
Public *bool `json:"public,omitempty"`
44-
Files map[GistFilename]GistFile `json:"files,omitempty"`
42+
Description *string `json:"description,omitempty"`
43+
Public *bool `json:"public,omitempty"`
44+
// Files is the set of files that make up the gist, keyed by filename. (Required.)
45+
Files map[GistFilename]GistFileRequest `json:"files"`
4546
}
4647

4748
// UpdateGistRequest represents the input for updating a gist.
4849
type UpdateGistRequest struct {
49-
Description *string `json:"description,omitempty"`
50-
Files map[GistFilename]GistFile `json:"files,omitempty"`
50+
Description *string `json:"description,omitempty"`
51+
// Files is the set of files to add, change or rename, keyed by filename.
52+
Files map[GistFilename]GistFileRequest `json:"files,omitempty"`
5153
}
5254

5355
// GistFilename represents filename on a gist.
@@ -67,6 +69,15 @@ func (g GistFile) String() string {
6769
return Stringify(g)
6870
}
6971

72+
// GistFileRequest represents a file's content within a CreateGistRequest or
73+
// UpdateGistRequest. The gist's files are keyed by filename.
74+
type GistFileRequest struct {
75+
// Content is the contents of the file. (Required when creating a gist.)
76+
Content *string `json:"content,omitempty"`
77+
// Filename, if set, renames the file. (Used when updating a gist.)
78+
Filename *string `json:"filename,omitempty"`
79+
}
80+
7081
// GistCommit represents a commit on a gist.
7182
type GistCommit struct {
7283
URL *string `json:"url,omitempty"`

‎github/gists_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func TestGistsService_Create(t *testing.T) {
266266
input := CreateGistRequest{
267267
Description: Ptr("Gist description"),
268268
Public: Ptr(false),
269-
Files: map[GistFilename]GistFile{
269+
Files: map[GistFilename]GistFileRequest{
270270
"test.txt": {Content: Ptr("Gist file content")},
271271
},
272272
}
@@ -323,7 +323,7 @@ func TestGistsService_Update(t *testing.T) {
323323

324324
input := UpdateGistRequest{
325325
Description: Ptr("New description"),
326-
Files: map[GistFilename]GistFile{
326+
Files: map[GistFilename]GistFileRequest{
327327
"new.txt": {Content: Ptr("new file content")},
328328
},
329329
}

‎github/github-accessors.go‎

Lines changed: 20 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎github/github-accessors_test.go‎

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)