<commit_before>
import io.vertx.core.Vertx
import io.vertx.ext.web.api.contract.openapi3.OpenAPI3RouterFactory
import io.vertx.kotlin.core.http.HttpServerOptions

fun main(args: Array<String>) {
    val api3 = openapi3 {
        info {
            title = "test api"
            version = "0.0.1"
        }

        paths {
            get("/hello") {
                operationId = "hello"
                code("200") {
                    response<String>("text/plain")
                }
            }
        }
    }

    println(api3.asJson().toString(2))

    val vertx = Vertx.vertx()

    val apiFile = api3.asFile()
    println(apiFile.absolutePath)

    OpenAPI3RouterFactory.createRouterFactoryFromFile(vertx, apiFile.absolutePath, { ar ->
        if (ar.succeeded()) {
            // Spec loaded with success
            val routerFactory = ar.result()
            val router = routerFactory.router

            routerFactory.addHandlerByOperationId("hello", { routingContext ->
                routingContext.response().end("Hello World!")
            })

            routerFactory.addFailureHandlerByOperationId("hello", { routingContext ->
                println("FAIL")
                routingContext.fail(500)
            })

            val server = vertx.createHttpServer(HttpServerOptions(
                    port = 8080,
                    host = "localhost"))
            server.requestHandler({ router.accept(it) }).listen(8080)
        }
        else {
            ar.cause()
        }
    })
}<commit_msg>create router after attaching handlers<commit_after>
import io.vertx.core.Vertx
import io.vertx.ext.web.api.contract.openapi3.OpenAPI3RouterFactory
import io.vertx.kotlin.core.http.HttpServerOptions

fun main(args: Array<String>) {
    val api3 = openapi3 {
        info {
            title = "test api"
            version = "0.0.1"
        }

        paths {
            get("/hello") {
                operationId = "hello"
                code("200") {
                    response<String>("text/plain")
                }
            }
        }
    }

    println(api3.asJson().toString(2))

    val apiFile = api3.asFile()
    println(apiFile.absolutePath)

    val vertx = Vertx.vertx()

    OpenAPI3RouterFactory.createRouterFactoryFromFile(vertx, apiFile.absolutePath, { ar ->
        if (ar.succeeded()) {
            // Spec loaded with success
            val routerFactory = ar.result()

            routerFactory.addHandlerByOperationId("hello", { routingContext ->
                routingContext.response().end("Hello World!")
            })

            routerFactory.addFailureHandlerByOperationId("hello", { routingContext ->
                println("FAIL")
                routingContext.fail(500)
            })

            val server = vertx.createHttpServer(HttpServerOptions(
                    port = 8080,
                    host = "localhost"))
            val router = routerFactory.router
            server.requestHandler({ router.accept(it) }).listen(8080)
        }
        else {
            ar.cause().printStackTrace()
        }
    })
}
{'fraction_non_alphanumeric': 0.11046698872785829, 'fraction_numerical': 0.01610305958132045, 'mean_word_length': 1.6775862068965517, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4018929', 'n_tokens_mistral': 893, 'n_tokens_neox': 819, 'n_words': 140}