Skip to content

Commit f2421af

Browse files
committed
Fix OpenAPI module ordering to respect settings.gradle.kts include() order
- Modified copySubProjectsOpenAPIFiles task to sort modules based on the order defined in settings.gradle.kts - Replaced alphabetical ordering with custom sorting that uses rootProject.subprojects order - Unknown modules are placed at the end using Int.MAX_VALUE as sort key - This ensures the generated OpenAPI specification preserves the intended module sequence
1 parent 4668ba1 commit f2421af

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

api/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ tasks.register<Copy>("copySubProjectsOpenAPIFiles") {
4747
// By convention, we expect OpenAPI files for sub-projects to be named and placed as follows:
4848
// <subproject>/src/main/openapi/<subproject>.yaml
4949
// For example: organization/src/main/openapi/organization.yaml
50+
// Get the order from settings.gradle.kts include() declaration
51+
val moduleOrder = rootProject.subprojects.map { it.name }
52+
5053
val sourcePaths =
5154
configurations.implementation
5255
.get()
@@ -61,6 +64,12 @@ tasks.register<Copy>("copySubProjectsOpenAPIFiles") {
6164
.map { file("${it}/src/main/openapi/${it.relativeTo(rootDir)}.yaml") }
6265
.filter { it.exists() }
6366
.map { it.absolutePath }
67+
.sortedBy { path ->
68+
// Extract module name from path and find its index in the desired order
69+
val moduleName = file(path).parentFile.parentFile.parentFile.name
70+
val index = moduleOrder.indexOf(moduleName)
71+
if (index >= 0) index else Int.MAX_VALUE // Put unknown modules at the end
72+
}
6473
.toMutableList()
6574
// If you need to reference a non-conventional path, feel free to add it below to the
6675
// sourcePaths local variable, like so: sourcePaths.add("my/path/to/another/openapi.yaml")

0 commit comments

Comments
 (0)