Skip to content

Commit

Permalink
an example for zio/zio-http#2836
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-chetvertkov committed May 9, 2024
1 parent d5c107a commit beb943c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/resources/petstore-minimal.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@
}
}
},
"404": {
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"default": {
"description": "unexpected error",
"content": {
Expand Down
7 changes: 5 additions & 2 deletions src/main/scala/openapi/generator/example/ServerExample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import base.Pets
import base.component.Pet
import zio.http.endpoint.Endpoint
import zio.http.endpoint.EndpointMiddleware.None
import zio.http.{Handler, Route, Server}
import zio.http.{Handler, Response, Route, Server, Status}
import zio.{Scope, ZIO, ZIOAppArgs, ZIOAppDefault, ZNothing}

object ServerExample extends ZIOAppDefault {

val endpoint: Endpoint[Unit, Pet, ZNothing, Unit, None] = Pets.createPets
val route: Route[Any, Nothing] = endpoint.implement(Handler.fromFunctionZIO(pet => {ZIO.logInfo("Pet: " + pet.toString)}))
val route: Route[Any, Nothing] = endpoint.implement(
Handler.fromFunctionZIO(pet => {ZIO.logInfo("Pet: " + pet.toString)})
.mapError(e => Response.text("Error: " + e.getMessage).status(Status.InternalServerError))
)

// create zio http app from the generated endpoint
val httpApp = route.toHttpApp
Expand Down

0 comments on commit beb943c

Please sign in to comment.