http codes (#9)

This commit is contained in:
Ryan Brink
2021-04-14 07:51:09 -04:00
committed by GitHub
parent 1839d0e36f
commit c9de96cf86
6 changed files with 96 additions and 8 deletions

View File

@ -1,3 +1,9 @@
## [0.0.5] - April 15th, 2021
### Added
- Full list of compile-time-constant status codes
## [0.0.4] - April 14th, 2021
### Changed

View File

@ -63,7 +63,7 @@ data class ExampleParams(val a: String, val aa: Int)
data class ExampleNested(val nesty: String)
@KompendiumResponse(status = 204, "Entity was deleted successfully")
@KompendiumResponse(status = KompendiumHttpCodes.NO_CONTENT, "Entity was deleted successfully")
object DeleteResponse
@KompendiumRequest("Example Request")
@ -74,10 +74,10 @@ data class ExampleRequest(
val aaa: List<Long>
)
@KompendiumResponse(200, "A Successful Endeavor")
@KompendiumResponse(KompendiumHttpCodes.OK, "A Successful Endeavor")
data class ExampleResponse(val c: String)
@KompendiumResponse(201, "Created Successfully")
@KompendiumResponse(KompendiumHttpCodes.CREATED, "Created Successfully")
data class ExampleCreatedResponse(val id: Int, val c: String)
object KompendiumTOC {

View File

@ -1,5 +1,5 @@
# Kompendium
project.version=0.0.4
project.version=0.0.5
# Kotlin
kotlin.code.style=official
# Gradle

View File

@ -0,0 +1,81 @@
package org.leafygreens.kompendium.util
// Take from https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
object KompendiumHttpCodes {
// Informational responses
const val CONTINUE = 100
const val SWITCHING_PROTOCOL = 101
const val PROCESSING = 102
const val EARLY_HINTS = 103
// Successful responses
const val OK = 200
const val CREATED = 201
const val ACCEPTED = 202
const val NON_AUTHORITATIVE_INFORMATION = 203
const val NO_CONTENT = 204
const val RESET_CONTENT = 205
const val PARTIAL_CONTENT = 206
const val MULTI_STATUS = 207
const val ALREADY_REPORTED = 208
const val IM_USED = 226
// Redirection messages
const val MULTIPLE_CHOICE = 300
const val MOVED_PERMANENTLY = 301
const val FOUND = 302
const val SEE_OTHER = 303
const val NOT_MODIFIED = 304
@Deprecated("Deprecated due to security concerns regarding in-band configuration of a proxy")
const val USE_PROXY = 305
@Deprecated("This response code is no longer used; it is just reserved.")
const val UNUSED = 306
const val TEMPORARY_REDIRECT = 307
const val PERMANENT_REDIRECT = 308
// Client Response Errors
const val BAD_REQUEST = 400
const val UNAUTHORIZED = 401
const val PAYMENT_REQUIRED = 402
const val FORBIDDEN = 403
const val NOT_FOUND = 404
const val METHOD_NOT_ALLOWED = 405
const val NOT_ACCEPTABLE = 406
const val PROXY_AUTHENTICATION_REQUIRED = 407
const val REQUEST_TIMEOUT = 408
const val CONFLICT = 409
const val GONE = 410
const val LENGTH_REQUIRED = 411
const val PRECONDITION_FAILED = 412
const val PAYLOAD_TOO_LARGE = 413
const val URI_TOO_LONG = 414
const val UNSUPPORTED_MEDIA_TYPE = 415
const val RANGE_NOT_SATISFIABLE = 416
const val EXPECTATION_FAILED = 417
const val IM_A_TEAPOT = 418
const val MISDIRECTED_REQUEST = 421
const val UNPROCESSABLE_ENTITY = 422
const val LOCKED = 423
const val FAILED_DEPENDENCY = 424
const val TOO_EARLY = 425
const val UPGRADE_REQUIRED = 426
const val PRECONDITION_REQUIRED = 428
const val TOO_MANY_REQUESTS = 429
const val REQUEST_HEADER_FIELDS_TOO_LARGE = 431
const val UNAVAILABLE_FOR_LEGAL_REASONS = 451
// Server Error Responses
const val INTERNAL_SERVER_ERROR = 500
const val NOT_IMPLEMENTED = 501
const val BAD_GATEWAY = 502
const val SERVICE_UNAVAILABLE = 503
const val GATEWAY_TIMEOUT = 504
const val HTTP_VERSION_NOT_SUPPORTED = 505
const val VARIANT_ALSO_NEGOTIATES = 506
const val INSUFFICIENT_STORAGE = 507
const val LOOP_DETECTED = 508
const val NOT_EXTENDED = 510
const val NETWORK_AUTHENTICATION_REQUIRED = 511
}

View File

@ -16,11 +16,11 @@ data class TestRequest(
val aaa: List<Long>
)
@KompendiumResponse(200, "A Successful Endeavor")
@KompendiumResponse(KompendiumHttpCodes.OK, "A Successful Endeavor")
data class TestResponse(val c: String)
@KompendiumResponse(201, "Created Successfully")
@KompendiumResponse(KompendiumHttpCodes.CREATED, "Created Successfully")
data class TestCreatedResponse(val id: Int, val c: String)
@KompendiumResponse(status = 204, "Entity was deleted successfully")
@KompendiumResponse(KompendiumHttpCodes.NO_CONTENT, "Entity was deleted successfully")
object TestDeleteResponse

View File

@ -32,6 +32,7 @@ import org.leafygreens.kompendium.playground.KompendiumTOC.testSingleDeleteInfo
import org.leafygreens.kompendium.playground.KompendiumTOC.testSingleGetInfo
import org.leafygreens.kompendium.playground.KompendiumTOC.testSinglePostInfo
import org.leafygreens.kompendium.playground.KompendiumTOC.testSinglePutInfo
import org.leafygreens.kompendium.util.KompendiumHttpCodes
fun main() {
embeddedServer(
@ -45,7 +46,7 @@ data class ExampleParams(val a: String, val aa: Int)
data class ExampleNested(val nesty: String)
@KompendiumResponse(status = 204, "Entity was deleted successfully")
@KompendiumResponse(KompendiumHttpCodes.NO_CONTENT, "Entity was deleted successfully")
object DeleteResponse
@KompendiumRequest("Example Request")