🐨 koa - Kotlin and Ktor OpenAPI

Overview

koa - Kotlin and Ktor OpenAPI

Koa intends to be a fully functional DSL for OpenAPI in Kotlin, including a Ktor plugin to add OpenAPI to your server Kotlin applications.

install(Koa) {
    title = "Koa example"
    description = "Ktor + OpenAPI (+ Swagger UI) = Koa!"
    version = "1.2.3"
}

install(KoaSwaggerUi) // Optional, you can remove it if you only want to serve the OpenAPI document

routing {
    get("/hello/there") {
        // do some complicated stuff...
    } describe {
        summary = "I am an endpoint!"
        description = "This is my endpoint. It's pretty nice, isn't it?"
        200 response "application/json" {
            description = "This is a successful response."
            schema(SomeObject(someParam = "some string"))
        }
    }
    
    // An endpoint to retrieve our OpenAPI document...
    get("/openapi") {
        call.respondOpenApiDocument()
    }
    
    // ... and an endpoint to serve Swagger UI. 
    // first parameter = path from which to serve
    // second parameter = path or URI from which OpenAPI document will be loaded
    swaggerUi("/swagger", "/openapi")
}

Experimental and very much a work in progress! Use at your own risk.

I do not currently have time to write full documentation for this, have a look at the sample (samples/ktor) for details, sorry :(

Usage

You can add the libraries via JitPack.

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'guru.zoroark:koa:main-SNAPSHOT'
    implementation 'guru.zoroark:koa-ktor:main-SNAPSHOT'
    implementation 'guru.zoroark:koa-ktor-ui:main-SNAPSHOT'
}

The following modules are present:

  • koa-dsl, the DSL components of Koa without any dependencies other than Swagger Core
  • koa-ktor, the Ktor feature which adds the ability to document endpoitns and serve OpenAPI documents
  • koa-ktor-ui, utility feature for Ktor that allows you to serve Swagger UI easily. Does not actually depend on koa-ktor, you can also use it as-is as long as an OpenAPI document is served from somewhere.
  • samples, sample applications
    • samples:ktor a more complete example of how you can use the koa-ktor feature.
You might also like...
Kotlin backend based on the Clean Architecture principles. Ktor, JWT, Exposed, Flyway, KGraphQL/GraphQL generated endpoints, Gradle.
Kotlin backend based on the Clean Architecture principles. Ktor, JWT, Exposed, Flyway, KGraphQL/GraphQL generated endpoints, Gradle.

Kotlin Clean Architecture Backend Kotlin backend based on the Clean Architecture principles. The application is separated into three modules: Domain,

Provides Ktor Server libs for building awesome Kotlin plugins which needs to provide builtin HTTP servers
Provides Ktor Server libs for building awesome Kotlin plugins which needs to provide builtin HTTP servers

Ktor Plugin Provides Ktor Server libs for building awesome Kotlin plugins which needs to provide builtin HTTP servers. Requires: https://github.com/Po

Api Rest Card Game made in Kotlin with Ktor

