Created
January 9, 2020 16:24
-
-
Save adamw/cc8584c72d0dab89b3a9aa3ae4029414 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
package sttp.tapir.example | |
import io.circe.generic.JsonCodec | |
import sttp.tapir._ | |
import sttp.model.StatusCode | |
import sttp.tapir.docs.openapi._ | |
import sttp.tapir.openapi.circe.yaml._ | |
import sttp.tapir.json.circe._ | |
object Example extends App { | |
@JsonCodec | |
case class Book(author: String, title: String, year: Int) | |
val bookExample = Book("Pedro Muñoz Seca", "La venganza de Don Mendo", 1918) | |
val API_TEXT = "api" | |
val API_VERSION = "v1.0" | |
val baseEndpointInput: EndpointInput[Unit] = API_TEXT / API_VERSION | |
lazy val bookEndpoint: Endpoint[Unit, StatusCode, Book, Nothing] = | |
endpoint.get | |
.in(baseEndpointInput / "books") | |
.name("book-resource") | |
.description("Poc Endpoint for learning and testing - book") | |
.out(jsonBody[Book].example(bookExample)) | |
.errorOut(statusCode) | |
// interpreting the endpoint description to generate yaml openapi documentation | |
val docs = List(bookEndpoint).toOpenAPI("The Tapir Library", "1.0") | |
docs.toYaml | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment