Skip to content
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

Fixes #244 #247

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"

"github.com/amzn/ion-go/ion"
"github.com/danielgtaylor/restish/cli"
"github.com/danielgtaylor/restish/openapi"
"github.com/barbich/restish/cli"
"github.com/barbich/restish/openapi"
"github.com/fxamacker/cbor/v2"
"github.com/shamaton/msgpack/v2"
"github.com/spf13/cobra"
Expand Down
4 changes: 2 additions & 2 deletions bulk/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"sort"
"strings"

"github.com/barbich/restish/cli"
"github.com/barbich/restish/openapi"
"github.com/danielgtaylor/mexpr"
"github.com/danielgtaylor/restish/cli"
"github.com/danielgtaylor/restish/openapi"
"github.com/danielgtaylor/shorthand/v2"
"github.com/hexops/gotextdiff"
"github.com/hexops/gotextdiff/myers"
Expand Down
2 changes: 1 addition & 1 deletion bulk/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/danielgtaylor/restish/cli"
"github.com/barbich/restish/cli"
"github.com/spf13/afero"
"github.com/stretchr/testify/require"
"gopkg.in/h2non/gock.v1"
Expand Down
2 changes: 1 addition & 1 deletion bulk/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"path/filepath"
"reflect"

"github.com/danielgtaylor/restish/cli"
"github.com/barbich/restish/cli"
"github.com/spf13/afero"
"github.com/zeebo/xxh3"
)
Expand Down
2 changes: 1 addition & 1 deletion bulk/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"time"

"github.com/danielgtaylor/restish/cli"
"github.com/barbich/restish/cli"
"github.com/danielgtaylor/shorthand/v2"
"github.com/logrusorgru/aurora"
"github.com/schollz/progressbar/v3"
Expand Down
14 changes: 7 additions & 7 deletions cli/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Links map[string][]*Link

// LinkParser parses link relationships in a response.
type LinkParser interface {
ParseLinks(resp *Response) error
ParseLinks(base *url.URL, resp *Response) error
}

