Created
April 25, 2020 18:55
-
-
Save viggin543/2dcdec08ec05e72bced326bed891eb60 to your computer and use it in GitHub Desktop.
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 | |
| import javax.ws.rs.POST | |
| import javax.ws.rs.Path | |
| @OpenAPIDefinition(info = Info( | |
| title = "OpenAPIDefinition annotation is required only once in a project", | |
| version = "1", | |
| description = """ | |
| ### markdown is supported</br> | |
| ---""")) | |
| @Path("/bananas") | |
| class BananaApi { | |
| @GET | |
| @Path("/{id}") | |
| @Operation( | |
| summary = "get a banana", | |
| description = """### markdown is supported</br>""", | |
| tags = ["bananas"], | |
| responses = [ | |
| ApiResponse(responseCode = "200", | |
| description = "OK", | |
| content = [Content(mediaType = "application/json", schema = Schema(implementation = Banana::class))]), | |
| ApiResponse(responseCode = "400", description = "Bad Request", | |
| content = [Content(mediaType = "application/json", schema = Schema(implementation = ApiError::class))]) | |
| ]) | |
| fun getBanana( | |
| @Parameter(name = "id", `in` = ParameterIn.PATH) | |
| id: String): Banana { | |
| return Banana(Color.GREEN, 0.5, id) | |
| } | |
| @POST | |
| @Path("/{id}") | |
| @Operation( | |
| summary = "create a banana", | |
| description = "", | |
| tags = ["bananas"], | |
| responses = [ | |
| ApiResponse(responseCode = "204", description = "OK"), | |
| ApiResponse(responseCode = "400", description = "Bad Request", | |
| content = [Content(mediaType = "application/json", schema = Schema(implementation = ApiError::class))]) | |
| ] | |
| ) | |
| fun createBanana( | |
| @RequestBody(content = [Content(mediaType = "application/json")]) | |
| banana: CreateBanana): Banana { | |
| return Banana(Color.GREEN, 0.5, "iddqd") | |
| } | |
| } | |
| enum class Color { | |
| GREEN, YELLOW, BROWN | |
| } | |
| data class Banana( | |
| val color: Color, | |
| @field:Schema(description = "price in USD", maximum = "256", example = "5") | |
| val price: Double, | |
| @field:Schema(description = "UUID", example = "29F44D73-B94A-4260-A73D-E6A94A766906") | |
| val id: String, | |
| @field:Schema(nullable = true) | |
| val nickname: String? = null) | |
| data class CreateBanana( | |
| val color: String, | |
| @field:Schema(description = "price in USD", maximum = "256", example = "5") | |
| val price: Double) | |
| data class ApiError(val error: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment