{"action":"created","comment":{"url":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/comments/280793191","pull_request_review_id":233494842,"id":280793191,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI4MDc5MzE5MQ==","diff_hunk":"@@ -0,0 +1,141 @@\n+package kuick.api.rest\n+\n+\n+import com.google.gson.JsonArray\n+import com.google.gson.JsonElement\n+import com.google.gson.JsonObject\n+import com.google.gson.JsonParser\n+import com.google.inject.Injector\n+import io.ktor.application.call\n+import io.ktor.http.ContentType\n+import io.ktor.http.HttpMethod\n+import io.ktor.request.receiveText\n+import io.ktor.response.respondText\n+import io.ktor.routing.Route\n+import io.ktor.routing.route\n+import io.ktor.util.AttributeKey\n+import kuick.api.buildArgsFromObject\n+import kuick.api.invokeHandler\n+import kuick.json.Json.gson\n+import kotlin.reflect.KFunction\n+import kotlin.reflect.KProperty\n+\n+\n+data class RestRouting(\n+        val parent: Route,\n+        val resourceName: String,\n+        val api: Any,\n+        val injector: Injector\n+) {\n+\n+    fun <T> registerRoute(route: RestRoute<T>): Route =\n+            parent.route(resourceName, method = route.httpMethod) {\n+                println(\"REST: ${route.httpMethod.value} /$resourceName -> ${route.handler}\") // logging\n+\n+                handle {\n+                    val jsonParser = JsonParser()\n+\n+                    val args = buildArgsFromObject(\n+                            route.handler,\n+                            jsonParser.parse(call.receiveText()),\n+                            call.attributes.allKeys.map { it.name to call.attributes[it as AttributeKey<Any>] }.toMap()\n+                    )\n+\n+                    val result = invokeHandler(api, route.handler, args)\n+\n+                    val jsonResult = gson.toJsonTree(result)\n+\n+                    //TODO is it a right place to handle these parameters?\n+                    val queryParameters = call.request.queryParameters\n+                    if (route.withFieldsParameter && queryParameters.contains(\"\\$fields\")) {\n+                        handleFieldsParam(jsonResult, queryParameters[\"\\$fields\"]!!)\n+                    }\n+                    if (route.withFieldsParameter && queryParameters.contains(\"\\$include\")) {\n+                        handleIncludeParam(jsonResult, queryParameters[\"\\$include\"]!!, route.includeParameterConfiguration)\n+                    }\n+\n+                    call.respondText(jsonResult.toString(), ContentType.Application.Json) // serialization\n+                }\n+            }\n+\n+    private fun handleFieldsParam(jsonResult: JsonElement, fieldsParam: String) {","path":"kuick-api-rest/src/jvmMain/kotlin/kuick/api/rest/rest.kt","position":60,"original_position":61,"commit_id":"e236b0438e34841ec416aa52309372bab51cd8ca","original_commit_id":"fee3f161cbbb14ef77d6db13baa2f7c0caa3fa95","user":{"login":"mpiniarski","id":11861292,"node_id":"MDQ6VXNlcjExODYxMjky","avatar_url":"https://avatars2.githubusercontent.com/u/11861292?v=4","gravatar_id":"","url":"https://api.github.com/users/mpiniarski","html_url":"https://github.com/mpiniarski","followers_url":"https://api.github.com/users/mpiniarski/followers","following_url":"https://api.github.com/users/mpiniarski/following{/other_user}","gists_url":"https://api.github.com/users/mpiniarski/gists{/gist_id}","starred_url":"https://api.github.com/users/mpiniarski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpiniarski/subscriptions","organizations_url":"https://api.github.com/users/mpiniarski/orgs","repos_url":"https://api.github.com/users/mpiniarski/repos","events_url":"https://api.github.com/users/mpiniarski/events{/privacy}","received_events_url":"https://api.github.com/users/mpiniarski/received_events","type":"User","site_admin":false},"body":"Sounds reasonable.\r\nIt would be ```fun JsonElement.preserveFields``` casue this funcionality is whitelist, not blacklist.\r\nWhat do you think?","created_at":"2019-05-03T14:19:34Z","updated_at":"2019-05-03T14:19:34Z","html_url":"https://github.com/NoSpoonLab/kuick/pull/34#discussion_r280793191","pull_request_url":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/34","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/comments/280793191"},"html":{"href":"https://github.com/NoSpoonLab/kuick/pull/34#discussion_r280793191"},"pull_request":{"href":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/34"}},"in_reply_to_id":277808339},"pull_request":{"url":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/34","id":272815715,"node_id":"MDExOlB1bGxSZXF1ZXN0MjcyODE1NzE1","html_url":"https://github.com/NoSpoonLab/kuick/pull/34","diff_url":"https://github.com/NoSpoonLab/kuick/pull/34.diff","patch_url":"https://github.com/NoSpoonLab/kuick/pull/34.patch","issue_url":"https://api.github.com/repos/NoSpoonLab/kuick/issues/34","number":34,"state":"open","locked":false,"title":"Api proposition ","user":{"login":"mpiniarski","id":11861292,"node_id":"MDQ6VXNlcjExODYxMjky","avatar_url":"https://avatars2.githubusercontent.com/u/11861292?v=4","gravatar_id":"","url":"https://api.github.com/users/mpiniarski","html_url":"https://github.com/mpiniarski","followers_url":"https://api.github.com/users/mpiniarski/followers","following_url":"https://api.github.com/users/mpiniarski/following{/other_user}","gists_url":"https://api.github.com/users/mpiniarski/gists{/gist_id}","starred_url":"https://api.github.com/users/mpiniarski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpiniarski/subscriptions","organizations_url":"https://api.github.com/users/mpiniarski/orgs","repos_url":"https://api.github.com/users/mpiniarski/repos","events_url":"https://api.github.com/users/mpiniarski/events{/privacy}","received_events_url":"https://api.github.com/users/mpiniarski/received_events","type":"User","site_admin":false},"body":"Proposition of integrating API building functionality to kuick.\r\n`kuick-api` together with `kuick-api-*` modules would provide funtionalities to quickly build flexible APIs in following models: rest, rpc and graphql, providing just minimal required configuration.\r\nProposed implementations are extensions for ktor framework. ","created_at":"2019-04-23T17:01:03Z","updated_at":"2019-05-03T14:19:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"84da5e389be8eb4642d35e0723bf3a641476b678","assignee":null,"assignees":[],"requested_reviewers":[{"login":"maballesteros","id":7047704,"node_id":"MDQ6VXNlcjcwNDc3MDQ=","avatar_url":"https://avatars3.githubusercontent.com/u/7047704?v=4","gravatar_id":"","url":"https://api.github.com/users/maballesteros","html_url":"https://github.com/maballesteros","followers_url":"https://api.github.com/users/maballesteros/followers","following_url":"https://api.github.com/users/maballesteros/following{/other_user}","gists_url":"https://api.github.com/users/maballesteros/gists{/gist_id}","starred_url":"https://api.github.com/users/maballesteros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maballesteros/subscriptions","organizations_url":"https://api.github.com/users/maballesteros/orgs","repos_url":"https://api.github.com/users/maballesteros/repos","events_url":"https://api.github.com/users/maballesteros/events{/privacy}","received_events_url":"https://api.github.com/users/maballesteros/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":1268169025,"node_id":"MDU6TGFiZWwxMjY4MTY5MDI1","url":"https://api.github.com/repos/NoSpoonLab/kuick/labels/help%20wanted","name":"help wanted","color":"008672","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/34/commits","review_comments_url":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/34/comments","review_comment_url":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/comments{/number}","comments_url":"https://api.github.com/repos/NoSpoonLab/kuick/issues/34/comments","statuses_url":"https://api.github.com/repos/NoSpoonLab/kuick/statuses/e236b0438e34841ec416aa52309372bab51cd8ca","head":{"label":"NoSpoonLab:api","ref":"api","sha":"e236b0438e34841ec416aa52309372bab51cd8ca","user":{"login":"NoSpoonLab","id":18526091,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE4NTI2MDkx","avatar_url":"https://avatars3.githubusercontent.com/u/18526091?v=4","gravatar_id":"","url":"https://api.github.com/users/NoSpoonLab","html_url":"https://github.com/NoSpoonLab","followers_url":"https://api.github.com/users/NoSpoonLab/followers","following_url":"https://api.github.com/users/NoSpoonLab/following{/other_user}","gists_url":"https://api.github.com/users/NoSpoonLab/gists{/gist_id}","starred_url":"https://api.github.com/users/NoSpoonLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NoSpoonLab/subscriptions","organizations_url":"https://api.github.com/users/NoSpoonLab/orgs","repos_url":"https://api.github.com/users/NoSpoonLab/repos","events_url":"https://api.github.com/users/NoSpoonLab/events{/privacy}","received_events_url":"https://api.github.com/users/NoSpoonLab/received_events","type":"Organization","site_admin":false},"repo":{"id":175035311,"node_id":"MDEwOlJlcG9zaXRvcnkxNzUwMzUzMTE=","name":"kuick","full_name":"NoSpoonLab/kuick","private":false,"owner":{"login":"NoSpoonLab","id":18526091,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE4NTI2MDkx","avatar_url":"https://avatars3.githubusercontent.com/u/18526091?v=4","gravatar_id":"","url":"https://api.github.com/users/NoSpoonLab","html_url":"https://github.com/NoSpoonLab","followers_url":"https://api.github.com/users/NoSpoonLab/followers","following_url":"https://api.github.com/users/NoSpoonLab/following{/other_user}","gists_url":"https://api.github.com/users/NoSpoonLab/gists{/gist_id}","starred_url":"https://api.github.com/users/NoSpoonLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NoSpoonLab/subscriptions","organizations_url":"https://api.github.com/users/NoSpoonLab/orgs","repos_url":"https://api.github.com/users/NoSpoonLab/repos","events_url":"https://api.github.com/users/NoSpoonLab/events{/privacy}","received_events_url":"https://api.github.com/users/NoSpoonLab/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/NoSpoonLab/kuick","description":null,"fork":false,"url":"https://api.github.com/repos/NoSpoonLab/kuick","forks_url":"https://api.github.com/repos/NoSpoonLab/kuick/forks","keys_url":"https://api.github.com/repos/NoSpoonLab/kuick/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NoSpoonLab/kuick/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NoSpoonLab/kuick/teams","hooks_url":"https://api.github.com/repos/NoSpoonLab/kuick/hooks","issue_events_url":"https://api.github.com/repos/NoSpoonLab/kuick/issues/events{/number}","events_url":"https://api.github.com/repos/NoSpoonLab/kuick/events","assignees_url":"https://api.github.com/repos/NoSpoonLab/kuick/assignees{/user}","branches_url":"https://api.github.com/repos/NoSpoonLab/kuick/branches{/branch}","tags_url":"https://api.github.com/repos/NoSpoonLab/kuick/tags","blobs_url":"https://api.github.com/repos/NoSpoonLab/kuick/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NoSpoonLab/kuick/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NoSpoonLab/kuick/git/refs{/sha}","trees_url":"https://api.github.com/repos/NoSpoonLab/kuick/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NoSpoonLab/kuick/statuses/{sha}","languages_url":"https://api.github.com/repos/NoSpoonLab/kuick/languages","stargazers_url":"https://api.github.com/repos/NoSpoonLab/kuick/stargazers","contributors_url":"https://api.github.com/repos/NoSpoonLab/kuick/contributors","subscribers_url":"https://api.github.com/repos/NoSpoonLab/kuick/subscribers","subscription_url":"https://api.github.com/repos/NoSpoonLab/kuick/subscription","commits_url":"https://api.github.com/repos/NoSpoonLab/kuick/commits{/sha}","git_commits_url":"https://api.github.com/repos/NoSpoonLab/kuick/git/commits{/sha}","comments_url":"https://api.github.com/repos/NoSpoonLab/kuick/comments{/number}","issue_comment_url":"https://api.github.com/repos/NoSpoonLab/kuick/issues/comments{/number}","contents_url":"https://api.github.com/repos/NoSpoonLab/kuick/contents/{+path}","compare_url":"https://api.github.com/repos/NoSpoonLab/kuick/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NoSpoonLab/kuick/merges","archive_url":"https://api.github.com/repos/NoSpoonLab/kuick/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NoSpoonLab/kuick/downloads","issues_url":"https://api.github.com/repos/NoSpoonLab/kuick/issues{/number}","pulls_url":"https://api.github.com/repos/NoSpoonLab/kuick/pulls{/number}","milestones_url":"https://api.github.com/repos/NoSpoonLab/kuick/milestones{/number}","notifications_url":"https://api.github.com/repos/NoSpoonLab/kuick/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NoSpoonLab/kuick/labels{/name}","releases_url":"https://api.github.com/repos/NoSpoonLab/kuick/releases{/id}","deployments_url":"https://api.github.com/repos/NoSpoonLab/kuick/deployments","created_at":"2019-03-11T15:58:47Z","updated_at":"2019-04-23T17:12:28Z","pushed_at":"2019-04-24T12:11:29Z","git_url":"git://github.com/NoSpoonLab/kuick.git","ssh_url":"git@github.com:NoSpoonLab/kuick.git","clone_url":"https://github.com/NoSpoonLab/kuick.git","svn_url":"https://github.com/NoSpoonLab/kuick","homepage":null,"size":607,"stargazers_count":1,"watchers_count":1,"language":"Kotlin","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"NoSpoonLab:master","ref":"master","sha":"2a62577917f240fd5c54168221d67343a37892a3","user":{"login":"NoSpoonLab","id":18526091,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE4NTI2MDkx","avatar_url":"https://avatars3.githubusercontent.com/u/18526091?v=4","gravatar_id":"","url":"https://api.github.com/users/NoSpoonLab","html_url":"https://github.com/NoSpoonLab","followers_url":"https://api.github.com/users/NoSpoonLab/followers","following_url":"https://api.github.com/users/NoSpoonLab/following{/other_user}","gists_url":"https://api.github.com/users/NoSpoonLab/gists{/gist_id}","starred_url":"https://api.github.com/users/NoSpoonLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NoSpoonLab/subscriptions","organizations_url":"https://api.github.com/users/NoSpoonLab/orgs","repos_url":"https://api.github.com/users/NoSpoonLab/repos","events_url":"https://api.github.com/users/NoSpoonLab/events{/privacy}","received_events_url":"https://api.github.com/users/NoSpoonLab/received_events","type":"Organization","site_admin":false},"repo":{"id":175035311,"node_id":"MDEwOlJlcG9zaXRvcnkxNzUwMzUzMTE=","name":"kuick","full_name":"NoSpoonLab/kuick","private":false,"owner":{"login":"NoSpoonLab","id":18526091,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE4NTI2MDkx","avatar_url":"https://avatars3.githubusercontent.com/u/18526091?v=4","gravatar_id":"","url":"https://api.github.com/users/NoSpoonLab","html_url":"https://github.com/NoSpoonLab","followers_url":"https://api.github.com/users/NoSpoonLab/followers","following_url":"https://api.github.com/users/NoSpoonLab/following{/other_user}","gists_url":"https://api.github.com/users/NoSpoonLab/gists{/gist_id}","starred_url":"https://api.github.com/users/NoSpoonLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NoSpoonLab/subscriptions","organizations_url":"https://api.github.com/users/NoSpoonLab/orgs","repos_url":"https://api.github.com/users/NoSpoonLab/repos","events_url":"https://api.github.com/users/NoSpoonLab/events{/privacy}","received_events_url":"https://api.github.com/users/NoSpoonLab/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/NoSpoonLab/kuick","description":null,"fork":false,"url":"https://api.github.com/repos/NoSpoonLab/kuick","forks_url":"https://api.github.com/repos/NoSpoonLab/kuick/forks","keys_url":"https://api.github.com/repos/NoSpoonLab/kuick/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NoSpoonLab/kuick/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NoSpoonLab/kuick/teams","hooks_url":"https://api.github.com/repos/NoSpoonLab/kuick/hooks","issue_events_url":"https://api.github.com/repos/NoSpoonLab/kuick/issues/events{/number}","events_url":"https://api.github.com/repos/NoSpoonLab/kuick/events","assignees_url":"https://api.github.com/repos/NoSpoonLab/kuick/assignees{/user}","branches_url":"https://api.github.com/repos/NoSpoonLab/kuick/branches{/branch}","tags_url":"https://api.github.com/repos/NoSpoonLab/kuick/tags","blobs_url":"https://api.github.com/repos/NoSpoonLab/kuick/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NoSpoonLab/kuick/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NoSpoonLab/kuick/git/refs{/sha}","trees_url":"https://api.github.com/repos/NoSpoonLab/kuick/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NoSpoonLab/kuick/statuses/{sha}","languages_url":"https://api.github.com/repos/NoSpoonLab/kuick/languages","stargazers_url":"https://api.github.com/repos/NoSpoonLab/kuick/stargazers","contributors_url":"https://api.github.com/repos/NoSpoonLab/kuick/contributors","subscribers_url":"https://api.github.com/repos/NoSpoonLab/kuick/subscribers","subscription_url":"https://api.github.com/repos/NoSpoonLab/kuick/subscription","commits_url":"https://api.github.com/repos/NoSpoonLab/kuick/commits{/sha}","git_commits_url":"https://api.github.com/repos/NoSpoonLab/kuick/git/commits{/sha}","comments_url":"https://api.github.com/repos/NoSpoonLab/kuick/comments{/number}","issue_comment_url":"https://api.github.com/repos/NoSpoonLab/kuick/issues/comments{/number}","contents_url":"https://api.github.com/repos/NoSpoonLab/kuick/contents/{+path}","compare_url":"https://api.github.com/repos/NoSpoonLab/kuick/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NoSpoonLab/kuick/merges","archive_url":"https://api.github.com/repos/NoSpoonLab/kuick/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NoSpoonLab/kuick/downloads","issues_url":"https://api.github.com/repos/NoSpoonLab/kuick/issues{/number}","pulls_url":"https://api.github.com/repos/NoSpoonLab/kuick/pulls{/number}","milestones_url":"https://api.github.com/repos/NoSpoonLab/kuick/milestones{/number}","notifications_url":"https://api.github.com/repos/NoSpoonLab/kuick/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NoSpoonLab/kuick/labels{/name}","releases_url":"https://api.github.com/repos/NoSpoonLab/kuick/releases{/id}","deployments_url":"https://api.github.com/repos/NoSpoonLab/kuick/deployments","created_at":"2019-03-11T15:58:47Z","updated_at":"2019-04-23T17:12:28Z","pushed_at":"2019-04-24T12:11:29Z","git_url":"git://github.com/NoSpoonLab/kuick.git","ssh_url":"git@github.com:NoSpoonLab/kuick.git","clone_url":"https://github.com/NoSpoonLab/kuick.git","svn_url":"https://github.com/NoSpoonLab/kuick","homepage":null,"size":607,"stargazers_count":1,"watchers_count":1,"language":"Kotlin","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/34"},"html":{"href":"https://github.com/NoSpoonLab/kuick/pull/34"},"issue":{"href":"https://api.github.com/repos/NoSpoonLab/kuick/issues/34"},"comments":{"href":"https://api.github.com/repos/NoSpoonLab/kuick/issues/34/comments"},"review_comments":{"href":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/34/comments"},"review_comment":{"href":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/NoSpoonLab/kuick/pulls/34/commits"},"statuses":{"href":"https://api.github.com/repos/NoSpoonLab/kuick/statuses/e236b0438e34841ec416aa52309372bab51cd8ca"}},"author_association":"NONE"}}
{"actor":{"display_login":"mpiniarski"}}