-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter mixins that have different types (#1510)
* Filter mixins that have different types Similar to what was done in #425, I've filtered out the mixins that have different type than the final shape they're applied to. As such, in the example above, `HasName` has a optional name member where as `Person` inherits the mixin but makes the member required. The filtering catches that and as a result the mixin is removed from the list of mixins to add on `Person`. This behaviour aligns with the behaviour that happens when no `@adt` trait is added and `Person` is code generated on it's own. In both cases, now, the trait `HasName` is not extended because the types of `name` don't align.
- Loading branch information
1 parent
001bb47
commit 5480e8e
Showing
5 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
modules/bootstrapped/src/generated/smithy4s/example/HasName.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package smithy4s.example | ||
|
||
|
||
trait HasName { | ||
def name: Option[String] | ||
} |
67 changes: 67 additions & 0 deletions
67
modules/bootstrapped/src/generated/smithy4s/example/PersonUnion.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.string | ||
import smithy4s.schema.Schema.struct | ||
import smithy4s.schema.Schema.union | ||
|
||
sealed trait PersonUnion extends scala.Product with scala.Serializable { self => | ||
@inline final def widen: PersonUnion = this | ||
def $ordinal: Int | ||
|
||
object project { | ||
def p: Option[PersonUnion.OtherPerson] = PersonUnion.OtherPerson.alt.project.lift(self) | ||
} | ||
|
||
def accept[A](visitor: PersonUnion.Visitor[A]): A = this match { | ||
case value: PersonUnion.OtherPerson => visitor.p(value) | ||
} | ||
} | ||
object PersonUnion extends ShapeTag.Companion[PersonUnion] { | ||
|
||
def otherPerson(name: String):OtherPerson = OtherPerson(name) | ||
|
||
val id: ShapeId = ShapeId("smithy4s.example", "PersonUnion") | ||
|
||
val hints: Hints = Hints.empty | ||
|
||
final case class OtherPerson(name: String) extends PersonUnion { | ||
def $ordinal: Int = 0 | ||
} | ||
|
||
object OtherPerson extends ShapeTag.Companion[OtherPerson] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "OtherPerson") | ||
|
||
val hints: Hints = Hints.empty | ||
|
||
// constructor using the original order from the spec | ||
private def make(name: String): OtherPerson = OtherPerson(name) | ||
|
||
val schema: Schema[OtherPerson] = struct( | ||
string.required[OtherPerson]("name", _.name), | ||
)(make).withId(id).addHints(hints) | ||
|
||
val alt = schema.oneOf[PersonUnion]("p") | ||
} | ||
|
||
|
||
trait Visitor[A] { | ||
def p(value: PersonUnion.OtherPerson): A | ||
} | ||
|
||
object Visitor { | ||
trait Default[A] extends Visitor[A] { | ||
def default: A | ||
def p(value: PersonUnion.OtherPerson): A = default | ||
} | ||
} | ||
|
||
implicit val schema: Schema[PersonUnion] = union( | ||
PersonUnion.OtherPerson.alt, | ||
){ | ||
_.$ordinal | ||
}.withId(id).addHints(hints) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters