Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: doc string interpolation for Endpoint documentation #2440

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions zio-http/src/main/scala/zio/http/endpoint/Endpoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import zio.http.Header.Accept.MediaTypeWithQFactor
import zio.http._
import zio.http.codec.{HttpCodec, _}
import zio.http.endpoint.Endpoint.{OutErrors, defaultMediaTypes}
import zio.http.endpoint.Endpoint.{EndpointDocs,_}


/**
* An [[zio.http.endpoint.Endpoint]] represents an API endpoint for the HTTP
Expand Down
20 changes: 20 additions & 0 deletions zio-http/src/main/scala/zio/http/endpoint/EndpointDocs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// EndpointDocs.scala

object EndpointDocs {
implicit class EndpointDocs(val sc: StringContext) extends AnyVal {
def doc(args: Any*): String = {
// Access the parts of the interpolated string
val parts = sc.parts.iterator

// Combine the parts with the arguments to create the final documentation string
val result = new StringBuilder(parts.next())
while (parts.hasNext) {
val arg = args(parts.nextIndex - 1).toString
result.append(arg).append(parts.next())
}

// Return the documentation string
result.toString()
}
}
}