Test openapi schema of Register
Fix some routes Improve Schema Validation
This commit is contained in:
10
src/main/kotlin/fr/dcproject/common/BitMaskEnum.kt
Normal file
10
src/main/kotlin/fr/dcproject/common/BitMaskEnum.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package fr.dcproject.common
|
||||
|
||||
interface BitMaskI {
|
||||
val bit: Long
|
||||
|
||||
infix operator fun contains(which: BitMaskI): Boolean = bit and which.bit == which.bit
|
||||
infix operator fun plus(mask: BitMaskI): BitMaskI = BitMask(mask.bit and this.bit)
|
||||
}
|
||||
|
||||
class BitMask(override val bit: Long) : BitMaskI
|
||||
@@ -11,10 +11,12 @@ import fr.dcproject.component.citizen.database.CitizenI
|
||||
import fr.dcproject.component.citizen.database.CitizenRepository
|
||||
import io.ktor.application.call
|
||||
import io.ktor.features.BadRequestException
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.locations.Location
|
||||
import io.ktor.locations.post
|
||||
import io.ktor.request.accept
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.response.respondText
|
||||
import io.ktor.routing.Route
|
||||
@@ -61,8 +63,17 @@ object Register {
|
||||
post<RegisterRequest> {
|
||||
try {
|
||||
val citizen = call.receiveOrBadRequest<Input>().toCitizen()
|
||||
val createdCitizen = citizenRepo.insertWithUser(citizen)?.user ?: throw BadRequestException("Bad request")
|
||||
call.respondText(createdCitizen.makeToken())
|
||||
citizenRepo.insertWithUser(citizen)?.user?.makeToken()?.let { token ->
|
||||
if (call.request.accept() == ContentType.Application.Json.toString()) {
|
||||
call.respond(
|
||||
object {
|
||||
val token: String = token
|
||||
}
|
||||
)
|
||||
} else {
|
||||
call.respondText(token)
|
||||
}
|
||||
} ?: throw BadRequestException("Bad request")
|
||||
} catch (e: MissingKotlinParameterException) {
|
||||
call.respond(HttpStatusCode.BadRequest)
|
||||
}
|
||||
|
||||
@@ -256,6 +256,82 @@ paths:
|
||||
type: string
|
||||
example:
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBdXRoZW50aWNhdGlvbiIsImlzcyI6ImRjLXByb2plY3QuZnIiLCJpZCI6ImQ1NDRhNmE4LWJhYjgtNDU2MC05NWIxLThhZjAyMDNkOTEwNCIsImV4cCI6MTU2NzA3Mzc0Mn0.0VTetv8fZFjVgpJ-bwJpidGNHJUOmgj8vuZcZXzwnLa7TtFwcXWvh3bDPYHqB66nmOfXyM57XnHDbmRwtipCag'
|
||||
/register:
|
||||
post:
|
||||
summary: Create account
|
||||
tags:
|
||||
- authentification
|
||||
operationId: register
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required:
|
||||
- name
|
||||
- birthday
|
||||
- email
|
||||
- user
|
||||
properties:
|
||||
name:
|
||||
type: object
|
||||
required:
|
||||
- firstName
|
||||
- lastName
|
||||
properties:
|
||||
firstName:
|
||||
type: string
|
||||
example:
|
||||
john
|
||||
lastName:
|
||||
type: string
|
||||
example:
|
||||
Doe
|
||||
birthday:
|
||||
type: string
|
||||
format: 'date'
|
||||
example: '1984-12-25'
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
example: my.email@dc-project.fr
|
||||
user:
|
||||
type: object
|
||||
required:
|
||||
- username
|
||||
- password
|
||||
properties:
|
||||
username:
|
||||
type: string
|
||||
example:
|
||||
john-doe
|
||||
password:
|
||||
type: string
|
||||
example:
|
||||
azerty
|
||||
format: password
|
||||
|
||||
responses:
|
||||
200:
|
||||
description: User created and JWT returned
|
||||
content:
|
||||
text/plain:
|
||||
example:
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBdXRoZW50aWNhdGlvbiIsImlzcyI6ImRjLXByb2plY3QuZnIiLCJpZCI6ImQ1NDRhNmE4LWJhYjgtNDU2MC05NWIxLThhZjAyMDNkOTEwNCIsImV4cCI6MTU2NzA3Mzc0Mn0.0VTetv8fZFjVgpJ-bwJpidGNHJUOmgj8vuZcZXzwnLa7TtFwcXWvh3bDPYHqB66nmOfXyM57XnHDbmRwtipCag'
|
||||
application/json:
|
||||
schema:
|
||||
properties:
|
||||
token:
|
||||
type: string
|
||||
example:
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBdXRoZW50aWNhdGlvbiIsImlzcyI6ImRjLXByb2plY3QuZnIiLCJpZCI6ImQ1NDRhNmE4LWJhYjgtNDU2MC05NWIxLThhZjAyMDNkOTEwNCIsImV4cCI6MTU2NzA3Mzc0Mn0.0VTetv8fZFjVgpJ-bwJpidGNHJUOmgj8vuZcZXzwnLa7TtFwcXWvh3bDPYHqB66nmOfXyM57XnHDbmRwtipCag'
|
||||
400:
|
||||
description: Bad request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
description: sdf
|
||||
|
||||
components:
|
||||
parameters:
|
||||
page:
|
||||
|
||||
Reference in New Issue
Block a user