sttp.tapir.SchemaType.SProductField overrides equals to compare by (name, schema), but inherits Object.hashCode. The equals / hashCode contract requires equal objects to share a hash code, so any use of SProductField as a Map key, in a Set, or via .distinct will silently misbehave.
Source:
|
override def equals(other: Any): Boolean = other match { |
|
case p: SProductField[?] => p.name == name && p.schema == schema |
|
case _ => false |
|
} |
trait SProductField[T] extends Serializable {
type FieldType
def name: FieldName
def schema: Schema[FieldType]
def get: T => Option[FieldType]
override def equals(other: Any): Boolean = other match {
case p: SProductField[?] => p.name == name && p.schema == schema
case _ => false
}
// no hashCode override
}
Two SProductFields with the same (name, schema) come back as equals == true but with different identity-based hashCodes, so a HashMap[SProductField[_], V] won't find an existing key, and a hash-bucketed Set won't dedup them.
Suggested fix — keep equals as it is, add a matching hashCode:
override def hashCode(): Int = (name, schema).##
Happy to PR with a small unit test that hashes/dedups two equal SProductField instances.
sttp.tapir.SchemaType.SProductFieldoverridesequalsto compare by(name, schema), but inheritsObject.hashCode. Theequals/hashCodecontract requires equal objects to share a hash code, so any use ofSProductFieldas aMapkey, in aSet, or via.distinctwill silently misbehave.Source:
tapir/core/src/main/scala/sttp/tapir/SchemaType.scala
Lines 69 to 72 in 88d662d
Two
SProductFields with the same(name, schema)come back asequals == truebut with different identity-basedhashCodes, so aHashMap[SProductField[_], V]won't find an existing key, and a hash-bucketedSetwon't dedup them.Suggested fix — keep
equalsas it is, add a matchinghashCode:Happy to PR with a small unit test that hashes/dedups two equal
SProductFieldinstances.