diff --git a/services/horizon/internal/actions/account.go b/services/horizon/internal/actions/account.go index 9a2e9189a4..82856de3b7 100644 --- a/services/horizon/internal/actions/account.go +++ b/services/horizon/internal/actions/account.go @@ -77,7 +77,7 @@ type AccountsQuery struct { // URITemplate returns a rfc6570 URI template the query struct func (q AccountsQuery) URITemplate() string { - return "/accounts{?" + strings.Join(getURIParams(&q, true), ",") + "}" + return getURITemplate(&q, "accounts", true) } var invalidAccountsParams = problem.P{ diff --git a/services/horizon/internal/actions/claimable_balance.go b/services/horizon/internal/actions/claimable_balance.go index bb0e5fa783..dbfa02c298 100644 --- a/services/horizon/internal/actions/claimable_balance.go +++ b/services/horizon/internal/actions/claimable_balance.go @@ -100,7 +100,7 @@ func (q ClaimableBalancesQuery) claimant() *xdr.AccountId { // URITemplate returns a rfc6570 URI template the query struct func (q ClaimableBalancesQuery) URITemplate() string { - return "/claimable_balances?{asset,claimant,sponsor}" + return getURITemplate(&q, "claimable_balances", true) } type GetClaimableBalancesHandler struct { diff --git a/services/horizon/internal/actions/claimable_balance_test.go b/services/horizon/internal/actions/claimable_balance_test.go index 0743d3189b..ad6bcd575a 100644 --- a/services/horizon/internal/actions/claimable_balance_test.go +++ b/services/horizon/internal/actions/claimable_balance_test.go @@ -533,7 +533,7 @@ func TestCursorAndOrderValidation(t *testing.T) { func TestClaimableBalancesQueryURLTemplate(t *testing.T) { tt := assert.New(t) - expected := "/claimable_balances?{asset,claimant,sponsor}" + expected := "/claimable_balances{?asset,sponsor,claimant,cursor,limit,order}" q := ClaimableBalancesQuery{} tt.Equal(expected, q.URITemplate()) } diff --git a/services/horizon/internal/actions/helpers.go b/services/horizon/internal/actions/helpers.go index 8a90504f1f..2cfe9b9738 100644 --- a/services/horizon/internal/actions/helpers.go +++ b/services/horizon/internal/actions/helpers.go @@ -440,15 +440,19 @@ func getURIParams(query interface{}, paginated bool) []string { params := getSchemaTags(reflect.ValueOf(query).Elem()) if paginated { pagingParams := []string{ - "cursor", - "limit", - "order", + ParamCursor, + ParamLimit, + ParamOrder, } params = append(params, pagingParams...) } return params } +func getURITemplate(query interface{}, basePath string, paginated bool) string { + return "/" + basePath + "{?" + strings.Join(getURIParams(query, paginated), ",") + "}" +} + func getSchemaTags(v reflect.Value) []string { qt := v.Type() fields := make([]string, 0, v.NumField()) diff --git a/services/horizon/internal/actions/liquidity_pool.go b/services/horizon/internal/actions/liquidity_pool.go index 6894043db6..bb1aedd882 100644 --- a/services/horizon/internal/actions/liquidity_pool.go +++ b/services/horizon/internal/actions/liquidity_pool.go @@ -68,7 +68,7 @@ type LiquidityPoolsQuery struct { // URITemplate returns a rfc6570 URI template the query struct func (q LiquidityPoolsQuery) URITemplate() string { - return "/liquidity_pools?{?reserves,account}" + return getURITemplate(&q, "liquidity_pools", true) } // Validate validates and parses the query diff --git a/services/horizon/internal/actions/path.go b/services/horizon/internal/actions/path.go index fe5a21328e..6c2e97fcd2 100644 --- a/services/horizon/internal/actions/path.go +++ b/services/horizon/internal/actions/path.go @@ -5,7 +5,6 @@ import ( "database/sql" "fmt" "net/http" - "strings" "github.com/stellar/go/amount" "github.com/stellar/go/protocols/horizon" @@ -72,7 +71,7 @@ func (q StrictReceivePathsQuery) DestinationAsset() xdr.Asset { // URITemplate returns a rfc6570 URI template for the query struct func (q StrictReceivePathsQuery) URITemplate() string { - return "/paths/strict-receive{?" + strings.Join(getURIParams(&q, false), ",") + "}" + return getURITemplate(&q, "paths/strict-receive", false) } // Validate runs custom validations. @@ -214,7 +213,7 @@ type FindFixedPathsQuery struct { // URITemplate returns a rfc6570 URI template for the query struct func (q FindFixedPathsQuery) URITemplate() string { - return "/paths/strict-send{?" + strings.Join(getURIParams(&q, false), ",") + "}" + return getURITemplate(&q, "paths/strict-send", false) } // Validate runs custom validations.