Skip to content

Instantly share code, notes, and snippets.

@sargunv
Last active May 28, 2016 01:37
Show Gist options
  • Save sargunv/67551290db77e0980fecc42dd6dc55ca to your computer and use it in GitHub Desktop.
Save sargunv/67551290db77e0980fecc42dd6dc55ca to your computer and use it in GitHub Desktop.
val spec = ApiSpec {
title = "Sample API"
description = "Sample API description"
basePath = "/v1"
contentTypes = mapOf(
"application/json" to JsonSerializer(),
"application/x-yaml" to YamlSerializer()
)
errorModel = Error::class
resource("/person") {
get {
description = "Get a list of persons"
longDescription = "Returns a paginated list of all person ids in the system"
queryParam("offset") {
model = Int::class
description = "index of the first item of the page"
}
queryParam("limit") {
model = Int::class
description = "number of items on the page"
}
responseModel = Page::class
successCode = 200
errorCodes = listOf(400)
handler = System::getPersons
}
post {
description = "Create a person"
longDescription = "Creates a new Person object and returns the created object"
bodyParam{
model = Person::class
description = "the person object to add to the system"
}
responseModel = Person::class
successCode = 201
errorCodes = listOf(400)
handler = System::createPerson
}
}
resource("/person/{id}") {
get {
description = "Get a person"
longDescription = "Returns a single Person object from the system"
pathParam("id") {
model = UUID::class
description = "the id of the target user"
}
responseModel = Person::class
successCode = 200
errorCodes = listOf(400, 404)
handler = Backend::getPerson
}
delete {
description = "Delete a person"
longDescription = "Removes a single Person object from the system"
pathParam("id") {
model = UUID::class
description = "the id of the target user"
}
successCode = 204
errorCodes = listOf(400, 404)
handler = Backend::deletePerson
}
}
}
data class Page {
val offset: Int,
val count: Int,
val total: Int,
val list: List<UUID>
}
data class Person(
val id: UUID,
val dateModified: Date,
val name: String,
val height: Double,
val jobTitle: String?,
val cars: List<Car>
)
data class Car(
val make: String,
val model: String
)
data class Error(
val message: String
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment