Skip to content

Commit 4828431

Browse files
theoden9014cyberdelia
authored andcommitted
Fix condition for error when duplicate link titles (#47)
1 parent 5baa87f commit 4828431

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

gen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (s *Schema) Generate() ([]byte, error) {
7070
Definition: schema,
7171
}
7272

73-
if !s.CheckForDuplicateTitles() {
73+
if !s.AreTitleLinksUnique() {
7474
return nil, fmt.Errorf("duplicate titles detected for %s", context.Name)
7575
}
7676

@@ -241,13 +241,13 @@ func (s *Schema) Values(name string, l *Link) []string {
241241
return values
242242
}
243243

244-
// CheckForDuplicateTitles ensures that all titles are unique for a schema.
244+
// AreTitleLinksUnique ensures that all titles are unique for a schema.
245245
//
246246
// If more than one link in a given schema has the same title, we cannot
247247
// accurately generate the client from the schema. Although it's not strictly a
248248
// schema violation, it needs to be fixed before the client can be properly
249249
// generated.
250-
func (s *Schema) CheckForDuplicateTitles() bool {
250+
func (s *Schema) AreTitleLinksUnique() bool {
251251
titles := map[string]bool{}
252252
var uniqueLinks []*Link
253253
for _, link := range s.Links {
@@ -258,7 +258,7 @@ func (s *Schema) CheckForDuplicateTitles() bool {
258258
titles[title] = true
259259
}
260260

261-
return len(uniqueLinks) != len(s.Links)
261+
return len(uniqueLinks) == len(s.Links)
262262
}
263263

264264
// URL returns schema base URL.

gen_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ var linkTitleTests = []struct {
634634
},
635635
},
636636
},
637-
Expected: true,
637+
Expected: false,
638638
},
639639
{
640640
Schema: &Schema{
@@ -649,7 +649,7 @@ var linkTitleTests = []struct {
649649
},
650650
},
651651
},
652-
Expected: true,
652+
Expected: false,
653653
},
654654
{
655655
Schema: &Schema{
@@ -664,13 +664,13 @@ var linkTitleTests = []struct {
664664
},
665665
},
666666
},
667-
Expected: false,
667+
Expected: true,
668668
},
669669
}
670670

671671
func TestLinkTitles(t *testing.T) {
672672
for i, lt := range linkTitleTests {
673-
resp := lt.Schema.CheckForDuplicateTitles()
673+
resp := lt.Schema.AreTitleLinksUnique()
674674
if resp != lt.Expected {
675675
t.Errorf("%d: wants %v, got %v", i, lt.Expected, resp)
676676
}

0 commit comments

Comments
 (0)