This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.swagger.v3.oas.annotations.OpenAPIDefinition | |
| import io.swagger.v3.oas.annotations.Operation | |
| import io.swagger.v3.oas.annotations.Parameter | |
| import io.swagger.v3.oas.annotations.enums.ParameterIn | |
| import io.swagger.v3.oas.annotations.info.Info | |
| import io.swagger.v3.oas.annotations.media.Content | |
| import io.swagger.v3.oas.annotations.media.Schema | |
| import io.swagger.v3.oas.annotations.parameters.RequestBody | |
| import io.swagger.v3.oas.annotations.responses.ApiResponse | |
| import javax.ws.rs.GET |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // build.gradle | |
| resolve { | |
| outputFileName = 'swagger' | |
| outputFormat = 'JSON' // or YAML | |
| prettyPrint = 'TRUE' | |
| classpath = sourceSets.main.runtimeClasspath | |
| resourcePackages = ['com.banana'] // packages with service definitions | |
| outputDir = file('open-api') | |
| readAllResources = true | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # install generator | |
| brew install swagger-codegen | |
| # generate a java client | |
| swagger-codegen generate -i bananas-service/open-api/swagger.json -l java -o java-client-generated | |
| # this will create a Gradle library project with the client code of the above API | |
| # it allows async/blocking calls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl 'http://generator3.swagger.io/api/generate' -H 'Accept: application/json' --compressed -H 'Content-Type: application/json' --data-raw '{"spec":{"openapi":"3.0.1","info":{"title":"OpenAPIDefinition annotation is required only once in a project","description":"\n### markdown is supported</br>\n---","version":"1"},"paths":{"/bananas/{id}":{"get":{"tags":["bananas"],"summary":"get a banana","description":"### markdown is supported</br>","operationId":"getBanana","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Banana"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}}}}},"/bananas":{"post":{"tags":["bananas"],"summary":"create a banana","operationId":"createBanana","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateBanana"}}}},"responses":{"204":{"descrip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test fun `blocking example` () { | |
| vertx = Vertx.vertx() | |
| runBlocking { | |
| vertx.deployVerticleAwait(MainVerticle()) | |
| } | |
| apiInstace = BananasApi(ApiClient() | |
| .setBasePath("http://localhost:8080/") | |
| ) | |
| val actual = apiInstace.createBanana(CreateBanana().color("GREEN").price(2.0)) | |
| assertEquals(Banana().color(Banana.ColorEnum.GREEN).price(2.0).id("iddqd"),actual, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun createBanana( | |
| @RequestBody(content = [Content(mediaType = "application/json")]) | |
| banana: CreateBanana) = suspend { | |
| Banana(Color.valueOf(banana.color), banana.price, "iddqd").also { | |
| println("banana created: $it") | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.company.core.logging | |
| import org.apache.logging.log4j.core.LogEvent | |
| import org.apache.logging.log4j.core.config.plugins.Plugin | |
| import org.apache.logging.log4j.core.lookup.StrLookup | |
| import java.time.Instant | |
| @Plugin(name = "uptime", category = StrLookup.CATEGORY) | |
| class UptimeLoockup : StrLookup { | |
| companion object { | |
| var startTime: Instant = Instant.now() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Configuration: | |
| name: Default | |
| packages: "com.company.core.logging" | |
| Appenders: | |
| Console: | |
| - name: json | |
| target: SYSTEM_OUT | |
| JsonLayout: | |
| compact: true | |
| complete: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| JsonLayout: | |
| ... | |
| keyValuePair: | |
| - key: uptime | |
| value: '$${uptime:seconds}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # the service | |
| package main | |
| import ( | |
| "database/sql" | |
| "fmt" | |
| "github.com/gin-gonic/gin" | |
| _ "github.com/go-sql-driver/mysql" | |
| "net/http" | |
| ) |