Skip to content

Commit 1b7c60b

Browse files
author
rriski
authored
feat: add check to detect duplicate endpoints in config.yaml (#134)
1 parent 6d3aed3 commit 1b7c60b

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ Service:
292292
- ServiceTaskCreate
293293
- ServiceTaskGet
294294
- ServiceUpdate
295-
- ServiceUpdate
296295
ServiceUser:
297296
- ServiceUserCreate
298297
- ServiceUserCredentialsModify

generator/config_check.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func checkDuplicateEndpoints(config map[string][]string) error {
8+
endpoints := make(map[string]struct{})
9+
duplicates := make(map[string]struct{})
10+
11+
for _, methods := range config {
12+
for _, method := range methods {
13+
if _, exists := endpoints[method]; exists {
14+
duplicates[method] = struct{}{}
15+
} else {
16+
endpoints[method] = struct{}{}
17+
}
18+
}
19+
}
20+
21+
if len(duplicates) > 0 {
22+
return fmt.Errorf("Duplicate endpoints found in config: %v", keys(duplicates))
23+
}
24+
return nil
25+
}
26+
27+
func keys(m map[string]struct{}) []string {
28+
keys := make([]string, 0, len(m))
29+
for k := range m {
30+
keys = append(keys, k)
31+
}
32+
return keys
33+
}

generator/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ func exec() error {
8282
return err
8383
}
8484

85+
// Check for duplicate endpoints
86+
err = checkDuplicateEndpoints(config)
87+
if err != nil {
88+
return err
89+
}
90+
8591
// Reads OpenAPI file and applies a patch
8692
docBytes, err := readOpenAPIPatched(cfg.OpenAPIFile, cfg.OpenAPIPatchFile)
8793
if err != nil {

0 commit comments

Comments
 (0)