Created
December 16, 2024 08:02
-
-
Save mike-seger/96d857c7432fbd20cdf75091db48b6cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.swagger.v3.oas.models.Paths | |
import io.swagger.v3.oas.models.OpenAPI | |
import org.springdoc.core.customizers.OpenApiCustomiser | |
import org.springframework.context.annotation.Bean | |
import org.springframework.context.annotation.Configuration | |
import java.util.TreeMap | |
@Configuration | |
class OpenApiConfig { | |
@Bean | |
fun sortPathsCustomiser(): OpenApiCustomiser { | |
return OpenApiCustomiser { openApi: OpenAPI -> | |
val paths = openApi.paths | |
if (paths != null) { | |
// Use TreeMap to sort paths alphabetically | |
val sortedPaths = Paths() | |
TreeMap(paths).forEach { (key, value) -> | |
sortedPaths.addPathItem(key, value) | |
} | |
openApi.paths = sortedPaths | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment