From 08a2b9591b4f5e138705684d1edab9303bfe15f6 Mon Sep 17 00:00:00 2001 From: ebichman-1 Date: Sun, 26 Apr 2026 15:27:13 +0300 Subject: [PATCH] fix(aep) enforce AEP compliance for List field naming, Location header, and error content-type Close four AEP compliance gaps that the upstream linter does not enforce: - AEP-132: Rename PolicyList response field from to - AEP-133: Populate Location header in CreatePolicy 201 response - AEP-193: Add middleware to return for error responses - Add custom Spectral rules to prevent regressions on the above BREAKING CHANGE: ListPolicies response JSON field renamed from to . Assisted-by: Claude Opus 4.6 (Anthropic) Signed-off-by: ebichman-1 --- .spectral.yaml | 18 +++++++ api/v1alpha1/openapi.yaml | 4 +- api/v1alpha1/types.gen.go | 4 +- internal/api/server/server.gen.go | 4 +- internal/apiserver/server.go | 2 + internal/engineserver/server.go | 2 + internal/handlers/v1alpha1/converters.go | 6 +-- internal/handlers/v1alpha1/policy.go | 7 ++- internal/handlers/v1alpha1/policy_test.go | 13 ++--- internal/middleware/problemjson.go | 42 ++++++++++++++++ internal/middleware/problemjson_test.go | 60 +++++++++++++++++++++++ internal/service/policy.go | 2 +- internal/service/policy_test.go | 44 ++++++++--------- test/e2e/policy_test.go | 28 +++++------ 14 files changed, 182 insertions(+), 54 deletions(-) create mode 100644 internal/middleware/problemjson.go create mode 100644 internal/middleware/problemjson_test.go diff --git a/.spectral.yaml b/.spectral.yaml index 7b51d09..53c8cc7 100644 --- a/.spectral.yaml +++ b/.spectral.yaml @@ -12,3 +12,21 @@ rules: functionOptions: schema: type: object + + aep-132-list-results-field: + description: List response array field must be named 'results' per AEP-132 + message: "List response schema must use 'results' as the array field name" + severity: warn + given: $.components.schemas[?(@.properties.next_page_token)].properties + then: + field: results + function: truthy + + aep-133-create-location-header: + description: Create (201) response must include Location header per AEP-133 + message: "Create operation 201 response must include a Location header" + severity: warn + given: $.paths[*].post.responses.201 + then: + field: headers.Location + function: truthy diff --git a/api/v1alpha1/openapi.yaml b/api/v1alpha1/openapi.yaml index 3d7abee..60ed619 100644 --- a/api/v1alpha1/openapi.yaml +++ b/api/v1alpha1/openapi.yaml @@ -485,9 +485,9 @@ components: Implements AEP-132 List standard method requirements. required: - - policies + - results properties: - policies: + results: type: array description: List of policy resources matching the request criteria items: diff --git a/api/v1alpha1/types.gen.go b/api/v1alpha1/types.gen.go index 8ba87cc..946eaf2 100644 --- a/api/v1alpha1/types.gen.go +++ b/api/v1alpha1/types.gen.go @@ -172,8 +172,8 @@ type PolicyList struct { // This token is opaque and should not be parsed by clients. NextPageToken *string `json:"next_page_token,omitempty"` - // Policies List of policy resources matching the request criteria - Policies []Policy `json:"policies"` + // Results List of policy resources matching the request criteria + Results []Policy `json:"results"` } // PolicyIdPath defines model for PolicyIdPath. diff --git a/internal/api/server/server.gen.go b/internal/api/server/server.gen.go index cf59094..0ef1e5e 100644 --- a/internal/api/server/server.gen.go +++ b/internal/api/server/server.gen.go @@ -180,8 +180,8 @@ type PolicyList struct { // This token is opaque and should not be parsed by clients. NextPageToken *string `json:"next_page_token,omitempty"` - // Policies List of policy resources matching the request criteria - Policies []Policy `json:"policies"` + // Results List of policy resources matching the request criteria + Results []Policy `json:"results"` } // PolicyIdPath defines model for PolicyIdPath. diff --git a/internal/apiserver/server.go b/internal/apiserver/server.go index 9f8f018..43369bf 100644 --- a/internal/apiserver/server.go +++ b/internal/apiserver/server.go @@ -14,6 +14,7 @@ import ( "github.com/dcm-project/policy-manager/internal/api/server" "github.com/dcm-project/policy-manager/internal/config" "github.com/dcm-project/policy-manager/internal/logging" + custommiddleware "github.com/dcm-project/policy-manager/internal/middleware" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" ) @@ -43,6 +44,7 @@ func (s *Server) Run(ctx context.Context) error { router.Use(logging.RequestLogger) router.Use(middleware.Logger) router.Use(middleware.Recoverer) + router.Use(custommiddleware.ProblemJSON) swagger, err := v1alpha1.GetSwagger() if err != nil { diff --git a/internal/engineserver/server.go b/internal/engineserver/server.go index 08137e4..49927e6 100644 --- a/internal/engineserver/server.go +++ b/internal/engineserver/server.go @@ -14,6 +14,7 @@ import ( engineserver "github.com/dcm-project/policy-manager/internal/api/engine" "github.com/dcm-project/policy-manager/internal/config" "github.com/dcm-project/policy-manager/internal/logging" + custommiddleware "github.com/dcm-project/policy-manager/internal/middleware" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" ) @@ -43,6 +44,7 @@ func (s *Server) Run(ctx context.Context) error { router.Use(logging.RequestLogger) router.Use(middleware.Logger) router.Use(middleware.Recoverer) + router.Use(custommiddleware.ProblemJSON) swagger, err := engineserverapi.GetSwagger() if err != nil { diff --git a/internal/handlers/v1alpha1/converters.go b/internal/handlers/v1alpha1/converters.go index 811ee25..6740e0d 100644 --- a/internal/handlers/v1alpha1/converters.go +++ b/internal/handlers/v1alpha1/converters.go @@ -48,12 +48,12 @@ func policyV1Alpha1ToServer(p v1alpha1.Policy) server.Policy { } func listResponseV1Alpha1ToServer(r v1alpha1.PolicyList) server.PolicyList { - policies := make([]server.Policy, len(r.Policies)) - for i, p := range r.Policies { + policies := make([]server.Policy, len(r.Results)) + for i, p := range r.Results { policies[i] = policyV1Alpha1ToServer(p) } return server.PolicyList{ NextPageToken: r.NextPageToken, - Policies: policies, + Results: policies, } } diff --git a/internal/handlers/v1alpha1/policy.go b/internal/handlers/v1alpha1/policy.go index 619056a..e2c5696 100644 --- a/internal/handlers/v1alpha1/policy.go +++ b/internal/handlers/v1alpha1/policy.go @@ -3,6 +3,7 @@ package v1alpha1 import ( "context" + "fmt" "github.com/dcm-project/policy-manager/api/v1alpha1" "github.com/dcm-project/policy-manager/internal/api/server" @@ -62,9 +63,11 @@ func (h *PolicyHandler) CreatePolicy(ctx context.Context, request server.CreateP } log.Info("Policy created", "policy_id", *created.Id) - // Convert back to server.Policy return server.CreatePolicy201JSONResponse{ Body: policyV1Alpha1ToServer(*created), + Headers: server.CreatePolicy201ResponseHeaders{ + Location: fmt.Sprintf("/api/v1alpha1/policies/%s", *created.Id), + }, }, nil } @@ -107,7 +110,7 @@ func (h *PolicyHandler) ListPolicies(ctx context.Context, request server.ListPol return h.handleListPoliciesError(err, request), nil } - log.Debug("ListPolicies completed", "count", len(result.Policies)) + log.Debug("ListPolicies completed", "count", len(result.Results)) return server.ListPolicies200JSONResponse(listResponseV1Alpha1ToServer(*result)), nil } diff --git a/internal/handlers/v1alpha1/policy_test.go b/internal/handlers/v1alpha1/policy_test.go index 656e0d4..efc0177 100644 --- a/internal/handlers/v1alpha1/policy_test.go +++ b/internal/handlers/v1alpha1/policy_test.go @@ -126,6 +126,7 @@ var _ = Describe("PolicyHandler", func() { createResponse, ok := response.(server.CreatePolicy201JSONResponse) Expect(ok).To(BeTrue(), "response should be CreatePolicy201JSONResponse") Expect(*createResponse.Body.Id).To(Equal("test-policy")) + Expect(createResponse.Headers.Location).To(Equal("/api/v1alpha1/policies/test-policy")) }) It("should return 400 when body is nil", func() { @@ -227,7 +228,7 @@ var _ = Describe("PolicyHandler", func() { pt2 := v1alpha1.USER mockService.ListPoliciesFn = func(_ context.Context, _ *string, _ *string, _ *string, _ *int32) (*v1alpha1.PolicyList, error) { return &v1alpha1.PolicyList{ - Policies: []v1alpha1.Policy{ + Results: []v1alpha1.Policy{ { Id: &policyID1, Path: &path1, @@ -254,9 +255,9 @@ var _ = Describe("PolicyHandler", func() { Expect(err).NotTo(HaveOccurred()) listResponse, ok := response.(server.ListPolicies200JSONResponse) Expect(ok).To(BeTrue(), "response should be ListPolicies200JSONResponse") - Expect(listResponse.Policies).To(HaveLen(2)) - Expect(*listResponse.Policies[0].Id).To(Equal("policy-1")) - Expect(*listResponse.Policies[1].Id).To(Equal("policy-2")) + Expect(listResponse.Results).To(HaveLen(2)) + Expect(*listResponse.Results[0].Id).To(Equal("policy-1")) + Expect(*listResponse.Results[1].Id).To(Equal("policy-2")) }) It("should pass filter parameter to service", func() { @@ -267,7 +268,7 @@ var _ = Describe("PolicyHandler", func() { mockService.ListPoliciesFn = func(_ context.Context, filter *string, _ *string, _ *string, _ *int32) (*v1alpha1.PolicyList, error) { receivedFilter = filter return &v1alpha1.PolicyList{ - Policies: []v1alpha1.Policy{}, + Results: []v1alpha1.Policy{}, }, nil } @@ -293,7 +294,7 @@ var _ = Describe("PolicyHandler", func() { receivedPageToken = pageToken receivedPageSize = pageSize return &v1alpha1.PolicyList{ - Policies: []v1alpha1.Policy{}, + Results: []v1alpha1.Policy{}, }, nil } diff --git a/internal/middleware/problemjson.go b/internal/middleware/problemjson.go new file mode 100644 index 0000000..aa5e207 --- /dev/null +++ b/internal/middleware/problemjson.go @@ -0,0 +1,42 @@ +package middleware + +import ( + "net/http" + "strings" +) + +// ProblemJSON is a Chi middleware that rewrites the Content-Type header +// from application/json to application/problem+json for error responses +// (status >= 400), per AEP-193 and RFC 9457. +func ProblemJSON(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + next.ServeHTTP(&problemJSONWriter{ResponseWriter: w}, r) + }) +} + +type problemJSONWriter struct { + http.ResponseWriter + wroteHeader bool +} + +func (w *problemJSONWriter) WriteHeader(code int) { + if !w.wroteHeader && code >= 400 { + ct := w.Header().Get("Content-Type") + if strings.HasPrefix(ct, "application/json") { + w.Header().Set("Content-Type", strings.Replace(ct, "application/json", "application/problem+json", 1)) + } + } + w.wroteHeader = true + w.ResponseWriter.WriteHeader(code) +} + +func (w *problemJSONWriter) Write(b []byte) (int, error) { + if !w.wroteHeader { + w.WriteHeader(http.StatusOK) + } + return w.ResponseWriter.Write(b) +} + +func (w *problemJSONWriter) Unwrap() http.ResponseWriter { + return w.ResponseWriter +} diff --git a/internal/middleware/problemjson_test.go b/internal/middleware/problemjson_test.go new file mode 100644 index 0000000..f3b9ccc --- /dev/null +++ b/internal/middleware/problemjson_test.go @@ -0,0 +1,60 @@ +package middleware + +import ( + "net/http" + "net/http/httptest" + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestMiddleware(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Middleware Suite") +} + +var _ = Describe("ProblemJSON", func() { + makeHandler := func(status int, contentType string) http.Handler { + return ProblemJSON(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", contentType) + w.WriteHeader(status) + w.Write([]byte(`{"type":"INTERNAL","status":500,"title":"error"}`)) + })) + } + + It("should rewrite Content-Type for 400 responses", func() { + rec := httptest.NewRecorder() + makeHandler(400, "application/json").ServeHTTP(rec, httptest.NewRequest("GET", "/", nil)) + Expect(rec.Header().Get("Content-Type")).To(Equal("application/problem+json")) + }) + + It("should rewrite Content-Type for 500 responses", func() { + rec := httptest.NewRecorder() + makeHandler(500, "application/json").ServeHTTP(rec, httptest.NewRequest("GET", "/", nil)) + Expect(rec.Header().Get("Content-Type")).To(Equal("application/problem+json")) + }) + + It("should preserve Content-Type for 200 responses", func() { + rec := httptest.NewRecorder() + handler := ProblemJSON(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + w.Write([]byte(`{"status":"ok"}`)) + })) + handler.ServeHTTP(rec, httptest.NewRequest("GET", "/", nil)) + Expect(rec.Header().Get("Content-Type")).To(Equal("application/json")) + }) + + It("should preserve Content-Type with charset for 400 responses", func() { + rec := httptest.NewRecorder() + makeHandler(404, "application/json; charset=utf-8").ServeHTTP(rec, httptest.NewRequest("GET", "/", nil)) + Expect(rec.Header().Get("Content-Type")).To(Equal("application/problem+json; charset=utf-8")) + }) + + It("should not touch non-JSON content types on errors", func() { + rec := httptest.NewRecorder() + makeHandler(500, "text/plain").ServeHTTP(rec, httptest.NewRequest("GET", "/", nil)) + Expect(rec.Header().Get("Content-Type")).To(Equal("text/plain")) + }) +}) diff --git a/internal/service/policy.go b/internal/service/policy.go index 38f807b..eb1758b 100644 --- a/internal/service/policy.go +++ b/internal/service/policy.go @@ -275,7 +275,7 @@ func (s *PolicyServiceImpl) ListPolicies(ctx context.Context, filter *string, or // Build response response := &v1alpha1.PolicyList{ - Policies: apiPolicies, + Results: apiPolicies, } if result.NextPageToken != "" { diff --git a/internal/service/policy_test.go b/internal/service/policy_test.go index 99718a9..8311096 100644 --- a/internal/service/policy_test.go +++ b/internal/service/policy_test.go @@ -495,13 +495,13 @@ var _ = Describe("PolicyService", func() { Expect(err).ToNot(HaveOccurred()) Expect(result).NotTo(BeNil()) - Expect(result.Policies).To(HaveLen(4)) + Expect(result.Results).To(HaveLen(4)) // Default order is policy_type ASC, priority ASC, id ASC // GLOBAL policies first, then USER policies - Expect(*result.Policies[0].Id).To(Equal("policy-1")) // GLOBAL, priority 100 - Expect(*result.Policies[1].Id).To(Equal("policy-3")) // GLOBAL, priority 300 - Expect(*result.Policies[2].Id).To(Equal("policy-2")) // USER, priority 200 - Expect(*result.Policies[3].Id).To(Equal("policy-4")) // USER, priority 400 + Expect(*result.Results[0].Id).To(Equal("policy-1")) // GLOBAL, priority 100 + Expect(*result.Results[1].Id).To(Equal("policy-3")) // GLOBAL, priority 300 + Expect(*result.Results[2].Id).To(Equal("policy-2")) // USER, priority 200 + Expect(*result.Results[3].Id).To(Equal("policy-4")) // USER, priority 400 }) It("should filter by policy_type=GLOBAL", func() { @@ -509,8 +509,8 @@ var _ = Describe("PolicyService", func() { result, err := policyService.ListPolicies(ctx, &filter, nil, nil, nil) Expect(err).ToNot(HaveOccurred()) - Expect(result.Policies).To(HaveLen(2)) - for _, p := range result.Policies { + Expect(result.Results).To(HaveLen(2)) + for _, p := range result.Results { Expect(p.PolicyType).NotTo(BeNil()) Expect(*p.PolicyType).To(Equal(v1alpha1.GLOBAL)) } @@ -521,8 +521,8 @@ var _ = Describe("PolicyService", func() { result, err := policyService.ListPolicies(ctx, &filter, nil, nil, nil) Expect(err).ToNot(HaveOccurred()) - Expect(result.Policies).To(HaveLen(2)) - for _, p := range result.Policies { + Expect(result.Results).To(HaveLen(2)) + for _, p := range result.Results { Expect(p.PolicyType).NotTo(BeNil()) Expect(*p.PolicyType).To(Equal(v1alpha1.USER)) } @@ -533,8 +533,8 @@ var _ = Describe("PolicyService", func() { result, err := policyService.ListPolicies(ctx, &filter, nil, nil, nil) Expect(err).ToNot(HaveOccurred()) - Expect(result.Policies).To(HaveLen(2)) - for _, p := range result.Policies { + Expect(result.Results).To(HaveLen(2)) + for _, p := range result.Results { Expect(*p.Enabled).To(BeTrue()) } }) @@ -544,8 +544,8 @@ var _ = Describe("PolicyService", func() { result, err := policyService.ListPolicies(ctx, &filter, nil, nil, nil) Expect(err).ToNot(HaveOccurred()) - Expect(result.Policies).To(HaveLen(2)) - for _, p := range result.Policies { + Expect(result.Results).To(HaveLen(2)) + for _, p := range result.Results { Expect(*p.Enabled).To(BeFalse()) } }) @@ -555,8 +555,8 @@ var _ = Describe("PolicyService", func() { result, err := policyService.ListPolicies(ctx, &filter, nil, nil, nil) Expect(err).ToNot(HaveOccurred()) - Expect(result.Policies).To(HaveLen(1)) - Expect(*result.Policies[0].Id).To(Equal("policy-1")) + Expect(result.Results).To(HaveLen(1)) + Expect(*result.Results[0].Id).To(Equal("policy-1")) }) It("should order by priority desc", func() { @@ -564,11 +564,11 @@ var _ = Describe("PolicyService", func() { result, err := policyService.ListPolicies(ctx, nil, &orderBy, nil, nil) Expect(err).ToNot(HaveOccurred()) - Expect(result.Policies).To(HaveLen(4)) - Expect(*result.Policies[0].Id).To(Equal("policy-4")) - Expect(*result.Policies[1].Id).To(Equal("policy-3")) - Expect(*result.Policies[2].Id).To(Equal("policy-2")) - Expect(*result.Policies[3].Id).To(Equal("policy-1")) + Expect(result.Results).To(HaveLen(4)) + Expect(*result.Results[0].Id).To(Equal("policy-4")) + Expect(*result.Results[1].Id).To(Equal("policy-3")) + Expect(*result.Results[2].Id).To(Equal("policy-2")) + Expect(*result.Results[3].Id).To(Equal("policy-1")) }) It("should support pagination", func() { @@ -576,14 +576,14 @@ var _ = Describe("PolicyService", func() { result, err := policyService.ListPolicies(ctx, nil, nil, nil, &pageSize) Expect(err).ToNot(HaveOccurred()) - Expect(result.Policies).To(HaveLen(2)) + Expect(result.Results).To(HaveLen(2)) Expect(result.NextPageToken).NotTo(BeNil()) // Get next page result2, err := policyService.ListPolicies(ctx, nil, nil, result.NextPageToken, &pageSize) Expect(err).ToNot(HaveOccurred()) - Expect(result2.Policies).To(HaveLen(2)) + Expect(result2.Results).To(HaveLen(2)) Expect(result2.NextPageToken).To(BeNil()) // No more pages }) diff --git a/test/e2e/policy_test.go b/test/e2e/policy_test.go index 7a1c5a3..b4aae5b 100644 --- a/test/e2e/policy_test.go +++ b/test/e2e/policy_test.go @@ -520,8 +520,8 @@ var _ = Describe("Policy CRUD Operations", func() { Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode()).To(Equal(http.StatusOK)) Expect(resp.JSON200).NotTo(BeNil()) - Expect(resp.JSON200.Policies).NotTo(BeEmpty()) - Expect(len(resp.JSON200.Policies)).To(BeNumerically(">=", 5)) + Expect(resp.JSON200.Results).NotTo(BeEmpty()) + Expect(len(resp.JSON200.Results)).To(BeNumerically(">=", 5)) }) It("should paginate with max_page_size", func() { @@ -532,7 +532,7 @@ var _ = Describe("Policy CRUD Operations", func() { Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode()).To(Equal(http.StatusOK)) Expect(resp.JSON200).NotTo(BeNil()) - Expect(len(resp.JSON200.Policies)).To(Equal(2)) + Expect(len(resp.JSON200.Results)).To(Equal(2)) }) It("should navigate to next page with page_token", func() { @@ -551,7 +551,7 @@ var _ = Describe("Policy CRUD Operations", func() { resp2, err := apiClient.ListPoliciesWithResponse(ctx, params2) Expect(err).NotTo(HaveOccurred()) Expect(resp2.StatusCode()).To(Equal(http.StatusOK)) - Expect(resp2.JSON200.Policies).NotTo(BeEmpty()) + Expect(resp2.JSON200.Results).NotTo(BeEmpty()) }) It("should verify next_page_token presence/absence", func() { @@ -619,7 +619,7 @@ var _ = Describe("Policy CRUD Operations", func() { resp, err := apiClient.ListPoliciesWithResponse(ctx, params) Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode()).To(Equal(http.StatusOK)) - for _, policy := range resp.JSON200.Policies { + for _, policy := range resp.JSON200.Results { Expect(*policy.PolicyType).To(Equal(v1alpha1.GLOBAL)) } }) @@ -632,7 +632,7 @@ var _ = Describe("Policy CRUD Operations", func() { resp, err := apiClient.ListPoliciesWithResponse(ctx, params) Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode()).To(Equal(http.StatusOK)) - for _, policy := range resp.JSON200.Policies { + for _, policy := range resp.JSON200.Results { Expect(*policy.PolicyType).To(Equal(v1alpha1.USER)) } }) @@ -645,7 +645,7 @@ var _ = Describe("Policy CRUD Operations", func() { resp, err := apiClient.ListPoliciesWithResponse(ctx, params) Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode()).To(Equal(http.StatusOK)) - for _, policy := range resp.JSON200.Policies { + for _, policy := range resp.JSON200.Results { Expect(policy.Enabled).NotTo(BeNil()) Expect(*policy.Enabled).To(BeTrue()) } @@ -659,7 +659,7 @@ var _ = Describe("Policy CRUD Operations", func() { resp, err := apiClient.ListPoliciesWithResponse(ctx, params) Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode()).To(Equal(http.StatusOK)) - for _, policy := range resp.JSON200.Policies { + for _, policy := range resp.JSON200.Results { Expect(policy.Enabled).NotTo(BeNil()) Expect(*policy.Enabled).To(BeFalse()) } @@ -673,7 +673,7 @@ var _ = Describe("Policy CRUD Operations", func() { resp, err := apiClient.ListPoliciesWithResponse(ctx, params) Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode()).To(Equal(http.StatusOK)) - for _, policy := range resp.JSON200.Policies { + for _, policy := range resp.JSON200.Results { Expect(*policy.PolicyType).To(Equal(v1alpha1.GLOBAL)) Expect(*policy.Enabled).To(BeTrue()) } @@ -755,7 +755,7 @@ var _ = Describe("Policy CRUD Operations", func() { // Verify ascending order var lastPriority int32 - for i, policy := range resp.JSON200.Policies { + for i, policy := range resp.JSON200.Results { if i > 0 && policy.Priority != nil { Expect(*policy.Priority).To(BeNumerically(">=", lastPriority)) } @@ -776,7 +776,7 @@ var _ = Describe("Policy CRUD Operations", func() { // Verify descending order var lastPriority int32 = 1001 // Higher than max - for _, policy := range resp.JSON200.Policies { + for _, policy := range resp.JSON200.Results { if policy.Priority != nil { Expect(*policy.Priority).To(BeNumerically("<=", lastPriority)) lastPriority = *policy.Priority @@ -795,7 +795,7 @@ var _ = Describe("Policy CRUD Operations", func() { // Verify alphabetical order var lastName string - for i, policy := range resp.JSON200.Policies { + for i, policy := range resp.JSON200.Results { if i > 0 && policy.DisplayName != nil { Expect(strings.ToLower(*policy.DisplayName) >= strings.ToLower(lastName)).To(BeTrue()) } @@ -813,7 +813,7 @@ var _ = Describe("Policy CRUD Operations", func() { resp, err := apiClient.ListPoliciesWithResponse(ctx, params) Expect(err).NotTo(HaveOccurred()) Expect(resp.StatusCode()).To(Equal(http.StatusOK)) - Expect(resp.JSON200.Policies).NotTo(BeEmpty()) + Expect(resp.JSON200.Results).NotTo(BeEmpty()) }) It("should reject order_by with unsupported field", func() { @@ -1534,7 +1534,7 @@ allow if { // Find the created policy in the list found := false - for _, p := range listResp.JSON200.Policies { + for _, p := range listResp.JSON200.Results { if *p.Id == policyID { found = true Expect(p.RegoCode).NotTo(BeNil())