From dea09af46b470ca45cc6dfc857a04ddbdb7db4b4 Mon Sep 17 00:00:00 2001 From: Tristan Leo Date: Mon, 24 Apr 2023 18:46:42 +0200 Subject: [PATCH] cleanup readme --- README.md | 203 ------------------------------------------------------ 1 file changed, 203 deletions(-) diff --git a/README.md b/README.md index 7d47fc3..ec58bf7 100644 --- a/README.md +++ b/README.md @@ -28,209 +28,6 @@ compile "cc.vileda:kotlin-openapi3-dsl:1.2.0" for a complete example [look at the test](src/test/kotlin/cc/vileda/openapi/dsl/OpenApiDslTest.kt) - -### complete vertx.io example - -```kotlin - -import cc.vileda.openapi.dsl.* -import io.swagger.oas.models.parameters.Parameter -import io.swagger.oas.models.security.SecurityScheme -import io.vertx.core.Handler -import io.vertx.core.json.JsonObject.mapFrom -import io.vertx.kotlin.core.http.HttpServerOptions -import io.vertx.reactivex.core.Vertx -import io.vertx.reactivex.ext.web.Router -import io.vertx.reactivex.ext.web.api.contract.openapi3.OpenAPI3RouterFactory -import io.vertx.reactivex.ext.web.handler.CorsHandler - -private val vertx = Vertx.vertx() - -data class HelloResponse( - val message: String -) - -data class HelloRequest( - val message: String -) - -private val api3 = openapiDsl { - info { - title = "test api" - version = "0.0.1" - } - - components { - schema() - schema() - securityScheme { - name = "apiKey" - type = SecurityScheme.Type.APIKEY - `in` = SecurityScheme.In.HEADER - } - } - - security { - put("apiKey", emptyList()) - } - - paths { - path("/hello") { - get { - tags = listOf("without params") - operationId = "hello" - description = "hello get" - parameter { - name = "id" - `in` = "query" - required = true - style = Parameter.StyleEnum.SIMPLE - schema() - } - responses { - response("200") { - description = "a 200 response" - content { - mediaTypeRef("application/json") { - description = "Hello response" - example = HelloResponse("World") - } - } - } - } - } - post { - tags = listOf("without params") - operationId = "postHello" - description = "hello post" - extension("x-stable", true) - responses { - response("201") { - description = "created response" - requestBody { - content { - mediaTypeRef("application/json") { - description = "Hello request" - example(HelloRequest("World")) { - description = "hello request" - } - } - } - } - content { - mediaType("application/json") { - description = "Hello response" - example = HelloResponse("World") - } - } - } - } - } - } - path("/greetings") { - get { - tags = listOf("without params") - operationId = "greetings" - description = "greetings get" - responses { - response("200"){ - description = "a 200 response" - content { - mediaTypeArrayOfRef("application/json") { - description = "An array of HelloResponses" - example = HelloResponse("Greetings") - } - } - } - } - } - } - } -} - -fun main(args: Array) { - val apiFile = api3.asFile() - println(api3.asJson().toString(2)) - OpenAPI3RouterFactory.rxCreateRouterFactoryFromFile(vertx, apiFile.absolutePath) - .doOnError { it.printStackTrace() } - .doOnSuccess(::createOperationHandlers) - .doOnSubscribe { println("Server started") } - .subscribe(::startServer) -} - -fun startServer(routerFactory: OpenAPI3RouterFactory) { - val mainRouter = Router.router(vertx) - bindAdditionalHandlers(mainRouter) - mainRouter.mountSubRouter("/", routerFactory.router) - val server = vertx.createHttpServer(HttpServerOptions( - port = 8080, - host = "localhost")) - server.requestHandler({ mainRouter.accept(it) }).listen(8080) -} - -fun bindAdditionalHandlers(router: Router) { - val create = CorsHandler.create("^.*$") - .allowedHeaders(setOf( - "Content-Type", - "apiKey" - )) - router.route().handler(create) - - router.get("/spec.json").handler { routingContext -> - routingContext.response() - .putHeader("Content-Type", "application/json") - .end(api3.asJson().toString(2)) - } -} - -private fun createOperationHandlers(routerFactory: OpenAPI3RouterFactory) { - routerFactory.addSecurityHandler("apiKey", Handler { - if (it.request().getHeader("apiKey") == "foo") it.next() - else it.fail(401) - }) - - routerFactory.addHandlerByOperationId("postHello", { routingContext -> - routingContext.response() - .putHeader("Content-Type", "application/json") - .end(mapFrom(HelloResponse("Hello World!")).encode()) - }) - - routerFactory.addHandlerByOperationId("hello", { routingContext -> - routingContext.response() - .putHeader("Content-Type", "application/json") - .end(mapFrom(HelloResponse("Hello World!")).encode()) - }) - - routerFactory.addFailureHandlerByOperationId("hello", { routingContext -> - println("FAIL") - routingContext.fail(500) - }) -} -``` - -## todo - -- [x] Make compatible to vertx [OpenAPI3RouterFactory](src/main/kotlin/OpenApi3Vertx.kt) -- [ ] Implement all OpenApi3 fields - - [ ] paths - - [x] all HTTP methods - - [x] minimal features - - [x] security features - - [ ] complete features - - [ ] requestBody - - [x] minimal features - - [ ] examples - - [ ] complete features - - [ ] parameters - - [x] minimal features - - [ ] complete features - - [x] components - - [x] $ref to components -- [x] Publish on bintray -- [x] Publish on jcenter -- [x] Publish on maven central - - ## license ``` Copyright 2017 Tristan Leo