Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort map keys for deterministic testing #45

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pkg/generators/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,18 @@ func isExtensionTag(tag string) bool {
return isExtension
}

// Returns sorted list of map keys. Needed for deterministic testing.
func sortedMapKeys(m map[string]string) []string {
keys := make([]string, len(m))
i := 0
for k := range m {
keys[i] = k
i++
}
sort.Strings(keys)
return keys
}

func (g openAPITypeWriter) generateExtensions(CommentLines []string) error {
tagValues := getOpenAPITagValue(CommentLines)
type NameValue struct {
Expand All @@ -440,7 +452,7 @@ func (g openAPITypeWriter) generateExtensions(CommentLines []string) error {
}
}
// Next, generate extensions from "tags".
for tagKey := range tagToExtension {
for _, tagKey := range sortedMapKeys(tagToExtension) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to sort by tag, not extension.

I'm not trying to make a point, I'm just making sure it's obvious :-)

tagValue, err := getSingleTagsValue(CommentLines, tagKey)
if err != nil {
return err
Expand Down