From 5f71bdc6b980b9135611401cc35aa8f3ac2542a4 Mon Sep 17 00:00:00 2001 From: adamw Date: Thu, 25 Jul 2024 16:47:24 +0200 Subject: [PATCH] Fix unit tests --- .../scala/sttp/tapir/SchemaMacroTest.scala | 9 ++++++++- .../tapir/generic/SchemaGenericAutoTest.scala | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala b/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala index 2b3df4fa97..c5b77ab228 100644 --- a/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala +++ b/core/src/test/scala/sttp/tapir/SchemaMacroTest.scala @@ -304,7 +304,14 @@ class SchemaMacroTest extends AnyFlatSpec with Matchers with TableDrivenProperty schemaType.subtypes.foreach { childSchema => val childProduct = childSchema.schemaType.asInstanceOf[SProduct[_]] - childProduct.fields.find(_.name.name == "kind") shouldBe Some(SProductField(FieldName("kind"), Schema.string, (_: Any) => None)) + val discValue = if (childSchema.name.get.fullName == "sttp.tapir.SchemaMacroTestData.User") "user" else "org" + childProduct.fields.find(_.name.name == "kind") shouldBe Some( + SProductField( + FieldName("kind"), + Schema.string.attribute(Schema.EncodedDiscriminatorValue.Attribute, Schema.EncodedDiscriminatorValue(discValue)), + (_: Any) => None + ) + ) } } diff --git a/core/src/test/scala/sttp/tapir/generic/SchemaGenericAutoTest.scala b/core/src/test/scala/sttp/tapir/generic/SchemaGenericAutoTest.scala index 311ee9e6b1..fd4d50636e 100644 --- a/core/src/test/scala/sttp/tapir/generic/SchemaGenericAutoTest.scala +++ b/core/src/test/scala/sttp/tapir/generic/SchemaGenericAutoTest.scala @@ -245,7 +245,13 @@ class SchemaGenericAutoTest extends AsyncFlatSpec with Matchers { schemaType.asInstanceOf[SCoproduct[Entity]].subtypes should contain theSameElementsAs List( Schema( SProduct[Organization]( - List(field(FieldName("name"), Schema(SString())), field(FieldName("who_am_i"), Schema(SString()))) + List( + field(FieldName("name"), Schema(SString())), + field( + FieldName("who_am_i"), + Schema(SString()).attribute(Schema.EncodedDiscriminatorValue.Attribute, Schema.EncodedDiscriminatorValue("Organization")) + ) + ) ), Some(SName("sttp.tapir.generic.Organization")) ), @@ -254,7 +260,10 @@ class SchemaGenericAutoTest extends AsyncFlatSpec with Matchers { List( field(FieldName("first"), Schema(SString())), field(FieldName("age"), Schema(SInteger(), format = Some("int32"))), - field(FieldName("who_am_i"), Schema(SString())) + field( + FieldName("who_am_i"), + Schema(SString()).attribute(Schema.EncodedDiscriminatorValue.Attribute, Schema.EncodedDiscriminatorValue("Person")) + ) ) ), Some(SName("sttp.tapir.generic.Person")) @@ -262,7 +271,10 @@ class SchemaGenericAutoTest extends AsyncFlatSpec with Matchers { Schema( SProduct[UnknownEntity.type]( List( - field(FieldName("who_am_i"), Schema(SString())) + field( + FieldName("who_am_i"), + Schema(SString()).attribute(Schema.EncodedDiscriminatorValue.Attribute, Schema.EncodedDiscriminatorValue("UnknownEntity")) + ) ) ), Some(SName("sttp.tapir.generic.UnknownEntity"))