var linkParsers = []LinkParser{}
Expand All @@ -34,7 +34,7 @@ func AddLinkParser(parser LinkParser) {
// ParseLinks uses all registered LinkParsers to parse links for a response.
func ParseLinks(base *url.URL, resp *Response) error {
for _, parser := range linkParsers {
if err := parser.ParseLinks(resp); err != nil {
if err := parser.ParseLinks(base, resp); err != nil {
return err
}
}
Expand All @@ -58,7 +58,7 @@ func ParseLinks(base *url.URL, resp *Response) error {
type LinkHeaderParser struct{}

// ParseLinks processes the links in a parsed response.
func (l LinkHeaderParser) ParseLinks(resp *Response) error {
func (l LinkHeaderParser) ParseLinks(base *url.URL, resp *Response) error {
if resp.Headers["Link"] != "" {
links, err := link.Parse(resp.Headers["Link"])
if err != nil {
Expand Down Expand Up @@ -90,7 +90,7 @@ type halBody struct {
type HALParser struct{}

// ParseLinks processes the links in a parsed response.
func (h HALParser) ParseLinks(resp *Response) error {
func (h HALParser) ParseLinks(base *url.URL, resp *Response) error {
entries := []interface{}{}
if l, ok := resp.Body.([]interface{}); ok {
entries = l
Expand Down Expand Up @@ -122,7 +122,7 @@ func (h HALParser) ParseLinks(resp *Response) error {
type TerrificallySimpleJSONParser struct{}

// ParseLinks processes the links in a parsed response.
func (t TerrificallySimpleJSONParser) ParseLinks(resp *Response) error {
func (t TerrificallySimpleJSONParser) ParseLinks(base *url.URL, resp *Response) error {
return t.walk(resp, "self", resp.Body)
}

Expand Down Expand Up @@ -181,7 +181,7 @@ type sirenBody struct {
type SirenParser struct{}

// ParseLinks processes the links in a parsed response.
func (s SirenParser) ParseLinks(resp *Response) error {
func (s SirenParser) ParseLinks(base *url.URL, resp *Response) error {
siren := sirenBody{}
if err := mapstructure.Decode(resp.Body, &siren); err == nil {
for _, link := range siren.Links {
Expand Down Expand Up @@ -230,7 +230,7 @@ func getJSONAPIlinks(links map[string]interface{}, resp *Response, isItem bool)
type JSONAPIParser struct{}

// ParseLinks processes the links in a parsed response.
func (j JSONAPIParser) ParseLinks(resp *Response) error {
func (j JSONAPIParser) ParseLinks(base *url.URL, resp *Response) error {
if b, ok := resp.Body.(map[string]interface{}); ok {
// Find top-level links
if l, ok := b["links"].(map[string]interface{}); ok {
Expand Down
18 changes: 10 additions & 8 deletions cli/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (

type errorLinkParser struct{}

func (p errorLinkParser) ParseLinks(r *Response) error {
var base *url.URL

func (p errorLinkParser) ParseLinks(base *url.URL, r *Response) error {
return fmt.Errorf("error parsing links")
}

Expand All @@ -35,15 +37,15 @@ func TestLinkHeaderParser(t *testing.T) {
}

p := LinkHeaderParser{}
err := p.ParseLinks(r)
err := p.ParseLinks(base, r)
assert.NoError(t, err)
assert.Equal(t, r.Links["self"][0].URI, "/self")
assert.Equal(t, r.Links["item"][0].URI, "/foo")
assert.Equal(t, r.Links["item"][1].URI, "/bar")

// Test a bad link header
r.Headers["Link"] = "bad value"
err = p.ParseLinks(r)
err = p.ParseLinks(base, r)
assert.Error(t, err)
}

Expand All @@ -64,7 +66,7 @@ func TestHALParser(t *testing.T) {
}

p := HALParser{}
err := p.ParseLinks(r)
err := p.ParseLinks(base, r)
assert.NoError(t, err)
assert.Equal(t, r.Links["self"][0].URI, "/self")
assert.Equal(t, r.Links["item"][0].URI, "/item")
Expand Down Expand Up @@ -92,7 +94,7 @@ func TestHALParserArray(t *testing.T) {
}

p := HALParser{}
err := p.ParseLinks(r)
err := p.ParseLinks(base, r)
assert.NoError(t, err)
assert.Equal(t, r.Links["self"][0].URI, "/one")
assert.Equal(t, r.Links["self"][1].URI, "/two")
Expand Down Expand Up @@ -129,7 +131,7 @@ func TestTerrificallySimpleJSONParser(t *testing.T) {
}

p := TerrificallySimpleJSONParser{}
err := p.ParseLinks(r)
err := p.ParseLinks(base, r)
assert.NoError(t, err)
assert.Equal(t, r.Links["self"][0].URI, "/self")
assert.Equal(t, r.Links["things-item"][0].URI, "/foo")
Expand All @@ -152,7 +154,7 @@ func TestSirenParser(t *testing.T) {
}

s := SirenParser{}
err := s.ParseLinks(r)
err := s.ParseLinks(base, r)
assert.NoError(t, err)
assert.Equal(t, r.Links["self"][0].URI, "/self")
assert.Equal(t, r.Links["one"][0].URI, "/multi")
Expand All @@ -179,7 +181,7 @@ func TestJSONAPIParser(t *testing.T) {
}

j := JSONAPIParser{}
err := j.ParseLinks(r)
err := j.ParseLinks(base, r)
assert.NoError(t, err)
assert.Equal(t, r.Links["self"][0].URI, "/self")
assert.Equal(t, r.Links["item"][0].URI, "/item")
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/danielgtaylor/restish
module github.com/barbich/restish

go 1.18
go 1.21

toolchain go1.22.1

require (
github.com/AlecAivazis/survey/v2 v2.3.6
Expand Down Expand Up @@ -64,7 +66,7 @@ require (
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/microcosm-cc/bluemonday v1.0.26 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.13.0 // indirect
Expand Down
10 changes: 9 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
Expand Down Expand Up @@ -152,6 +153,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
Expand Down Expand Up @@ -208,9 +210,11 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
Expand All @@ -233,8 +237,9 @@ github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/microcosm-cc/bluemonday v1.0.21 h1:dNH3e4PSyE4vNX+KlRGHT5KrSvjeUkoNPwEORjffHJg=
github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM=
github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58=
github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand Down Expand Up @@ -283,6 +288,7 @@ github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/schollz/progressbar/v3 v3.12.2 h1:yLqqqpQNMxGxHY8uEshRihaHWwa0rf0yb7/Zrpgq2C0=
github.com/schollz/progressbar/v3 v3.12.2/go.mod h1:HFJYIYQQJX32UJdyoigUl19xoV6aMwZt6iX/C30RWfg=
Expand Down Expand Up @@ -337,6 +343,7 @@ github.com/yuin/goldmark v1.5.3/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5ta
github.com/yuin/goldmark-emoji v1.0.1 h1:ctuWEyzGBwiucEqxzwe0SOYDXPAucOrE9NQC18Wa1os=
github.com/yuin/goldmark-emoji v1.0.1/go.mod h1:2w1E6FEWLcDQkoTE+7HU6QF1F6SLlNGjRIBbIZQFqkQ=
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down Expand Up @@ -685,6 +692,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"os"

"github.com/danielgtaylor/restish/bulk"
"github.com/danielgtaylor/restish/cli"
"github.com/danielgtaylor/restish/oauth"
"github.com/danielgtaylor/restish/openapi"
"github.com/barbich/restish/bulk"
"github.com/barbich/restish/cli"
"github.com/barbich/restish/oauth"
"github.com/barbich/restish/openapi"
)

var version string = "dev"
Expand Down
2 changes: 1 addition & 1 deletion oauth/authcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"context"

"github.com/danielgtaylor/restish/cli"
"github.com/barbich/restish/cli"
"github.com/mattn/go-isatty"
"golang.org/x/oauth2"
)
Expand Down
2 changes: 1 addition & 1 deletion oauth/clientcreds.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/url"
"strings"

"github.com/danielgtaylor/restish/cli"
"github.com/barbich/restish/cli"
"golang.org/x/oauth2/clientcredentials"
)

Expand Down
2 changes: 1 addition & 1 deletion oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"net/http"

"github.com/danielgtaylor/restish/cli"
"github.com/barbich/restish/cli"
"golang.org/x/oauth2"
)

Expand Down
2 changes: 1 addition & 1 deletion oauth/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/url"

"github.com/danielgtaylor/restish/cli"
"github.com/barbich/restish/cli"
"golang.org/x/oauth2"
)

Expand Down
2 changes: 1 addition & 1 deletion oauth/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/danielgtaylor/restish/cli"
"github.com/barbich/restish/cli"
"golang.org/x/oauth2"
)

Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"sort"
"strings"

"github.com/barbich/restish/cli"
"github.com/danielgtaylor/casing"
"github.com/danielgtaylor/restish/cli"
"github.com/danielgtaylor/shorthand/v2"
"github.com/gosimple/slug"
"github.com/pb33f/libopenapi"
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"
"testing/iotest"

"github.com/danielgtaylor/restish/cli"
"github.com/barbich/restish/cli"
v3 "github.com/pb33f/libopenapi/datamodel/high/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down