Tag based grouping for controllers#488
Tag based grouping for controllers#488DevNamedZed wants to merge 2 commits intofabrikt-io:masterfrom
Conversation
| enum class ControllerCodeGenOptionType(val description: String) { | ||
| SUSPEND_MODIFIER("This option adds the suspend modifier to the generated controller functions"), | ||
| AUTHENTICATION("This option adds the authentication parameter to the generated controller functions"), | ||
| TAG_GROUPING("This option groups controllers based on the first tag rather than paths"), |
There was a problem hiding this comment.
Can we make it even more clear what the option does?
| TAG_GROUPING("This option groups controllers based on the first tag rather than paths"), | |
| GROUP_BY_TAG("This option groups controllers based on the first tag rather than paths"), |
| * @param tagGrouping if true, groups paths by their first operation tag; | ||
| * if false, groups by the first URI path segment (default behavior) | ||
| */ | ||
| fun OpenApi3.routeToPaths(tagGrouping: Boolean): Map<String, Map<String, Path>> = |
There was a problem hiding this comment.
I would suggest a more explicit strategy approach as this API is a little vague.
Something along the lines of:
enum class GroupingStrategy {
BY_FIRST_TAG,
BY_FIRST_PATH_SEGMENT
}
fun OpenApi3.groupedPaths(groupingStrategy: GroupingStrategy)Perhaps with an even more clear return:
typealias GroupKey = String
typealias Route = String
typealias GroupedPaths = Map<GroupKey, Map<Route, Path>>
fun OpenApi3.groupedPaths(groupingStrategy: GroupingStrategy): GroupedPathsThere was a problem hiding this comment.
Sorry for late reply. I updated per comments. Thanks for library and taking this change
- Add new controller generation option - TAG_GROUPING - Update Ktor, Micronaut, Spring controller generators - Add unit tests and test in playground
- Use enum instead of boolean - Use type aliases instead of primitive types and collections - Rename functions for clearer meaning
3287bd7 to
e99f030
Compare
|
|
||
| typealias GroupKey = String | ||
| typealias Route = String | ||
| typealias GroupedPaths = Map<GroupKey, Map<Route, Path>> |
There was a problem hiding this comment.
I know this is a popular paradigm amoug some, but I personally dislike it. Please revert these typealias definitions, they give me post-scala ptsd :)
|
|
||
| private fun Path.firstOperationTagOrNull(): String? { | ||
| val opsInStableOrder = listOfNotNull( | ||
| get, post, put, patch, delete, options, head, trace |
There was a problem hiding this comment.
Can we avoid hardcoding this? We have QUERY nearly in spec and I don't want to change this
| } | ||
|
|
||
| @Test | ||
| fun `ensure TAG_GROUPING produces controllers grouped by first tag`() { |
There was a problem hiding this comment.
rather than add a dedicated test, either pick one of the resource/examples api specs and add tag grouping, or follow the existing pattern and commit generated code examples.
The pattern we use is that the test directory forms a living documentation of what is generated
| } | ||
|
|
||
| @Test | ||
| fun `ensure TAG_GROUPING produces controllers grouped by first tag`() { |
There was a problem hiding this comment.
Same comment as pervious. Follow existing test setup with expected output committed as files
Add option that enables grouping controllers by the first tag instead of URL path segments.