Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Jul 25, 2024
1 parent 3c45153 commit 5f71bdc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 8 additions & 1 deletion core/src/test/scala/sttp/tapir/SchemaMacroTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
}
}

Expand Down
18 changes: 15 additions & 3 deletions core/src/test/scala/sttp/tapir/generic/SchemaGenericAutoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
),
Expand All @@ -254,15 +260,21 @@ 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"))
),
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"))
Expand Down

0 comments on commit 5f71bdc

Please sign in to comment.