ApiRest-CardGame "Card Game API" is a project made in Kotlin with Ktor. The API allows you to manage a simple card game deck (shuffle, take a card, pu

Kotlin Ktor REST Service
Kotlin Ktor REST Service

Servicio web para crear una API REST usando Kotlin y Kator así como otras tecnologías propuestas por JetBrains.

A small backend for the Thinkrchive app written in Kotlin with Ktor

A small backend for the Thinkrchive app written in Kotlin with Ktor. It uses Postgresql with a few requests and JWT authentication for admins.

Ktor is an asynchronous framework for creating microservices, web applications and more.
Ktor is an asynchronous framework for creating microservices, web applications and more.

ktor-sample Ktor is an asynchronous framework for creating microservices, web applications and more. Written in Kotlin from the ground up. Application

Microservices with Ktor and Nomad

Microserviços com Ktor e Nomad Esse projeto é um teste prático de microserviços usando o framework Ktor, o banco de dados Postgres, o orquestrador de

🪟 Pluggable Ktor plugin to implement Sentry for error handling and request contexts

🪟 Ktor Plugin for Sentry Pluggable Ktor plugin to implement Sentry for error handling and request contexts. What is this library? This basically impl

Various Ktor extensions and plugins.

Ktor Plugins Collection of useful Ktor plugins. All plugins are hosted on Maven central and have same version that should be similar to the latest ver

Comments
  • Add an easy way to describe something on multiple routes

    Add an easy way to describe something on multiple routes

    For example, say we have endpoints that can all return some kind of error that needs to be documented on all of them. Provide a way to do something like this:

    withDescription({
        418 response "application/json" {
           // ...
        }
    }) {
        get("hello") {
            // ...
        } describe {
            // the response is automatically added here
        }
    }
    
    opened by utybo 1
  • update dependencies, migrate to Ktor 2

    update dependencies, migrate to Ktor 2

    I have updated the dependencies and "migrated" everything to Ktor 2.

    I just cant seem to get the swagger UI running Opening /swagger just displays an empty page.

    opened by ALP011216 0
  • Migration to Tegral

    Migration to Tegral

    Hi there!

    TL;DR: Koa has been superseded by Tegral OpenAPI, which you can check out here

    Thanks for your interest in Koa! Koa has been improved (including rewrites in a few places), properly documented and moved to the Tegral project. Please check it out here!

    Advantages of Tegral OpenAPI over Koa include:

    • More reliable class --> schema transformation (List<Something> now works properly)
    • Actual releases to Maven Central
    • A more complete DSL (still not fully complete but we're getting there)
    • More tooling: the DSL can now be used fully standalone, including as a separate file *.openapi.kts, which can then be turned to a regular OpenAPI JSON or YAML file using the new CLI.
    • Proper documentation. If you want to check out more, see here for the Tegral 0.0.2 release announcement, which includes details about Tegral OpenAPI.

    In short, it's everything you know and love about Koa, but even better!

    As a result, the Koa repository has been archived, as further development will only happen on the Tegral repository


    Original message

    Just a heads up for people interested in this project: I'll soon be migrating it under the Tegral repository, with proper integration into Tegral. This means that:

    • This project will receive appropriate documentation support, both in the form of KDoc and regular documentation
    • This project will be synced with the rest of Tegral libraries.

    Note that you will not have to use everything from Tegral to use the OpenAPI capabilities. Just like the current Koa feature/plugin (and just like everything in Tegral), you'll be able to just add it like any other Ktor feature/plugin without anything else from the Tegral ecosystem.

    opened by utybo 0
  • Workaround for /swagger not working

    Workaround for /swagger not working

    Because Swagger UI uses relative links to resolve resources (like CSS, JS and images), going to /swagger will serve the correct index.html file, but the browser will call the wrong URLs when trying to resolve resources. A simple workaround is to trigger a 307 redirection from /swagger to /swagger/index.html if possible.

    There is a potential trap here because I don't think Ktor has an easy way of specifying "redirect to this subroute", and we can only set a redirection to an absolute path.

    opened by utybo 0
Owner
Zoroark
EPITA student (4th yr, ING2), teaching assistant and developer @EPITA. @EpiLink dev. Make things simple or else bonk.
Zoroark
A clean OpenAPI client generator for Kotlin multiplatform

kotlin-openapi-generator A not yet feature complete client generator. Features: generates 100% Kotlin multiplatform code does not generate any useless

Jakob K 5 Jun 6, 2022
HQ OpenAPI Specification and Client & Server SDK Generators

HQ-API HQ OpenAPI Specification and Client & Server SDK Generators Cloning Github Repository Get access to Flocktory team in Github Adding a new SSH k

Flocktory Spain, S.L. 1 Sep 2, 2022
Integration Testing Kotlin Multiplatform Kata for Kotlin Developers. The main goal is to practice integration testing using Ktor and Ktor Client Mock

This kata is a Kotlin multiplatform version of the kata KataTODOApiClientKotlin of Karumi. We are here to practice integration testing using HTTP stub

Jorge Sánchez Fernández 29 Oct 3, 2022
KTor-Client---Android - The essence of KTor Client for network calls

KTor Client - Android This project encompasses the essence of KTor Client for ne

Mansoor Nisar 2 Jan 18, 2022
SSU u-saint parser with Kotlin-Multiplatform and Ktor.

kusaint Soongsil University(SSU) u-Saint Parser with Kotlin Multiplatform. Prerequisites JVM !!IMPORTANT!! To run kusaint as a library in JVM environm

Hyomin Koo 3 Mar 23, 2022
A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations.

kotlin-ktor-rest-api A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations. F

Selim Atasoy 32 Dec 20, 2022
Backend coding challenge using Kotlin and Ktor

Backend Coding Challenge We appreciate you taking the time to participate and su

Thermondo 0 Jan 4, 2022
Shoppe - Kotlin and Ktor app, which can easily be deployed to Heroku

[ ?? Work in progress ??‍♀️ ⛏ ?? ??️ ?? ?? ?? ] Shoppe Kotlin Multiplatform App

Adrian Witaszak 33 Jul 12, 2022
Architecture With Kotlin-Ktor and SvelteJS

Architecture With Kotlin-Ktor and SvelteJS Features Showing data frrom open API on US Population Showing Auto Generated QR code Why Ktor - Create asyn

Bidit Pakrashi 2 Jun 8, 2022
A simple (and naive) RESTful API made with Ktor, jasync-sql and JWT.

A simple (and naive) RESTful API made with Ktor, jasync-sql and JWT. Route Method Description /account POST Create a new account /account DELETE Delet

null 2 Nov 4, 2021