Skip to content

Commit

Permalink
Fix for #3144
Browse files Browse the repository at this point in the history
  • Loading branch information
guizmaii committed Nov 19, 2024
1 parent a9ab6fe commit c6ffc8d
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ package zio.http.endpoint

import scala.annotation.nowarn
import scala.reflect.ClassTag

import zio._

import zio.stream.ZStream

import zio.schema.Schema

import zio.http.Header.Accept.MediaTypeWithQFactor
import zio.http._
import zio.http.codec._
import zio.http.endpoint.Endpoint.{OutErrors, defaultMediaTypes}
import zio.http.internal.<:!<

/**
* An [[zio.http.endpoint.Endpoint]] represents an API endpoint for the HTTP
Expand Down Expand Up @@ -367,66 +364,69 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
* Returns a new endpoint derived from this one, whose request content must
* satisfy the specified schema.
*/
def in[Input2: HttpContentCodec](implicit
def in[Input2: EnvironmentTag: HttpContentCodec](implicit
combiner: Combiner[Input, Input2],
): Endpoint[PathInput, combiner.Out, Err, Output, Auth] =
copy(input = input ++ HttpCodec.content[Input2])
inCodec(HttpCodec.content[Input2])

/**
* Returns a new endpoint derived from this one, whose request content must
* satisfy the specified schema and is documented.
*/
def in[Input2: HttpContentCodec](doc: Doc)(implicit
def in[Input2: EnvironmentTag: HttpContentCodec](doc: Doc)(implicit
combiner: Combiner[Input, Input2],
): Endpoint[PathInput, combiner.Out, Err, Output, Auth] =
copy(input = input ++ HttpCodec.content[Input2] ?? doc)
inCodec(HttpCodec.content[Input2] ?? doc)

/**
* Returns a new endpoint derived from this one, whose request content must
* satisfy the specified schema and is documented.
*/
def in[Input2: HttpContentCodec](name: String)(implicit
def in[Input2: EnvironmentTag: HttpContentCodec](name: String)(implicit
combiner: Combiner[Input, Input2],
): Endpoint[PathInput, combiner.Out, Err, Output, Auth] =
copy(input = input ++ HttpCodec.content[Input2](name))
inCodec(HttpCodec.content[Input2](name))

/**
* Returns a new endpoint derived from this one, whose request content must
* satisfy the specified schema and is documented.
*/
def in[Input2: HttpContentCodec](name: String, doc: Doc)(implicit
def in[Input2: EnvironmentTag: HttpContentCodec](name: String, doc: Doc)(implicit
combiner: Combiner[Input, Input2],
): Endpoint[PathInput, combiner.Out, Err, Output, Auth] =
copy(input = input ++ (HttpCodec.content[Input2](name) ?? doc))
inCodec(HttpCodec.content[Input2](name) ?? doc)

def in[Input2: HttpContentCodec](mediaType: MediaType)(implicit
def in[Input2: EnvironmentTag: HttpContentCodec](mediaType: MediaType)(implicit
combiner: Combiner[Input, Input2],
): Endpoint[PathInput, combiner.Out, Err, Output, Auth] =
copy(input = input ++ HttpCodec.content[Input2](mediaType))
inCodec(HttpCodec.content[Input2](mediaType))

def in[Input2: HttpContentCodec](mediaType: MediaType, doc: Doc)(implicit
def in[Input2: EnvironmentTag: HttpContentCodec](mediaType: MediaType, doc: Doc)(implicit
combiner: Combiner[Input, Input2],
): Endpoint[PathInput, combiner.Out, Err, Output, Auth] =
copy(input = input ++ (HttpCodec.content(mediaType) ?? doc))
inCodec(HttpCodec.content(mediaType) ?? doc)

def in[Input2: HttpContentCodec](mediaType: MediaType, name: String)(implicit
def in[Input2: EnvironmentTag: HttpContentCodec](mediaType: MediaType, name: String)(implicit
combiner: Combiner[Input, Input2],
): Endpoint[PathInput, combiner.Out, Err, Output, Auth] =
copy(input = input ++ HttpCodec.content(name, mediaType))
inCodec(HttpCodec.content(name, mediaType))

def in[Input2: HttpContentCodec](mediaType: MediaType, name: String, doc: Doc)(implicit
def in[Input2: EnvironmentTag: HttpContentCodec](mediaType: MediaType, name: String, doc: Doc)(implicit
combiner: Combiner[Input, Input2],
): Endpoint[PathInput, combiner.Out, Err, Output, Auth] =
copy(input = input ++ (HttpCodec.content(name, mediaType) ?? doc))
inCodec(HttpCodec.content(name, mediaType) ?? doc)

/**
* Returns a new endpoint derived from this one, whose request must satisfy
* the specified codec.
*/
def inCodec[Input2](codec: HttpCodec[HttpCodecType.RequestType, Input2])(implicit
def inCodec[Input2: EnvironmentTag](codec: HttpCodec[HttpCodecType.RequestType, Input2])(implicit
combiner: Combiner[Input, Input2],
): Endpoint[PathInput, combiner.Out, Err, Output, Auth] =
copy(input = input ++ codec)
): Endpoint[PathInput, combiner.Out, Err, Output, Auth] = {
val isOptional = EnvironmentTag[Input2] <:< EnvironmentTag[Option[?]]
println(s"==================== Is optional: $isOptional ==================== ")
copy(input = input ++ (if (isOptional) codec.optional.asInstanceOf[zio.http.codec.HttpCodec[zio.http.codec.HttpCodecType.RequestType,Input2]] else codec))
}

/**
* Returns a new endpoint derived from this one, whose input type is a stream
Expand Down

0 comments on commit c6ffc8d

Please sign in to comment.