Skip to content

Commit

Permalink
Improve operation sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Düsterhöft committed Aug 27, 2018
1 parent a94ed52 commit d2371c8
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ internal object OpenApi20Generator {

private fun groupByPath(resources: List<ResourceModel>): Map<String, List<ResourceModel>> {
return resources.sortedWith(
// by path segment count first (first main resources, subresources later) - then path string
comparingInt<ResourceModel> { it.request.path.count { c -> c == '/' } }
// by first path segment, then path length, then path
comparing<ResourceModel, String> { it.request.path.split("/").firstOrNull().orEmpty() }
.thenComparing(comparingInt<ResourceModel> { it.request.path.count { c -> c == '/' } })
.thenComparing(comparing<ResourceModel, String> { it.request.path }))
.groupBy { it.request.path }
}
Expand Down

0 comments on commit d2371c8

Please sign in to comment.