Skip to content

Commit

Permalink
Move validatorForDescribed* to LowPriority trait to prevent ambigio…
Browse files Browse the repository at this point in the history
…us implicits under Scala 3.6+ (#3938)
  • Loading branch information
WojciechMazur authored Jul 19, 2024
1 parent 16e794e commit 72dfda5
Showing 1 changed file with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,35 @@ trait TapirCodecIron extends DescriptionWitness with LowPriorityValidatorForPred

}

}

private[iron] trait ValidatorForPredicate[Value, Predicate] {
def validator: Validator[Value]
def makeErrors(value: Value, errorMessage: String): List[ValidationError[_]]
lazy val containsMinSizePositive: Boolean = validator.asPrimitiveValidators.exists {
case Validator.MinSize(a) => a > 0
case _ => false
}
}

private[iron] trait PrimitiveValidatorForPredicate[Value, Predicate] extends ValidatorForPredicate[Value, Predicate] {
def validator: Validator.Primitive[Value]
def makeErrors(value: Value, errorMessage: String): List[ValidationError[_]]
}

private[iron] object ValidatorForPredicate {
def fromPrimitiveValidator[Value, Predicate](
primitiveValidator: Validator.Primitive[Value]
): PrimitiveValidatorForPredicate[Value, Predicate] =
new PrimitiveValidatorForPredicate[Value, Predicate] {
override def validator: Validator.Primitive[Value] = primitiveValidator
override def makeErrors(value: Value, errorMessage: String): List[ValidationError[_]] =
List(ValidationError[Value](primitiveValidator, value))
}
}

private[iron] trait LowPriorityValidatorForPredicate extends LowPriorityValidatorForPredicate2 {

inline given validatorForDescribedAnd[N, P](using
id: IsDescription[P],
mirror: IntersectionTypeMirror[id.Predicate]
Expand Down Expand Up @@ -244,32 +273,7 @@ trait TapirCodecIron extends DescriptionWitness with LowPriorityValidatorForPred
validator.asInstanceOf[PrimitiveValidatorForPredicate[N, P]]
}

private[iron] trait ValidatorForPredicate[Value, Predicate] {
def validator: Validator[Value]
def makeErrors(value: Value, errorMessage: String): List[ValidationError[_]]
lazy val containsMinSizePositive: Boolean = validator.asPrimitiveValidators.exists {
case Validator.MinSize(a) => a > 0
case _ => false
}
}

private[iron] trait PrimitiveValidatorForPredicate[Value, Predicate] extends ValidatorForPredicate[Value, Predicate] {
def validator: Validator.Primitive[Value]
def makeErrors(value: Value, errorMessage: String): List[ValidationError[_]]
}

private[iron] object ValidatorForPredicate {
def fromPrimitiveValidator[Value, Predicate](
primitiveValidator: Validator.Primitive[Value]
): PrimitiveValidatorForPredicate[Value, Predicate] =
new PrimitiveValidatorForPredicate[Value, Predicate] {
override def validator: Validator.Primitive[Value] = primitiveValidator
override def makeErrors(value: Value, errorMessage: String): List[ValidationError[_]] =
List(ValidationError[Value](primitiveValidator, value))
}
}

private[iron] trait LowPriorityValidatorForPredicate {
private[iron] trait LowPriorityValidatorForPredicate2 {

inline given [Value, Predicate](using
inline constraint: Constraint[Value, Predicate],
Expand Down

0 comments on commit 72dfda5

Please sign in to comment.