From 1655f47044e9374b4232295827b0203d099df8b0 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Tue, 16 Mar 2021 18:23:40 +0100 Subject: [PATCH] Test openapi schema of /citizens --- .../citizen/database/CitizenRepository.kt | 2 +- .../component/citizen/routes/FindCitizens.kt | 16 +++++- src/main/resources/openapi2.yaml | 56 +++++++++++++++++++ src/test/kotlin/integration/Citizen routes.kt | 2 +- 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/fr/dcproject/component/citizen/database/CitizenRepository.kt b/src/main/kotlin/fr/dcproject/component/citizen/database/CitizenRepository.kt index aed738f..16046c0 100644 --- a/src/main/kotlin/fr/dcproject/component/citizen/database/CitizenRepository.kt +++ b/src/main/kotlin/fr/dcproject/component/citizen/database/CitizenRepository.kt @@ -35,7 +35,7 @@ class CitizenRepository(override var requester: Requester) : RepositoryI { sort: String? = null, direction: RepositoryI.Direction? = null, search: String? = null - ): Paginated = requester + ): Paginated = requester .getFunction("find_citizens") .select( page, diff --git a/src/main/kotlin/fr/dcproject/component/citizen/routes/FindCitizens.kt b/src/main/kotlin/fr/dcproject/component/citizen/routes/FindCitizens.kt index 8908c6c..d3d970c 100644 --- a/src/main/kotlin/fr/dcproject/component/citizen/routes/FindCitizens.kt +++ b/src/main/kotlin/fr/dcproject/component/citizen/routes/FindCitizens.kt @@ -1,8 +1,10 @@ package fr.dcproject.component.citizen.routes +import fr.dcproject.common.dto.toOutput import fr.dcproject.common.security.assert import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.citizen.CitizenAccessControl +import fr.dcproject.component.citizen.database.CitizenCreator import fr.dcproject.component.citizen.database.CitizenRepository import fr.dcproject.routes.PaginatedRequest import fr.dcproject.routes.PaginatedRequestI @@ -13,6 +15,7 @@ import io.ktor.locations.Location import io.ktor.locations.get import io.ktor.response.respond import io.ktor.routing.Route +import java.util.UUID @KtorExperimentalLocationsAPI object FindCitizens { @@ -29,7 +32,18 @@ object FindCitizens { get { val citizens = repo.find(it.page, it.limit, it.sort, it.direction, it.search) ac.assert { canView(citizens.result, citizenOrNull) } - call.respond(citizens) + call.respond( + citizens.toOutput { c: CitizenCreator -> + object { + val id: UUID = c.id + val name: Any = object { + val firstName: String = c.name.firstName + val lastName: String = c.name.lastName + } + val email: String = c.email + } + } + ) } } } diff --git a/src/main/resources/openapi2.yaml b/src/main/resources/openapi2.yaml index beb4889..b5fede6 100644 --- a/src/main/resources/openapi2.yaml +++ b/src/main/resources/openapi2.yaml @@ -362,6 +362,62 @@ paths: 404: description: no user with this email + /citizens: + get: + security: + - JWTAuth: [] + summary: Get all citizens + tags: + - citizen + operationId: getCitizens + parameters: + - $ref: '#/components/parameters/page' + - $ref: '#/components/parameters/limit' + - $ref: '#/components/parameters/sort' + - $ref: '#/components/parameters/direction' + - $ref: '#/components/parameters/search' + responses: + 200: + description: The Citizen objects + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/Paginated' + - type: object + properties: + result: + type: array + items: + type: object + required: + - id + - name + - email + properties: + id: + $ref: '#/components/schemas/UUID' + name: + type: object + required: + - firstName + - lastName + properties: + firstName: + type: string + example: + john + lastName: + type: string + example: + Doe + email: + type: string + format: email + example: my.email@dc-project.fr + 401: + $ref: '#/components/responses/401' + components: parameters: page: diff --git a/src/test/kotlin/integration/Citizen routes.kt b/src/test/kotlin/integration/Citizen routes.kt index 66d221c..1764ca3 100644 --- a/src/test/kotlin/integration/Citizen routes.kt +++ b/src/test/kotlin/integration/Citizen routes.kt @@ -23,7 +23,7 @@ import org.junit.jupiter.api.TestInstance @Tags(Tag("integration"), Tag("citizen")) class `Citizen routes` : BaseTest() { @Test - fun `I can get Citizens informations`() { + fun `I can get Citizens information`() { withIntegrationApplication { `Given I have citizen`("Jean", "Perrin", id = "5267a5c6-af42-4a02-aa2b-6b71d2e43973") `When I send a GET request`("/citizens") {