Skip to content

Commit

Permalink
Fix non-deterministic ordering of 'required' field in OpenAPI spec
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
maxb committed May 30, 2023
1 parent 4d7d175 commit 0cadf43
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sdk/framework/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0cadf43

Please sign in to comment.