From 15af0252b4f546fd9f7e403734e6af633e4f6fc2 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Fri, 1 Sep 2023 16:43:24 +0200 Subject: [PATCH] Sort permissions related methods after everything else --- openapi/code/service.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/openapi/code/service.go b/openapi/code/service.go index 4c4cf237c..9d8f39f34 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() + }) + + slices.SortFunc(permissionMethods, func(a, b *Method) bool { return a.CamelName() < b.CamelName() }) - return methods + + return append(primaryMethods, permissionMethods...) } // List returns a method annotated with x-databricks-crud:list