Skip to content

Commit

Permalink
docs: make max-depth expand parameter required (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
CypherpunkSamurai authored Oct 7, 2021
1 parent cf7cddc commit 6d51422
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/e2e/sdk_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (c *sdkClient) expand(t require.TestingT, r *relationtuple.SubjectSet, dept
WithNamespace(r.Namespace).
WithObject(r.Object).
WithRelation(r.Relation).
WithMaxDepth(pointerx.Int64(int64(depth))),
WithMaxDepth(int64(depth)),
)
require.NoError(t, err)
return buildTree(t, resp.Payload)
Expand Down
5 changes: 5 additions & 0 deletions internal/expand/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (h *handler) RegisterWriteGRPC(s *grpc.Server) {}
// nolint:deadcode,unused
type getExpandRequest struct {
// in:query
// required: true
MaxDepth int `json:"max-depth"`
}

Expand All @@ -76,6 +77,10 @@ type getExpandRequest struct {
// 404: genericError
// 500: genericError
func (h *handler) getExpand(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
if !r.URL.Query().Has("max-depth") {
h.d.Writer().WriteError(w, r, herodot.ErrBadRequest.WithError("required query parameter 'max-depth' is missing"))
return
}
depth, err := strconv.ParseInt(r.URL.Query().Get("max-depth"), 0, 0)
if err != nil {
h.d.Writer().WriteError(w, r, herodot.ErrBadRequest.WithError(err.Error()))
Expand Down
10 changes: 10 additions & 0 deletions internal/expand/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ func TestRESTHandler(t *testing.T) {
ts := httptest.NewServer(r)
defer ts.Close()

t.Run("case=returns required query parameter max-depth is missing is missing", func(t *testing.T) {
resp, err := ts.Client().Get(ts.URL + expand.RouteBase)
require.NoError(t, err)

assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
assert.Contains(t, string(body), "required query parameter 'max-depth'")
})

t.Run("case=returns bad request on malformed int", func(t *testing.T) {
resp, err := ts.Client().Get(ts.URL + expand.RouteBase + "?max-depth=foo")
require.NoError(t, err)
Expand Down
25 changes: 9 additions & 16 deletions internal/httpclient/client/read/get_expand_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion spec/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@
"type": "integer",
"format": "int64",
"name": "max-depth",
"in": "query"
"in": "query",
"required": true
}
],
"responses": {
Expand Down

0 comments on commit 6d51422

Please sign in to comment.