Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ type (
// MarshalJSON implements the json.Marshaler interface.
// The URI is a quoted string.
func (u URI) MarshalJSON() ([]byte, error) {
if u.URL == nil {
return []byte("null"), nil
}
return json.Marshal(u.String())
}

Expand Down
5 changes: 5 additions & 0 deletions scalar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func TestURI_MarshalJSON(t *testing.T) {
in githubv4.URI
want string
}{
{
name: "null",
in: githubv4.URI{},
want: `null`,
},
{
in: githubv4.URI{URL: &url.URL{Scheme: "https", Host: "example.org", Path: "/foo/bar"}},
want: `"https://example.org/foo/bar"`,
Expand Down