Skip to content

Commit

Permalink
Add test for both "#/components/schemas/" and "#/$defs/"
Browse files Browse the repository at this point in the history
  • Loading branch information
seveneves committed Aug 7, 2024
1 parent c88ce94 commit 02d61a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package sttp.apispec.validation

class ComponentsSchemaComparatorTest extends SchemaComparatorTest(SchemaResolver.ComponentsRefPrefix)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package sttp.apispec.validation

class DefsSchemaComparatorTest extends SchemaComparatorTest(SchemaResolver.DefsRefPrefix)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import sttp.apispec._

import scala.collection.immutable.ListMap

class SchemaComparatorTest extends AnyFunSuite {
abstract class SchemaComparatorTest(referencePrefix: String) extends AnyFunSuite {

private val stringSchema = Schema(SchemaType.String)
private val integerSchema = Schema(SchemaType.Integer)
private val numberSchema = Schema(SchemaType.Number)
Expand Down Expand Up @@ -107,7 +108,7 @@ class SchemaComparatorTest extends AnyFunSuite {
)

private def ref(name: String): Schema =
Schema.referenceTo(SchemaResolver.ComponentsRefPrefix, name)
Schema.referenceTo(referencePrefix, name)

private def compare(writerSchema: Schema, readerSchema: Schema): List[SchemaCompatibilityIssue] =
new SchemaComparator(writerSchemas, readerSchemas)
Expand Down Expand Up @@ -481,11 +482,11 @@ class SchemaComparatorTest extends AnyFunSuite {
assert(compare(
Schema(
oneOf = List(ref("Foo"), ref("Bar")),
discriminator = Some(Discriminator("type", Some(ListMap("WFoo" -> s"${SchemaResolver.ComponentsRefPrefix}Foo"))))
discriminator = Some(Discriminator("type", Some(ListMap("WFoo" -> s"${referencePrefix}Foo"))))
),
Schema(
oneOf = List(ref("Foo"), ref("Bar"), ref("Baz")),
discriminator = Some(Discriminator("type", Some(ListMap("RBar" -> s"${SchemaResolver.ComponentsRefPrefix}Bar"))))
discriminator = Some(Discriminator("type", Some(ListMap("RBar" -> s"${referencePrefix}Bar"))))
),
) == List(
UnsupportedDiscriminatorValues(List("WFoo", "Bar"))
Expand All @@ -496,7 +497,7 @@ class SchemaComparatorTest extends AnyFunSuite {
assert(compare(
Schema(
oneOf = List(ref("Foo"), ref("Bar")),
discriminator = Some(Discriminator("type", Some(ListMap("Baz" -> s"${SchemaResolver.ComponentsRefPrefix}Bar"))))
discriminator = Some(Discriminator("type", Some(ListMap("Baz" -> s"${referencePrefix}Bar"))))
),
Schema(
oneOf = List(ref("Foo"), ref("Baz")),
Expand Down

0 comments on commit 02d61a1

Please sign in to comment.