Skip to content

Commit d2371c8

Browse files
author
Mathias Düsterhöft
committed
Improve operation sorting
1 parent a94ed52 commit d2371c8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

restdocs-openapi-gradle-plugin/src/main/kotlin/com/epages/restdocs/openapi/gradle/OpenApi20Generator.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ internal object OpenApi20Generator {
129129

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

0 commit comments

Comments
 (0)