Skip to content

Commit

Permalink
Update to Scala 2.13.4
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Dec 16, 2020
1 parent dec90d6 commit 0490f0e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sbt.Reference.display
import sbt.internal.ProjectMatrix

val scala2_12 = "2.12.12"
val scala2_13 = "2.13.3"
val scala2_13 = "2.13.4"

val allScalaVersions = List(scala2_12, scala2_13)
val scala2_12Versions = List(scala2_12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private[generic] class CaseClassUtil[C <: blackbox.Context, T: C#WeakTypeTag](va
case a if a.tree.tpe <:< annotationType =>
a.tree.children.tail match {
case List(Literal(Constant(str: String))) => str
case _ => throw new IllegalStateException(s"Cannot extract annotation argument from: ${c.universe.showRaw(a.tree)}")
}
}
}
Expand All @@ -54,6 +55,7 @@ private[generic] class CaseClassUtil[C <: blackbox.Context, T: C#WeakTypeTag](va
None
case List(Literal(Constant(str: String))) =>
Some(str)
case _ => throw new IllegalStateException(s"Cannot extract annotation argument from: ${c.universe.showRaw(a.tree)}")
}
}
}
6 changes: 6 additions & 0 deletions core/src/main/scala/sttp/tapir/internal/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,10 @@ package object internal {
private def wrapException[F[_], O, E, I](exception: Throwable)(implicit me: MonadError[F]): F[Either[E, O]] = {
me.unit(Left(exception.asInstanceOf[E]): Either[E, O])
}

// see https://github.com/scala/bug/issues/12186
implicit class RichVector[T](c: Vector[T]) {
def headAndTail: Option[(T, Vector[T])] = if (c.isEmpty) None else Some((c.head, c.tail))
def initAndLast: Option[(Vector[T], T)] = if (c.isEmpty) None else Some((c.init, c.last))
}
}
26 changes: 13 additions & 13 deletions core/src/main/scala/sttp/tapir/server/internal/DecodeInputs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ object DecodeInputs {
decodeValues: DecodeInputsResult.Values,
ctx: DecodeInputsContext
): (DecodeInputsResult, DecodeInputsContext) = {
pathInputs match {
case Vector() =>
pathInputs.initAndLast match {
case None =>
// Match everything if no path input is specified
(decodeValues, ctx)
case _ :+ last =>
case Some((_, last)) =>
matchPathInner(
pathInputs = pathInputs,
ctx = ctx,
Expand All @@ -119,8 +119,8 @@ object DecodeInputs {
decodedPathInputs: Vector[(IndexedBasicInput, DecodeResult[_])],
lastPathInput: IndexedBasicInput
): (DecodeInputsResult, DecodeInputsContext) = {
pathInputs match {
case (idxInput @ IndexedBasicInput(in, _)) +: restInputs =>
pathInputs.headAndTail match {
case Some((idxInput @ IndexedBasicInput(in, _), restInputs)) =>
in match {
case EndpointInput.FixedPath(expectedSegment, codec, _) =>
val (nextSegment, newCtx) = ctx.nextPathSegment
Expand Down Expand Up @@ -161,7 +161,7 @@ object DecodeInputs {
case _ =>
throw new IllegalStateException(s"Unexpected EndpointInput ${in.show} encountered. This is most likely a bug in the library")
}
case Vector() =>
case None =>
val (extraSegmentOpt, newCtx) = ctx.nextPathSegment
extraSegmentOpt match {
case Some(_) =>
Expand All @@ -181,9 +181,9 @@ object DecodeInputs {
decodedPathInputs: Vector[(IndexedBasicInput, DecodeResult[_])],
acc: DecodeInputsResult.Values
): DecodeInputsResult = {
decodedPathInputs match {
case Vector() => acc
case t +: ts =>
decodedPathInputs.headAndTail match {
case None => acc
case Some((t, ts)) =>
t match {
case (indexedInput, failure: DecodeResult.Failure) => DecodeInputsResult.Failure(indexedInput.input, failure)
case (indexedInput, DecodeResult.Value(v)) => foldDecodedPathInputs(ts, acc.setBasicInputValue(v, indexedInput.index))
Expand All @@ -204,11 +204,11 @@ object DecodeInputs {
values: DecodeInputsResult.Values,
ctx: DecodeInputsContext
): (DecodeInputsResult, DecodeInputsContext) = {
inputs match {
case Vector() => (values, ctx)
case IndexedBasicInput(input @ EndpointIO.Body(_, _, _), index) +: inputsTail =>
inputs.headAndTail match {
case None => (values, ctx)
case Some((IndexedBasicInput(input @ EndpointIO.Body(_, _, _), index), inputsTail)) =>
matchOthers(inputsTail, values.addBodyInput(input, index), ctx)
case indexedInput +: inputsTail =>
case Some((indexedInput, inputsTail)) =>
val (result, ctx2) = matchOther(indexedInput.input, ctx)
result match {
case DecodeResult.Value(v) => matchOthers(inputsTail, values.setBasicInputValue(v, indexedInput.index), ctx2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sttp.tapir.server.internal

import sttp.tapir.internal.{CombineParams, Params, ParamsAsAny}
import sttp.tapir.internal.{CombineParams, Params, ParamsAsAny, RichVector}
import sttp.tapir.{DecodeResult, EndpointIO, EndpointInput, Mapping}

sealed trait InputValuesResult
Expand All @@ -25,9 +25,9 @@ object InputValues {
case EndpointIO.MappedPair(wrapped, codec) => handleMappedPair(wrapped, codec, remainingBasicValues)
case auth: EndpointInput.Auth[_] => apply(auth.input, remainingBasicValues)
case _: EndpointInput.Basic[_] =>
remainingBasicValues match {
case v +: valuesTail => InputValuesResult.Value(ParamsAsAny(v), valuesTail)
case Vector() =>
remainingBasicValues.headAndTail match {
case Some((v, valuesTail)) => InputValuesResult.Value(ParamsAsAny(v), valuesTail)
case None =>
throw new IllegalStateException(s"Mismatch between basic input values: $remainingBasicValues, and basic inputs in: $input")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ private[docs] object SecuritySchemesForEndpoints {
takenNames: Set[SchemeName],
acc: Map[SecurityScheme, SchemeName]
): Map[SecurityScheme, SchemeName] = {
schemes match {
case Vector() => acc
case scheme +: tail =>
schemes.headAndTail match {
case None => acc
case Some((scheme, tail)) =>
val baseName = scheme.`type` + "Auth"
val name = uniqueName(baseName, !takenNames.contains(_))
nameSecuritySchemes(tail, takenNames + name, acc + (scheme -> name))
Expand Down

0 comments on commit 0490f0e

Please sign in to comment.