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 fa5c9f7
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 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,13 +18,9 @@ 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._
Expand Down Expand Up @@ -367,66 +363,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

4 comments on commit fa5c9f7

@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: 351903

@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: 357252

@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: 359229

@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: 346629

Please sign in to comment.