Skip to content

Instantly share code, notes, and snippets.

@mike-seger
Created December 16, 2024 08:02
Show Gist options
  • Save mike-seger/96d857c7432fbd20cdf75091db48b6cb to your computer and use it in GitHub Desktop.
Save mike-seger/96d857c7432fbd20cdf75091db48b6cb to your computer and use it in GitHub Desktop.
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