diff --git a/openapi/code/service.go b/openapi/code/service.go index 4d5fba426..25a7e2bd8 100644 --- a/openapi/code/service.go +++ b/openapi/code/service.go @@ -3,6 +3,7 @@ package code import ( "fmt" "path/filepath" + "regexp" "strings" "github.com/databricks/databricks-sdk-go/openapi" @@ -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