From 5b510ffeca50504fb029967e4d9b13861ecc88d7 Mon Sep 17 00:00:00 2001 From: Anton Averchenkov <84287187+averche@users.noreply.github.com> Date: Thu, 25 May 2023 13:34:34 -0400 Subject: [PATCH] openapi: Fix response schema for pki list roles (#20782) --- builtin/logical/pki/path_roles.go | 14 +++++++------- builtin/logical/pki/path_roles_test.go | 7 +++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/builtin/logical/pki/path_roles.go b/builtin/logical/pki/path_roles.go index 4cb15d95d..16564085e 100644 --- a/builtin/logical/pki/path_roles.go +++ b/builtin/logical/pki/path_roles.go @@ -37,9 +37,9 @@ func pathListRoles(b *backend) *framework.Path { Description: "OK", Fields: map[string]*framework.FieldSchema{ "keys": { - Type: framework.TypeMap, - Description: `List of keys`, - Required: false, + Type: framework.TypeStringSlice, + Description: "List of roles", + Required: true, }, }, }}, @@ -53,7 +53,7 @@ func pathListRoles(b *backend) *framework.Path { } func pathRoles(b *backend) *framework.Path { - pathRolesResponse := map[string]*framework.FieldSchema{ + pathRolesResponseFields := map[string]*framework.FieldSchema{ "ttl": { Type: framework.TypeDurationSecond, Required: true, @@ -826,7 +826,7 @@ serviced by this role.`, Responses: map[int][]framework.Response{ http.StatusOK: {{ Description: "OK", - Fields: pathRolesResponse, + Fields: pathRolesResponseFields, }}, }, }, @@ -835,7 +835,7 @@ serviced by this role.`, Responses: map[int][]framework.Response{ http.StatusOK: {{ Description: "OK", - Fields: pathRolesResponse, + Fields: pathRolesResponseFields, }}, }, // Read more about why these flags are set in backend.go. @@ -858,7 +858,7 @@ serviced by this role.`, Responses: map[int][]framework.Response{ http.StatusOK: {{ Description: "OK", - Fields: pathRolesResponse, + Fields: pathRolesResponseFields, }}, }, // Read more about why these flags are set in backend.go. diff --git a/builtin/logical/pki/path_roles_test.go b/builtin/logical/pki/path_roles_test.go index fb729e836..98f5e277b 100644 --- a/builtin/logical/pki/path_roles_test.go +++ b/builtin/logical/pki/path_roles_test.go @@ -12,10 +12,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/vault/sdk/helper/testhelpers/schema" - "github.com/go-errors/errors" "github.com/hashicorp/go-secure-stdlib/strutil" + "github.com/hashicorp/vault/sdk/helper/testhelpers/schema" "github.com/hashicorp/vault/sdk/logical" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -146,14 +145,14 @@ func TestPki_RoleKeyUsage(t *testing.T) { } resp, err = b.HandleRequest(context.Background(), roleReq) - schema.ValidateResponse(t, schema.GetResponseSchema(t, b.Route("roles/testrole"), logical.UpdateOperation), resp, true) + schema.ValidateResponse(t, schema.GetResponseSchema(t, b.Route(roleReq.Path), logical.UpdateOperation), resp, true) if err != nil || (resp != nil && resp.IsError()) { t.Fatalf("bad: err: %v resp: %#v", err, resp) } roleReq.Operation = logical.ReadOperation resp, err = b.HandleRequest(context.Background(), roleReq) - schema.ValidateResponse(t, schema.GetResponseSchema(t, b.Route("roles/testrole"), logical.ReadOperation), resp, true) + schema.ValidateResponse(t, schema.GetResponseSchema(t, b.Route(roleReq.Path), logical.ReadOperation), resp, true) if err != nil || (resp != nil && resp.IsError()) { t.Fatalf("bad: err: %v resp: %#v", err, resp) }