Skip to content

Commit

Permalink
Merge pull request #157 from softwaremill/schema-comparator
Browse files Browse the repository at this point in the history
SchemaComparator
  • Loading branch information
adamw authored Apr 24, 2024
2 parents bac9578 + 84e680b commit 19ef388
Show file tree
Hide file tree
Showing 8 changed files with 1,661 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
~/.ivy2/cache
~/.coursier
key: sbt-cache-${{ runner.os }}-${{ hashFiles('project/build.properties') }}
- name: Install libidn11-dev
- name: Install libidn2-dev
run: |
sudo apt-get update
sudo apt-get install libidn11-dev
sudo apt-get install libidn2-dev
- name: Compile
run: sbt -v compile
- name: Test
Expand Down
35 changes: 21 additions & 14 deletions apispec-model/src/main/scala/sttp/apispec/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,19 @@ case class Schema(
// 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.
val nullSchema = Schema(SchemaType.Null)
if(anyOf.contains(nullSchema)) this // ensure idempotency
else if (anyOf.nonEmpty) copy(anyOf = anyOf :+ nullSchema)
else Schema(anyOf = List(this, nullSchema))
if(anyOf.contains(Schema.Null)) this // ensure idempotency
else if (anyOf.nonEmpty) copy(anyOf = anyOf :+ Schema.Null)
else Schema(anyOf = List(this, Schema.Null))
}
}

case class Discriminator(propertyName: String, mapping: Option[ListMap[String, String]])

object Schema {
final val Empty = Schema()
final val Nothing = Schema(not = Some(Empty))
final val Null = Schema(SchemaType.Null)

def apply(schemaType: SchemaType, moreTypes: SchemaType*): Schema =
new Schema(`type` = Some(schemaType :: moreTypes.toList))

Expand All @@ -159,7 +162,9 @@ object Schema {
Schema($ref = Some(s"$prefix${$ref}"))
}

sealed abstract class SchemaType(val value: String)
sealed abstract class SchemaType(val value: String) {
override def toString: String = value
}
object SchemaType {
case object Boolean extends SchemaType("boolean")
case object Object extends SchemaType("object")
Expand All @@ -168,16 +173,18 @@ object SchemaType {
case object String extends SchemaType("string")
case object Integer extends SchemaType("integer")
case object Null extends SchemaType("null")

final val Values = List(Boolean, Object, Array, Number, String, Integer, Null)
}

object SchemaFormat {
val Int32: Option[String] = Some("int32")
val Int64: Option[String] = Some("int64")
val Float: Option[String] = Some("float")
val Double: Option[String] = Some("double")
val Byte: Option[String] = Some("byte")
val Binary: Option[String] = Some("binary")
val Date: Option[String] = Some("date")
val DateTime: Option[String] = Some("date-time")
val Password: Option[String] = Some("password")
final val Int32 = "int32"
final val Int64 = "int64"
final val Float = "float"
final val Double = "double"
final val Byte = "byte"
final val Binary = "binary"
final val Date = "date"
final val DateTime = "date-time"
final val Password = "password"
}
Loading

0 comments on commit 19ef388

Please sign in to comment.