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

Fix some Endpoint::doc field usages && Rename it to documentation to avoid this kind of mistake in the future #3044

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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
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,
Copy link
Member Author

@guizmaii guizmaii Aug 22, 2024

Choose a reason for hiding this comment

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

I don't understand why using myEndpoint.out[...](status = ..., doc = ...) would reset the doc to an empty one. Probably a typo

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,
Copy link
Member Author

Choose a reason for hiding this comment

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

This was not using the correct doc. It was using the one passed in parameter and not the one from this

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,
Copy link
Member Author

Choose a reason for hiding this comment

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

This was not using the correct doc. It was using the one passed in parameter and not the one from this

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
Copy link
Member Author

Choose a reason for hiding this comment

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

Not related to the main subject of this PR but I've seen that this implementation detail was public. I think we can make it private


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
Loading