Test openapi schema of /citizens/{id}
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package fr.dcproject.component.citizen.routes
|
package fr.dcproject.component.citizen.routes
|
||||||
|
|
||||||
import fr.dcproject.common.security.assert
|
import fr.dcproject.common.security.assert
|
||||||
|
import fr.dcproject.component.auth.citizen
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.component.citizen.CitizenAccessControl
|
import fr.dcproject.component.citizen.CitizenAccessControl
|
||||||
import fr.dcproject.component.citizen.database.CitizenRef
|
import fr.dcproject.component.citizen.database.CitizenRef
|
||||||
@@ -12,6 +13,8 @@ import io.ktor.locations.Location
|
|||||||
import io.ktor.locations.get
|
import io.ktor.locations.get
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
import org.joda.time.format.ISODateTimeFormat
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
@@ -26,7 +29,25 @@ object GetOneCitizen {
|
|||||||
val citizen = citizenRepository.findById(it.citizen.id) ?: throw NotFoundException("Citizen not found ${it.citizen.id}")
|
val citizen = citizenRepository.findById(it.citizen.id) ?: throw NotFoundException("Citizen not found ${it.citizen.id}")
|
||||||
ac.assert { canView(citizen, citizenOrNull) }
|
ac.assert { canView(citizen, citizenOrNull) }
|
||||||
|
|
||||||
call.respond(it.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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -389,32 +389,7 @@ paths:
|
|||||||
result:
|
result:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: object
|
$ref: '#/components/schemas/CitizenListResponse'
|
||||||
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:
|
401:
|
||||||
$ref: '#/components/responses/401'
|
$ref: '#/components/responses/401'
|
||||||
|
|
||||||
@@ -432,52 +407,29 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: object
|
$ref: '#/components/schemas/CitizenResponse'
|
||||||
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
|
|
||||||
|
|
||||||
|
/citizens/{citizen}:
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/citizen'
|
||||||
|
get:
|
||||||
|
security:
|
||||||
|
- JWTAuth: []
|
||||||
|
summary: Get Citizen
|
||||||
|
tags:
|
||||||
|
- citizen
|
||||||
|
operationId: getCitizen
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: The Citizen object
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/CitizenResponse'
|
||||||
|
404:
|
||||||
|
description: Citizen not found
|
||||||
|
401:
|
||||||
|
$ref: '#/components/responses/401'
|
||||||
components:
|
components:
|
||||||
parameters:
|
parameters:
|
||||||
page:
|
page:
|
||||||
@@ -560,6 +512,16 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
|
|
||||||
|
citizen:
|
||||||
|
name: citizen
|
||||||
|
in: path
|
||||||
|
description: ID of citizen
|
||||||
|
example: 6434f4f9-f570-f22a-c134-8668350651ff
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
|
||||||
responses:
|
responses:
|
||||||
401:
|
401:
|
||||||
description: Unautorized
|
description: Unautorized
|
||||||
@@ -723,6 +685,81 @@ components:
|
|||||||
score:
|
score:
|
||||||
type: integer
|
type: integer
|
||||||
|
|
||||||
|
CitizenListResponse:
|
||||||
|
additionalProperties: false
|
||||||
|
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
|
||||||
|
CitizenResponse:
|
||||||
|
additionalProperties: false
|
||||||
|
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
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
JWTAuth:
|
JWTAuth:
|
||||||
type: http
|
type: http
|
||||||
|
|||||||
Reference in New Issue
Block a user