From ca402dbea70e2a4d50de2d219ace411829962913 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Wed, 17 Mar 2021 18:09:05 +0100 Subject: [PATCH] Test openapi schema of /comments/{comment} --- .../article/routes/CreateCommentArticle.kt | 1 + .../article/routes/GetArticleComments.kt | 1 + .../comment/generic/routes/GetOneComment.kt | 46 ++++++++++++++++++- src/main/resources/openapi2.yaml | 29 +++++++++++- 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt b/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt index 255301e..db0a7c7 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/article/routes/CreateCommentArticle.kt @@ -43,6 +43,7 @@ object CreateCommentArticle { object { val id: UUID = comment.id val content: String = comment.content + val childrenCount: Int = 0 val createdAt: DateTime = comment.createdAt val parent: Any? = comment.parent?.let { p -> object { diff --git a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt index 62c394a..7ea9a45 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/article/routes/GetArticleComments.kt @@ -44,6 +44,7 @@ object GetArticleComments { object { val id: UUID = comment.id val content: String = comment.content + val childrenCount: Int = comment.childrenCount ?: 0 val createdAt: DateTime = comment.createdAt val parent: Any? = comment.parent?.let { p -> object { diff --git a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt index 0ee00bc..5e21c1b 100644 --- a/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt +++ b/src/main/kotlin/fr/dcproject/component/comment/generic/routes/GetOneComment.kt @@ -13,6 +13,7 @@ import io.ktor.locations.Location import io.ktor.locations.get import io.ktor.response.respond import io.ktor.routing.Route +import org.joda.time.DateTime import java.util.UUID @KtorExperimentalLocationsAPI @@ -27,7 +28,50 @@ object GetOneComment { val comment = repo.findById(it.comment.id) ?: throw NotFoundException("Comment ${it.comment.id} not found") ac.assert { canView(comment, citizenOrNull) } - call.respond(HttpStatusCode.OK, comment) + call.respond( + HttpStatusCode.OK, + object { + val id: UUID = comment.id + val content: String = comment.content + val childrenCount: Int = comment.childrenCount ?: 0 + val createdAt: DateTime = comment.createdAt + val parent: Any? = comment.parent?.let { p -> + object { + val id: UUID = p.id + val reference: String = p.reference + } + } + val target: Any = comment.target.let { t -> + object { + val id: UUID = t.id + val reference: String = t.reference + } + } + val createdBy: Any = comment.createdBy.let { c -> + object { + val id: UUID = c.id + val name: Any = c.name.let { n -> + object { + val firstName: String = n.firstName + val lastName: String = n.lastName + } + } + val user: Any = c.user.let { u -> + object { + val username: String = u.username + } + } + } + } + val votes: Any = object { + val up: Int = 0 + val neutral: Int = 0 + val down: Int = 0 + val total: Int = 0 + val score: Int = 0 + } + } + ) } } } diff --git a/src/main/resources/openapi2.yaml b/src/main/resources/openapi2.yaml index 40c2f77..d49c75d 100644 --- a/src/main/resources/openapi2.yaml +++ b/src/main/resources/openapi2.yaml @@ -533,7 +533,20 @@ paths: $ref: '#/components/schemas/CommentResponse' 401: $ref: '#/components/responses/401' - + /comments/{comment}: + parameters: + - $ref: '#/components/parameters/comment' + get: + summary: Get Comment by Comment ID + tags: + - comment + responses: + 200: + description: Return Comment and children + content: + application/json: + schema: + $ref: '#/components/schemas/CommentResponse' components: parameters: page: @@ -626,6 +639,16 @@ components: type: string format: uuid + comment: + name: comment + in: path + description: The ID of comment + example: 701dc504-db49-7e3a-2c0a-32542507ea57 + required: true + schema: + type: string + format: uuid + responses: 401: description: Unautorized @@ -908,6 +931,7 @@ components: - createdBy - votes - target + - childrenCount properties: id: $ref: '#/components/schemas/UUID' @@ -934,6 +958,9 @@ components: $ref: '#/components/schemas/UUID' reference: type: string + childrenCount: + type: integer + minimum: 0 votes: properties: up: