zio / zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers
https://zio.dev/zio-http
Apache License 2.0
787 stars 396 forks source link

OpenAPIGen fails on PathCodec.empty Root path #3110

Closed tmkontra closed 1 week ago

tmkontra commented 1 month ago

Describe the bug The root endpoint (PathCodec.empty) causes OpenAPIGen to throw an exception

To Reproduce

Source code:

object MyServer {
  import zio.http.codec.PathCodec._

  private val indexRoute =
    Endpoint(RoutePattern.GET / PathCodec.empty)
      .out[String]

  def routes: Routes[Env, Nothing] =
    Routes(
      indexRoute.implement(_ => ZIO.service[MyService].map(_.show()))
    )

  def endpoints = Seq(indexRoute)

  def openapi = OpenAPIGen.fromEndpoints(title="My API", version="0.1", endpoints)

  def apply() =
    routes ++ SwaggerUI.routes(PathCodec.empty / "docs", openapi)
}

Stack trace:

timestamp=2024-09-07T04:33:14.742410Z level=ERROR thread=#zio-fiber-1112602523 message="" cause="Exception in thread "zio-fiber-345660099" java.lang.Exception: Invalid path: 
    at zio.http.endpoint.openapi.OpenAPIGen$.buildPath$1$$anonfun$1(OpenAPIGen.scala:556)
    at scala.Option.getOrElse(Option.scala:201)
    at zio.http.endpoint.openapi.OpenAPIGen$.buildPath$1(OpenAPIGen.scala:556)
    at zio.http.endpoint.openapi.OpenAPIGen$.path$7(OpenAPIGen.scala:514)
    at zio.http.endpoint.openapi.OpenAPIGen$.gen(OpenAPIGen.scala:799)
    at zio.http.endpoint.openapi.OpenAPIGen$.fromEndpoints$$anonfun$3(OpenAPIGen.scala:485)
    at scala.collection.immutable.List.map(List.scala:246)
    at scala.collection.immutable.List.map(List.scala:79)
    at zio.http.endpoint.openapi.OpenAPIGen$.fromEndpoints(OpenAPIGen.scala:485)
    at zio.http.endpoint.openapi.OpenAPIGen$.fromEndpoints(OpenAPIGen.scala:491)
    at http.MilemarkerServer$.openapi(MilemarkerServer.scala:13)
    at http.MilemarkerServer$.apply(MilemarkerServer.scala:16)
    at run.Application$.run$$anonfun$1$$anonfun$1$$anonfun$3(Application.scala:33)
    at run.Application.run(Application.scala:32)
    at run.Application.run(Application.scala:35)"

Process finished with exit code 1

Expected behaviour OpenAPIGen succeeds

Desktop (please complete the following information):

jdegoes commented 4 weeks ago

/bounty $50 for fix and test

algora-pbc[bot] commented 4 weeks ago

πŸ’Ž $50 bounty β€’ ZIO

Steps to solve:

  1. Start working: Comment /attempt #3110 with your implementation plan
  2. Submit work: Create a pull request including /claim #3110 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bounty β€’ Share on socials

Attempt Started (GMT+0) Solution
πŸ”΄ @pawelsadlo Sep 10, 2024, 12:18:43 PM WIP
🟒 @987Nabil #3121
pawelsadlo commented 4 weeks ago

/attempt #3110

Algora profile Completed bounties Tech Active attempts Options
@pawelsadlo 1 ZIO bounty
Scala
Cancel attempt
algora-pbc[bot] commented 4 weeks ago

πŸ’‘ @987Nabil submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] commented 3 weeks ago

@pawelsadlo: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then πŸ™

algora-pbc[bot] commented 2 weeks ago

The bounty is up for grabs! Everyone is welcome to /attempt #3110 πŸ™Œ

algora-pbc[bot] commented 1 week ago

πŸŽ‰πŸŽˆ @987Nabil has been awarded $50! 🎈🎊