Skip to content

Commit

Permalink
feat: add check to detect duplicate endpoints in config.yaml (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
rriski authored Oct 4, 2024
1 parent 6d3aed3 commit 1b7c60b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 0 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ Service:
- ServiceTaskCreate
- ServiceTaskGet
- ServiceUpdate
- ServiceUpdate
ServiceUser:
- ServiceUserCreate
- ServiceUserCredentialsModify
Expand Down
33 changes: 33 additions & 0 deletions generator/config_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"fmt"
)

func checkDuplicateEndpoints(config map[string][]string) error {
endpoints := make(map[string]struct{})
duplicates := make(map[string]struct{})

for _, methods := range config {
for _, method := range methods {
if _, exists := endpoints[method]; exists {
duplicates[method] = struct{}{}
} else {
endpoints[method] = struct{}{}
}
}
}

if len(duplicates) > 0 {
return fmt.Errorf("Duplicate endpoints found in config: %v", keys(duplicates))
}
return nil
}

func keys(m map[string]struct{}) []string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
return keys
}
6 changes: 6 additions & 0 deletions generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ func exec() error {
return err
}

// Check for duplicate endpoints
err = checkDuplicateEndpoints(config)
if err != nil {
return err
}

// Reads OpenAPI file and applies a patch
docBytes, err := readOpenAPIPatched(cfg.OpenAPIFile, cfg.OpenAPIPatchFile)
if err != nil {
Expand Down

0 comments on commit 1b7c60b

Please sign in to comment.