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

Update scalafmt-core to 3.8.6 #205

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@

# Scala Steward: Reformat with scalafmt 3.7.14
ece31cc91dfbb7f55e1dd9080ef914e3a00ce20a

# Scala Steward: Reformat with scalafmt 3.8.6
9fc6b699144d79a363e41d409f45d75a918444f4
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
runner.dialect = scala3
version = 3.7.17
version = 3.8.6
maxColumn = 120
13 changes: 7 additions & 6 deletions apispec-model/src/main/scala/sttp/apispec/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,18 @@ case class Schema(
case Some(types) =>
val NullExample = ExampleSingleValue("null")
if (types.contains(SchemaType.Null)) this // ensure idempotency
else copy(
`type` = Some(types :+ SchemaType.Null),
`enum` = `enum`.orElse(`const`.map(List(_))).map(vs => (vs :+ NullExample).distinct),
`const` = None
)
else
copy(
`type` = Some(types :+ SchemaType.Null),
`enum` = `enum`.orElse(`const`.map(List(_))).map(vs => (vs :+ NullExample).distinct),
`const` = None
)

case None =>
// Representing nullable schemas (without explicit `type`) using `anyOf` is safer than `oneOf`.
// If `oneOf` was used, and the original schema was already nullable, `null` would not be a valid
// value for the resulting schema.
if(anyOf.contains(Schema.Null)) this // ensure idempotency
if (anyOf.contains(Schema.Null)) this // ensure idempotency
else if (anyOf.nonEmpty) copy(anyOf = anyOf :+ Schema.Null)
else Schema(anyOf = List(this, Schema.Null))
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@ sealed abstract class SchemaCompatibilityIssue {
.mkString("\n")
}

/**
* A [[SchemaCompatibilityIssue]] used when the schemas are different but the comparator was unable
* to determine compatibility. Thus, the schemas may or may not be compatible.
*/
/** A [[SchemaCompatibilityIssue]] used when the schemas are different but the comparator was unable to determine
* compatibility. Thus, the schemas may or may not be compatible.
*/
case class GeneralSchemaMismatch(
writerSchema: Schema,
readerSchema: Schema
writerSchema: Schema,
readerSchema: Schema
) extends SchemaCompatibilityIssue {
def description: String =
"schemas differ, but it was not possible to determine their compatibility"
}

case class NoValuesAllowed(
writerSchema: Schema
writerSchema: Schema
) extends SchemaCompatibilityIssue {
def description: String = "target schema does not allow any values"
}

case class TypeMismatch(
incompatibleWriterTypes: List[SchemaType],
readerTypes: List[SchemaType]
incompatibleWriterTypes: List[SchemaType],
readerTypes: List[SchemaType]
) extends SchemaCompatibilityIssue {
def description: String = {
val wt = incompatibleWriterTypes
Expand All @@ -51,9 +50,9 @@ case class TypeMismatch(
}

case class EnumMismatch(
// None indicates that the writer schema has no enum values
incompatibleWriterValues: Option[List[ExampleValue]],
readerValues: List[ExampleValue]
// None indicates that the writer schema has no enum values
incompatibleWriterValues: Option[List[ExampleValue]],
readerValues: List[ExampleValue]
) extends SchemaCompatibilityIssue {
def description: String = {
val writerValuesRepr =
Expand All @@ -65,8 +64,8 @@ case class EnumMismatch(
}

case class FormatMismatch(
writerFormat: Option[String],
readerFormat: String
writerFormat: Option[String],
readerFormat: String
) extends SchemaCompatibilityIssue {
def description: String = {
val writerFormatRepr = writerFormat.fold("")(wf => s" with which $wf is not compatible")
Expand All @@ -75,8 +74,8 @@ case class FormatMismatch(
}

case class MultipleOfMismatch(
writerMultiplier: Option[BigDecimal],
readerMultiplier: BigDecimal
writerMultiplier: Option[BigDecimal],
readerMultiplier: BigDecimal
) extends SchemaCompatibilityIssue {
def description: String = {
val writerMultiplierRepr = writerMultiplier.fold("")(wm => s", as opposed to $wm")
Expand All @@ -85,24 +84,24 @@ case class MultipleOfMismatch(
}

case class NumericBoundsMismatch(
writerBounds: Bounds[BigDecimal],
readerBounds: Bounds[BigDecimal]
writerBounds: Bounds[BigDecimal],
readerBounds: Bounds[BigDecimal]
) extends SchemaCompatibilityIssue {
def description: String =
s"target value bounds $readerBounds are stricter than $writerBounds"
}

case class StringLengthBoundsMismatch(
writerBounds: Bounds[Int],
readerBounds: Bounds[Int]
writerBounds: Bounds[Int],
readerBounds: Bounds[Int]
) extends SchemaCompatibilityIssue {
def description: String =
s"target string length bounds $readerBounds are stricter than $writerBounds"
}

case class PatternMismatch(
writerPattern: Option[Pattern],
readerPattern: Pattern
writerPattern: Option[Pattern],
readerPattern: Pattern
) extends SchemaCompatibilityIssue {
def description: String = {
val writerPatternRepr = writerPattern.fold("")(wp => s", as opposed to $wp")
Expand All @@ -115,122 +114,121 @@ case object UniqueItemsRequired extends SchemaCompatibilityIssue {
}

case class ArrayLengthBoundsMismatch(
writerBounds: Bounds[Int],
readerBounds: Bounds[Int]
writerBounds: Bounds[Int],
readerBounds: Bounds[Int]
) extends SchemaCompatibilityIssue {
def description: String =
s"target array length (minItems/maxItems) bounds $readerBounds are stricter than $writerBounds"
}

case class ObjectSizeBoundsMismatch(
writerBounds: Bounds[Int],
readerBounds: Bounds[Int]
writerBounds: Bounds[Int],
readerBounds: Bounds[Int]
) extends SchemaCompatibilityIssue {
def description: String =
s"target object size (minProperties/maxProperties) $readerBounds is stricter than $writerBounds"
}

case class MissingRequiredProperties(
newRequiredProperties: Set[String]
newRequiredProperties: Set[String]
) extends SchemaCompatibilityIssue {
def description: String = s"target schema requires properties: ${newRequiredProperties.mkString(", ")}"
}

case class MissingDependentRequiredProperties(
property: String,
newRequiredProperties: Set[String]
property: String,
newRequiredProperties: Set[String]
) extends SchemaCompatibilityIssue {
def description: String =
s"target schema introduced new required dependent properties for property $property: ${newRequiredProperties.mkString(", ")}"
}

case class DiscriminatorPropertyMismatch(
writerDiscriminator: String,
readerDiscriminator: String
writerDiscriminator: String,
readerDiscriminator: String
) extends SchemaCompatibilityIssue {
def description: String =
s"target schema discriminator property $readerDiscriminator, as opposed to $writerDiscriminator"
}

case class UnsupportedDiscriminatorValues(
unsupportedValues: List[String]
unsupportedValues: List[String]
) extends SchemaCompatibilityIssue {
def description: String =
s"target schema does not accept discriminator values: ${unsupportedValues.mkString(", ")}"
}

/** Base class for compatibility issues which aggregate issues from a subschema. A _subschema_ is a schema used within a
* structure of another schema, e.g. a schema for an array item, a property, etc.
*/
* structure of another schema, e.g. a schema for an array item, a property, etc.
*/
sealed abstract class SubschemaCompatibilityIssue extends SchemaCompatibilityIssue {
def subschemaIssues: List[SchemaCompatibilityIssue]
}

case class IncompatibleProperty(
property: String,
subschemaIssues: List[SchemaCompatibilityIssue]
property: String,
subschemaIssues: List[SchemaCompatibilityIssue]
) extends SubschemaCompatibilityIssue {
def description: String =
s"incompatible schema for property $property:\n${issuesRepr(subschemaIssues)}"
}

case class IncompatibleDiscriminatorCase(
discriminatorValue: String,
subschemaIssues: List[SchemaCompatibilityIssue]
discriminatorValue: String,
subschemaIssues: List[SchemaCompatibilityIssue]
) extends SubschemaCompatibilityIssue {
def description: String =
s"incompatible schema for discriminator value $discriminatorValue:\n${issuesRepr(subschemaIssues)}"
}

case class IncompatibleAdditionalProperties(
subschemaIssues: List[SchemaCompatibilityIssue]
subschemaIssues: List[SchemaCompatibilityIssue]
) extends SubschemaCompatibilityIssue {
def description: String =
s"incompatible schema for additional properties:\n${issuesRepr(subschemaIssues)}"
}

case class IncompatiblePropertyNames(
subschemaIssues: List[SchemaCompatibilityIssue]
subschemaIssues: List[SchemaCompatibilityIssue]
) extends SubschemaCompatibilityIssue {
override def description: String =
s"incompatible schema for property names:\n${issuesRepr(subschemaIssues)}"
}

case class IncompatibleItems(
subschemaIssues: List[SchemaCompatibilityIssue]
subschemaIssues: List[SchemaCompatibilityIssue]
) extends SubschemaCompatibilityIssue {
def description: String =
s"incompatible schema for items:\n${issuesRepr(subschemaIssues)}"
}

case class IncompatiblePrefixItem(
index: Int,
subschemaIssues: List[SchemaCompatibilityIssue]
index: Int,
subschemaIssues: List[SchemaCompatibilityIssue]
) extends SubschemaCompatibilityIssue {
def description: String =
s"incompatible schema for prefix item at index $index:\n${issuesRepr(subschemaIssues)}"
}

case class IncompatibleUnionVariant(
index: Int,
subschemaIssues: List[SchemaCompatibilityIssue]
index: Int,
subschemaIssues: List[SchemaCompatibilityIssue]
) extends SubschemaCompatibilityIssue {
def description: String =
s"incompatible anyOf/oneOf variant at index $index:\n${issuesRepr(subschemaIssues)}"
}

/**
* An issue raised when a schema is not compatible with any of the alternatives in a target union schema.
*
* @param alternatives a list of non-empty lists of issues, where each list corresponds to one of the alternatives
*/
/** An issue raised when a schema is not compatible with any of the alternatives in a target union schema.
*
* @param alternatives
* a list of non-empty lists of issues, where each list corresponds to one of the alternatives
*/
case class AlternativeIssues(
alternatives: List[List[SchemaCompatibilityIssue]]
alternatives: List[List[SchemaCompatibilityIssue]]
) extends SchemaCompatibilityIssue {
override def description: String = {
val alternativesReprs = alternatives.zipWithIndex.map {
case (issues, idx) =>
s"for alternative $idx:\n${issuesRepr(issues)}"
val alternativesReprs = alternatives.zipWithIndex.map { case (issues, idx) =>
s"for alternative $idx:\n${issuesRepr(issues)}"
}
s"schema is not compatible with any of the alternatives in oneOf/anyOf:\n${alternativesReprs.mkString("\n")}"
}
Expand Down
18 changes: 9 additions & 9 deletions apispec-model/src/main/scala/sttp/apispec/validation/util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ case class Bounds[T](min: Option[Bound[T]], max: Option[Bound[T]]) {
override def toString: String = {
val minRepr = min.fold("(-inf") {
case Bound(value, false) => s"($value"
case Bound(value, true) => s"[$value"
case Bound(value, true) => s"[$value"
}
val maxRepr = max.fold("inf)") {
case Bound(value, false) => s"$value)"
case Bound(value, true) => s"$value]"
case Bound(value, true) => s"$value]"
}
s"$minRepr,$maxRepr"
}

def contains(other: Bounds[T])(implicit ord: Ordering[T]): Boolean = {
val minOk = (min, other.min) match {
case (Some(Bound(tm, false)), Some(Bound(om, true))) => ord.lt(tm, om)
case (Some(Bound(tm, _)), Some(Bound(om, _))) => ord.lteq(tm, om)
case (Some(_), None) => false
case (None, _) => true
case (Some(Bound(tm, _)), Some(Bound(om, _))) => ord.lteq(tm, om)
case (Some(_), None) => false
case (None, _) => true
}
val maxOk = (max, other.max) match {
case (Some(Bound(tm, false)), Some(Bound(om, true))) => ord.gt(tm, om)
case (Some(Bound(tm, _)), Some(Bound(om, _))) => ord.gteq(tm, om)
case (Some(_), None) => false
case (None, _) => true
case (Some(Bound(tm, _)), Some(Bound(om, _))) => ord.gteq(tm, om)
case (Some(_), None) => false
case (None, _) => true
}
minOk && maxOk
}
}
}
23 changes: 14 additions & 9 deletions apispec-model/src/test/scala/sttp/apispec/SchemaTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,25 @@ class SchemaTest extends AnyFunSuite {
}

test("nullable enum") {
val schema = Schema(`type` = Some(List(SchemaType.String)), `enum` = Some(List("a", "b").map(ExampleSingleValue(_))))
assert(schema.nullable == Schema(
`type` = Some(List(SchemaType.String, SchemaType.Null)),
`enum` = Some(List("a", "b", "null").map(ExampleSingleValue(_)))
))
val schema =
Schema(`type` = Some(List(SchemaType.String)), `enum` = Some(List("a", "b").map(ExampleSingleValue(_))))
assert(
schema.nullable == Schema(
`type` = Some(List(SchemaType.String, SchemaType.Null)),
`enum` = Some(List("a", "b", "null").map(ExampleSingleValue(_)))
)
)
assert(schema.nullable.nullable == schema.nullable) // idempotency
}

test("nullable const") {
val schema = Schema(`type` = Some(List(SchemaType.String)), `const` = Some(ExampleSingleValue("a")))
assert(schema.nullable == Schema(
`type` = Some(List(SchemaType.String, SchemaType.Null)),
`enum` = Some(List("a", "null").map(ExampleSingleValue(_)))
))
assert(
schema.nullable == Schema(
`type` = Some(List(SchemaType.String, SchemaType.Null)),
`enum` = Some(List("a", "null").map(ExampleSingleValue(_)))
)
)
assert(schema.nullable.nullable == schema.nullable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,3 @@ class BoundsTest extends AnyFunSuite {
assert(!b.contains(Bounds(Some(Bound.exclusive(-1)), Some(Bound.exclusive(11)))))
}
}


Loading
Loading