Skip to content

Commit

Permalink
importer-rest-api-specs: normalize swagger tag names to prevent dup…
Browse files Browse the repository at this point in the history
…licates (avoid parsing the same tag twice)
  • Loading branch information
manicminer committed Jul 18, 2024
1 parent 9673038 commit a55bf59
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ package parser

import (
"sort"
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func (p *apiDefinitionsParser) ParseSwaggerTags() []string {
tags := make(map[string]struct{})

// first we go through, assuming there are tags
for _, operation := range p.context.SwaggerSpecExpanded.Operations() {
for _, details := range operation {
for _, tag := range details.Tags {
tags[tag] = struct{}{}
normalizedTag := cases.Title(language.AmericanEnglish, cases.NoLower).String(tag)
tags[normalizedTag] = struct{}{}
}
}
}

out := make([]string, 0)
for key := range tags {
out = append(out, strings.Title(key))
out = append(out, key)
}
sort.Strings(out)
return out
Expand Down

0 comments on commit a55bf59

Please sign in to comment.