@file:OptIn(ExperimentalSerializationApi::class)packageio.github.smiley4.ktoropenapi.examplesimportio.github.smiley4.ktoropenapi.OpenApiimportio.github.smiley4.ktoropenapi.config.ExampleEncoderimportio.github.smiley4.ktoropenapi.config.SchemaGeneratorimportio.github.smiley4.ktoropenapi.getimportio.github.smiley4.ktoropenapi.openApiimportio.github.smiley4.ktorredoc.redocimportio.github.smiley4.ktorswaggerui.swaggerUIimportio.ktor.http.HttpStatusCodeimportio.ktor.server.application.Applicationimportio.ktor.server.application.installimportio.ktor.server.engine.embeddedServerimportio.ktor.server.netty.Nettyimportio.ktor.server.response.respondTextimportio.ktor.server.routing.routeimportio.ktor.server.routing.routingimportkotlinx.serialization.ExperimentalSerializationApiimportkotlinx.serialization.Serializableimportkotlinx.serialization.json.Jsonimportkotlinx.serialization.json.JsonNamingStrategyfunmain(){embeddedServer(Netty,port=8080,host="localhost",module=Application::myModule).start(wait=true)}privatefunApplication.myModule(){valjson=Json{prettyPrint=trueencodeDefaults=trueexplicitNulls=falsenamingStrategy=JsonNamingStrategy.SnakeCase}install(OpenApi){schemas{// configure the schema generator to use the default kotlinx-serializergenerator=SchemaGenerator.kotlinx(json)}examples{// configure the example encoder to encode kotlin objects using kotlinx-serializerexampleEncoder=ExampleEncoder.kotlinx(json)}}routing{// add the routes for the OpenAPI spec, Swagger UI and ReDocroute("swagger"){swaggerUI("/api.json")}route("api.json"){openApi()}route("redoc"){redoc("/api.json")}// a documented routeget("hello",{description="A Hello-World route"request{queryParameter<String>("name"){description="the name to greet"example("Name Parameter"){value="Mr. Example"}}}response{code(HttpStatusCode.OK){description="successful request - always returns 'Hello World!'"body<TestResponse>{example("Success Response"){value=TestResponse(name="Mr. Example",length=11)}}}}}){call.respondText("Hello ${call.request.queryParameters["name"]}")}}}@SerializabledataclassTestResponse(valname:String,vallength:Int,)