diff --git a/internal/e2e/sdk_client_test.go b/internal/e2e/sdk_client_test.go index ca136a73d..3d2850ccc 100644 --- a/internal/e2e/sdk_client_test.go +++ b/internal/e2e/sdk_client_test.go @@ -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) diff --git a/internal/expand/handler.go b/internal/expand/handler.go index ceb5b1c05..cb25143df 100644 --- a/internal/expand/handler.go +++ b/internal/expand/handler.go @@ -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"` } @@ -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())) diff --git a/internal/expand/handler_test.go b/internal/expand/handler_test.go index feed2f517..dde5e5343 100644 --- a/internal/expand/handler_test.go +++ b/internal/expand/handler_test.go @@ -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) diff --git a/internal/httpclient/client/read/get_expand_parameters.go b/internal/httpclient/client/read/get_expand_parameters.go index 5e81db9cf..f8f58085a 100644 --- a/internal/httpclient/client/read/get_expand_parameters.go +++ b/internal/httpclient/client/read/get_expand_parameters.go @@ -63,7 +63,7 @@ type GetExpandParams struct { // MaxDepth. // // Format: int64 - MaxDepth *int64 + MaxDepth int64 /* Namespace. @@ -137,13 +137,13 @@ func (o *GetExpandParams) SetHTTPClient(client *http.Client) { } // WithMaxDepth adds the maxDepth to the get expand params -func (o *GetExpandParams) WithMaxDepth(maxDepth *int64) *GetExpandParams { +func (o *GetExpandParams) WithMaxDepth(maxDepth int64) *GetExpandParams { o.SetMaxDepth(maxDepth) return o } // SetMaxDepth adds the maxDepth to the get expand params -func (o *GetExpandParams) SetMaxDepth(maxDepth *int64) { +func (o *GetExpandParams) SetMaxDepth(maxDepth int64) { o.MaxDepth = maxDepth } @@ -188,20 +188,13 @@ func (o *GetExpandParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Reg } var res []error - if o.MaxDepth != nil { + // query param max-depth + qrMaxDepth := o.MaxDepth + qMaxDepth := swag.FormatInt64(qrMaxDepth) + if qMaxDepth != "" { - // query param max-depth - var qrMaxDepth int64 - - if o.MaxDepth != nil { - qrMaxDepth = *o.MaxDepth - } - qMaxDepth := swag.FormatInt64(qrMaxDepth) - if qMaxDepth != "" { - - if err := r.SetQueryParam("max-depth", qMaxDepth); err != nil { - return err - } + if err := r.SetQueryParam("max-depth", qMaxDepth); err != nil { + return err } } diff --git a/spec/api.json b/spec/api.json index dd51daf30..73be5924a 100755 --- a/spec/api.json +++ b/spec/api.json @@ -316,7 +316,8 @@ "type": "integer", "format": "int64", "name": "max-depth", - "in": "query" + "in": "query", + "required": true } ], "responses": {