Test openapi schema of /citizens/current

This commit is contained in:
2021-03-16 18:51:41 +01:00
parent 1655f47044
commit 52bdcd0990
3 changed files with 85 additions and 4 deletions

View File

@@ -11,6 +11,9 @@ 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 org.joda.time.format.ISODateTimeFormat
import java.util.UUID
@KtorExperimentalLocationsAPI
object GetCurrentCitizen {
@@ -24,7 +27,25 @@ object GetCurrentCitizen {
call.respond(HttpStatusCode.Unauthorized)
} else {
ac.assert { canView(currentUser, citizenOrNull) }
call.respond(citizen)
call.respond(
object {
val id: UUID = citizen.id
val name: Any = citizen.name.let { n ->
object {
val firstName: String = n.firstName
val lastName: String = n.lastName
}
}
val email: String = citizen.email
val birthday: String = citizen.birthday.run {
toString(ISODateTimeFormat.date())
}
val createdAt: DateTime = citizen.createdAt
val user: Any = object {
val username: String = citizen.user.username
}
}
)
}
}
}

View File

@@ -418,6 +418,66 @@ paths:
401:
$ref: '#/components/responses/401'
/citizens/current:
get:
security:
- JWTAuth: []
summary: Get Citizen
tags:
- citizen
operationId: getCurrentCitizen
responses:
200:
description: The Citizen object
content:
application/json:
schema:
type: object
required:
- id
- name
- email
- createdAt
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
birthday:
type: string
format: 'date'
example: '1984-12-25'
createdAt:
type: string
format: 'date-time'
user:
type: object
required:
- username
properties:
id:
$ref: '#/components/schemas/UUID'
username:
type: string
example:
john-doe
components:
parameters:
page: