acterics / ktor-swagger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Download

This project provides a library that allows you you to integrate the swaggerUi with ktor

An example efrom the ktor-sample-swagger is deployed on heroku.

Example Usage

This library adds some extension function that build on the ktor routing feature to provide an API that allows this feature to automatically generate a swagger.json file for your webserver.

routing {
    get<pets>("all".responds(ok<PetsModel>())) {
        call.respond(data)
    }
    post<pets, PetModel>("create".responds(created<PetModel>())) { _, entity ->
        call.respond(Created, entity.copy(id = newId()).apply {
            data.pets.add(this)
        })
    }
    get<pet>("find".responds(ok<PetModel>(), notFound())) { params ->
        data.pets.find { it.id == params.id }
            ?.let {
                call.respond(it)
            }
    }
}

Project Status

This project is a proof of concept built on a library to support this functionality.

There is an open proposal to include this project as an official Ktor feature here.

About

License:Apache License 2.0


Languages

Language:Kotlin 100.0%