Giter Site home page Giter Site logo

ktor-swagger's Introduction

Build Status

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.

When using this with Jackson

By default, Jackson includes fields with null values in the JSON output that it generates. This results in swagger.json and openapi.json files that cannot be processed by Swagger UI properly, leading to error messages while parsing the type and format info of parameters. To prevent this, install Jackson content negotiation as follows:

install(ContentNegotiation) {
    jackson {
        setSerializationInclusion(JsonInclude.Include.NON_NULL)
        // (You can add additional Jackson config stuff here, such as registerModules(JavaTimeModule()), etc.)
    }
}

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.

This project is looking for maintainers. Please open an issue if you're interested in taking over maintaining this project.

Other Similar Projects

Ktor-OpenAPI-Generator

ktor-swagger's People

Contributors

catincosmicspace avatar dbrewster avatar jeff-ruhl avatar jiaoling avatar jlleitschuh avatar klinefk1 avatar nielsfalk avatar nilsmagnus avatar volkert-fastned avatar wicpar avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.