Skip to content

Commit 35ebbc1

Browse files
adrianstanciujreynard-code
authored andcommitted
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 b1e2565 commit 35ebbc1

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

0 commit comments

Comments
 (0)