From e65d295c8809f4cc61b63bbc03293586c71c5483 Mon Sep 17 00:00:00 2001 From: Max Bowsher Date: Wed, 31 May 2023 20:10:24 +0100 Subject: [PATCH] Fix non-deterministic ordering of 'required' field in OpenAPI spec (#20881) * Fix non-deterministic ordering of 'required' field in OpenAPI spec Fixes a minor annoyance I discovered whilst comparing before and after OpenAPI specs whilst working on hashicorp/vault-client-go#180. Sort the entries in a JSON array which has set semantics, after we construct it by iterating a map (non-deterministic ordering). * changelog --- changelog/20881.txt | 3 +++ sdk/framework/openapi.go | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 changelog/20881.txt diff --git a/changelog/20881.txt b/changelog/20881.txt new file mode 100644 index 000000000000..fd3e6d5fa44f --- /dev/null +++ b/changelog/20881.txt @@ -0,0 +1,3 @@ +```release-note:improvement +sdk/framework: Fix non-deterministic ordering of 'required' fields in OpenAPI spec +``` diff --git a/sdk/framework/openapi.go b/sdk/framework/openapi.go index 3c99fe508e78..53e7ee256c30 100644 --- a/sdk/framework/openapi.go +++ b/sdk/framework/openapi.go @@ -383,6 +383,10 @@ func documentPath(p *Path, specialPaths *logical.Paths, requestResponsePrefix st s.Properties[name] = &p } + // Make the ordering deterministic, so that the generated OpenAPI spec document, observed over several + // versions, doesn't contain spurious non-semantic changes. + sort.Strings(s.Required) + // If examples were given, use the first one as the sample // of this schema. if len(props.Examples) > 0 {