Skip to content

Commit

Permalink
Fix some Endpoint::doc field usages && Rename it to documentation
Browse files Browse the repository at this point in the history
… to avoid this kind of mistake in the future
  • Loading branch information
guizmaii committed Aug 22, 2024
1 parent 7cfb9fc commit 74aec00
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private[cli] object CliEndpoint {
endpoint: Endpoint[P, In, Err, Out, _],
getInput: Boolean = true,
): CliEndpoint =
if (getInput) fromCodec(endpoint.input) ?? endpoint.doc
else fromCodec(endpoint.output) ?? endpoint.doc
if (getInput) fromCodec(endpoint.input) ?? endpoint.documentation
else fromCodec(endpoint.output) ?? endpoint.documentation

def fromCodec[Input](input: HttpCodec[_, Input]): CliEndpoint = {
input match {
Expand Down
38 changes: 19 additions & 19 deletions zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output: HttpCodec[HttpCodecType.ResponseType, Output],
error: HttpCodec[HttpCodecType.ResponseType, Err],
codecError: HttpCodec[HttpCodecType.ResponseType, HttpCodecError],
doc: Doc,
documentation: Doc,
authType: Auth,
) { self =>

Expand All @@ -74,7 +74,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
* Returns a new API that is derived from this one, but which includes
* additional documentation that will be included in OpenAPI generation.
*/
def ??(that: Doc): Endpoint[PathInput, Input, Err, Output, Auth] = copy(doc = self.doc + that)
def ??(that: Doc): Endpoint[PathInput, Input, Err, Output, Auth] = copy(documentation = self.documentation + that)

/**
* Flattens out this endpoint to a chunk of alternatives. Each alternative is
Expand Down Expand Up @@ -454,7 +454,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output,
error,
codecError,
doc,
documentation,
authType,
)

Expand All @@ -471,7 +471,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output,
error,
codecError,
self.doc,
documentation,
authType,
)

Expand All @@ -488,7 +488,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output,
error,
codecError,
doc,
documentation,
authType,
)

Expand All @@ -505,7 +505,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output,
error,
codecError,
self.doc,
documentation,
authType,
)

Expand All @@ -522,7 +522,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = (HttpCodec.content[Output2] ++ StatusCodec.status(Status.Ok)) | self.output,
error,
codecError,
doc,
documentation,
authType,
)

Expand Down Expand Up @@ -557,7 +557,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = (HttpCodec.content[Output2] ++ StatusCodec.status(status)) | self.output,
error,
codecError,
doc,
documentation,
authType,
)

Expand All @@ -575,7 +575,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = ((HttpCodec.content[Output2] ++ StatusCodec.status(status)) ?? doc) | self.output,
error,
codecError,
Doc.empty,
documentation,
authType,
)

Expand All @@ -593,7 +593,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = (HttpCodec.content[Output2](mediaType) ++ StatusCodec.Ok ?? doc) | self.output,
error,
codecError,
doc,
documentation,
authType,
)

Expand All @@ -612,7 +612,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = ((HttpCodec.content[Output2](mediaType) ++ StatusCodec.status(status)) ?? doc) | self.output,
error,
codecError,
doc,
documentation,
authType,
)

Expand All @@ -630,7 +630,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = (HttpCodec.content[Output2](mediaType) ++ StatusCodec.status(status)) | self.output,
error,
codecError,
doc,
documentation,
authType,
)

Expand Down Expand Up @@ -695,7 +695,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = (contentCodec ++ StatusCodec.status(Status.Ok)) | self.output,
error,
codecError,
doc,
documentation,
authType,
)
}
Expand All @@ -719,7 +719,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = (contentCodec ++ StatusCodec.status(Status.Ok) ?? doc) | self.output,
error,
codecError,
self.doc,
documentation,
authType,
)
}
Expand All @@ -743,7 +743,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = (contentCodec ++ StatusCodec.status(status) ?? doc) | self.output,
error,
codecError,
self.doc,
documentation,
authType,
)
}
Expand Down Expand Up @@ -779,7 +779,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = (contentCodec ++ StatusCodec.status(status)) | self.output,
error,
codecError,
self.doc,
documentation,
authType,
)
}
Expand All @@ -797,7 +797,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
output = ((contentCodec ++ StatusCodec.status(status)) ?? doc) | self.output,
error,
codecError,
self.doc,
documentation,
authType,
)
}
Expand All @@ -815,12 +815,12 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
* example to group endpoints for OpenAPI.
*/
def tag(tag: String, tags: String*): Endpoint[PathInput, Input, Err, Output, Auth] =
copy(doc = doc.tag(tag +: tags))
copy(documentation = documentation.tag(tag +: tags))

/**
* A list of tags for this endpoint.
*/
def tags: List[String] = doc.tags
def tags: List[String] = documentation.tags

/**
* Transforms the input of this endpoint using the specified functions. This
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object HttpGen {
}

private def doc(endpoint: Endpoint[_, _, _, _, _]) =
if (endpoint.doc == Doc.empty) None else Some(endpoint.doc.toPlaintext(color = false))
if (endpoint.documentation == Doc.empty) None else Some(endpoint.documentation.toPlaintext(color = false))

def variables(inAtoms: AtomizedMetaCodecs): Seq[HttpVariable] =
pathVariables(inAtoms) ++ queryVariables(inAtoms) ++ headersVariables(inAtoms) ++ bodyVariables(inAtoms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ object OpenAPI {

// todo maybe not the best regex, but the old one was not working at all
// safe chars from RFC1738 "$" | "-" | "_" | "." | "+"
val validPath: Regex = """\/[\/a-zA-Z0-9\-_{}$.+]*""".r
private val validPath: Regex = """\/[\/a-zA-Z0-9\-_{}$.+]*""".r

def fromString(name: String): Option[Path] = name match {
case validPath() => Some(Path(name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ object OpenAPIGen {
val method0 = method(inAtoms.method)
// Endpoint has only one doc. But open api has a summery and a description
val pathItem = OpenAPI.PathItem.empty
.copy(description = Some(endpoint.doc + endpoint.input.doc.getOrElse(Doc.empty)).filter(!_.isEmpty))
.copy(description = Some(endpoint.documentation + endpoint.input.doc.getOrElse(Doc.empty)).filter(!_.isEmpty))
val pathItemWithOp = method0 match {
case Method.OPTIONS => pathItem.addOptions(operation(endpoint))
case Method.GET => pathItem.addGet(operation(endpoint))
Expand Down Expand Up @@ -557,7 +557,7 @@ object OpenAPIGen {
}

def operation(endpoint: Endpoint[_, _, _, _, _]): OpenAPI.Operation = {
val maybeDoc = Some(endpoint.doc + pathDoc).filter(!_.isEmpty)
val maybeDoc = Some(endpoint.documentation + pathDoc).filter(!_.isEmpty)
OpenAPI.Operation(
tags = endpoint.tags,
summary = None,
Expand Down

2 comments on commit 74aec00

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 : Performance Benchmarks (SimpleEffectBenchmarkServer)

concurrency: 256
requests/sec: 335901

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 : Performance Benchmarks (PlainTextBenchmarkServer)

concurrency: 256
requests/sec: 335723

Please sign in to comment.