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 permissions related methods after everything else #599

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 22 additions & 4 deletions openapi/code/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package code
import (
"fmt"
"path/filepath"
"regexp"
"strings"

"github.com/databricks/databricks-sdk-go/openapi"
Expand Down Expand Up @@ -32,14 +33,31 @@ func (svc *Service) MatchesPackageName() bool {
}

// Methods returns sorted slice of methods
func (svc *Service) Methods() (methods []*Method) {
func (svc *Service) Methods() []*Method {
permissionOperationRegex := regexp.MustCompile(`(Permissions|PermissionLevels)$`)

// Order the primary methods first, followed by the permission methods.
// This keeps the docs in a more logical order. Otherwise, the permission
// methods would be interspersed with the primary methods.
primaryMethods := []*Method{}
permissionMethods := []*Method{}
for _, v := range svc.methods {
methods = append(methods, v)
if permissionOperationRegex.MatchString(v.Operation.OperationId) {
permissionMethods = append(permissionMethods, v)
} else {
primaryMethods = append(primaryMethods, v)
}
}
slices.SortFunc(methods, func(a, b *Method) bool {

slices.SortFunc(primaryMethods, func(a, b *Method) bool {
return a.CamelName() < b.CamelName()
})
return methods

slices.SortFunc(permissionMethods, func(a, b *Method) bool {
return a.CamelName() < b.CamelName()
})

return append(primaryMethods, permissionMethods...)
}

// List returns a method annotated with x-databricks-crud:list
Expand Down