From e13ccf98357d5b50c20b2a153bf8144fb478e954 Mon Sep 17 00:00:00 2001 From: Max Bowsher Date: Tue, 25 Jul 2023 16:27:50 +0100 Subject: [PATCH] OpenAPI: Sort parameters for stable output (#22043) In my recent #21942, I overlooked the need to sort another part of the OpenAPI document to ensure stable output. I've also removed `strings.ToLower()` from the code I copied from, as this code is sorting Vault API parameter names, which are all lowercase anyway! --- sdk/framework/openapi.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sdk/framework/openapi.go b/sdk/framework/openapi.go index 92b2243108..6e76f8edc6 100644 --- a/sdk/framework/openapi.go +++ b/sdk/framework/openapi.go @@ -316,7 +316,7 @@ func documentPath(p *Path, backend *Backend, requestResponsePrefix string, doc * // Sort parameters for a stable output sort.Slice(pi.Parameters, func(i, j int) bool { - return strings.ToLower(pi.Parameters[i].Name) < strings.ToLower(pi.Parameters[j].Name) + return pi.Parameters[i].Name < pi.Parameters[j].Name }) // Process each supported operation by building up an Operation object @@ -462,6 +462,11 @@ func documentPath(p *Path, backend *Backend, requestResponsePrefix string, doc * } op.Parameters = append(op.Parameters, p) } + + // Sort parameters for a stable output + sort.Slice(op.Parameters, func(i, j int) bool { + return op.Parameters[i].Name < op.Parameters[j].Name + }) } // Add tags based on backend type