From 8807c3fe3174212309b96004cb2606e03a4167e9 Mon Sep 17 00:00:00 2001 From: Roman Janusz Date: Mon, 22 Apr 2024 18:04:14 +0200 Subject: [PATCH] added test for nullable schemas --- .../validation/SchemaComparatorTest.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apispec-model/src/test/scala/sttp/apispec/validation/SchemaComparatorTest.scala b/apispec-model/src/test/scala/sttp/apispec/validation/SchemaComparatorTest.scala index 6288c36..cce3af0 100644 --- a/apispec-model/src/test/scala/sttp/apispec/validation/SchemaComparatorTest.scala +++ b/apispec-model/src/test/scala/sttp/apispec/validation/SchemaComparatorTest.scala @@ -121,6 +121,8 @@ class SchemaComparatorTest extends AnyFunSuite { assert(compare(ref("Something"), ref("Something")) == List( TypeMismatch(List(SchemaType.String), List(SchemaType.Integer)) )) + assert(compare(ref("Integer"), ref("Something")) == Nil) + assert(compare(ref("Something"), ref("String")) == Nil) } test("recursive schemas") { @@ -130,6 +132,23 @@ class SchemaComparatorTest extends AnyFunSuite { )) } + test("nullable schemas") { + assert(compare(stringSchema, stringSchema.nullable) == Nil) + assert(compare(opaqueSchema, opaqueSchema.nullable) == Nil) + assert(compare(ref("String"), ref("String").nullable) == Nil) + assert(compare(integerSchema.nullable, numberSchema.nullable) == Nil) + + assert(compare(stringSchema.nullable, stringSchema) == List( + TypeMismatch(List(SchemaType.Null), List(SchemaType.String)) + )) + assert(compare(opaqueSchema.nullable, opaqueSchema) == List( + GeneralSchemaMismatch(opaqueSchema.nullable, opaqueSchema) //TODO better issue? + )) + assert(compare(ref("String").nullable, ref("String")) == List( + GeneralSchemaMismatch(ref("String").nullable, stringSchema) //TODO better issue? + )) + } + test("enum and const mismatch") { def enums(values: Any*): List[ExampleSingleValue] = values.toList.map(ExampleSingleValue)