-
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.
Merge pull request #1432 from disneystreaming/enable-alloy.proto
Enable code generation of alloy.proto in core
- Loading branch information
Showing
35 changed files
with
1,037 additions
and
5 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
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
25 changes: 25 additions & 0 deletions
25
modules/bootstrapped/src/generated/smithy4s/example/BigDecimalWrapper.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,25 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.bigdecimal | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class BigDecimalWrapper(bigDecimal: BigDecimal) | ||
|
||
object BigDecimalWrapper extends ShapeTag.Companion[BigDecimalWrapper] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "BigDecimalWrapper") | ||
|
||
val hints: Hints = Hints( | ||
alloy.proto.ProtoEnabled(), | ||
).lazily | ||
|
||
// constructor using the original order from the spec | ||
private def make(bigDecimal: BigDecimal): BigDecimalWrapper = BigDecimalWrapper(bigDecimal) | ||
|
||
implicit val schema: Schema[BigDecimalWrapper] = struct( | ||
bigdecimal.required[BigDecimalWrapper]("bigDecimal", _.bigDecimal).addHints(alloy.proto.ProtoIndex(1)), | ||
)(make).withId(id).addHints(hints) | ||
} |
38 changes: 38 additions & 0 deletions
38
modules/bootstrapped/src/generated/smithy4s/example/ClosedInt.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,38 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Enumeration | ||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.EnumTag | ||
import smithy4s.schema.Schema.enumeration | ||
|
||
sealed abstract class ClosedInt(_value: String, _name: String, _intValue: Int, _hints: Hints) extends Enumeration.Value { | ||
override type EnumType = ClosedInt | ||
override val value: String = _value | ||
override val name: String = _name | ||
override val intValue: Int = _intValue | ||
override val hints: Hints = _hints | ||
override def enumeration: Enumeration[EnumType] = ClosedInt | ||
@inline final def widen: ClosedInt = this | ||
} | ||
object ClosedInt extends Enumeration[ClosedInt] with ShapeTag.Companion[ClosedInt] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "ClosedInt") | ||
|
||
val hints: Hints = Hints.empty | ||
|
||
case object FOO extends ClosedInt("FOO", "FOO", 0, Hints.empty) { | ||
override val hints: Hints = Hints(alloy.proto.ProtoIndex(0)).lazily | ||
} | ||
case object BAR extends ClosedInt("BAR", "BAR", 1, Hints.empty) { | ||
override val hints: Hints = Hints(alloy.proto.ProtoIndex(1)).lazily | ||
} | ||
|
||
val values: List[ClosedInt] = List( | ||
FOO, | ||
BAR, | ||
) | ||
val tag: EnumTag[ClosedInt] = EnumTag.ClosedIntEnum | ||
implicit val schema: Schema[ClosedInt] = enumeration(tag, values).withId(id).addHints(hints) | ||
} |
38 changes: 38 additions & 0 deletions
38
modules/bootstrapped/src/generated/smithy4s/example/ClosedString.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,38 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Enumeration | ||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.EnumTag | ||
import smithy4s.schema.Schema.enumeration | ||
|
||
sealed abstract class ClosedString(_value: String, _name: String, _intValue: Int, _hints: Hints) extends Enumeration.Value { | ||
override type EnumType = ClosedString | ||
override val value: String = _value | ||
override val name: String = _name | ||
override val intValue: Int = _intValue | ||
override val hints: Hints = _hints | ||
override def enumeration: Enumeration[EnumType] = ClosedString | ||
@inline final def widen: ClosedString = this | ||
} | ||
object ClosedString extends Enumeration[ClosedString] with ShapeTag.Companion[ClosedString] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "ClosedString") | ||
|
||
val hints: Hints = Hints.empty | ||
|
||
case object FOO extends ClosedString("FOO", "FOO", 0, Hints.empty) { | ||
override val hints: Hints = Hints(alloy.proto.ProtoIndex(0)).lazily | ||
} | ||
case object BAR extends ClosedString("BAR", "BAR", 1, Hints.empty) { | ||
override val hints: Hints = Hints(alloy.proto.ProtoIndex(1)).lazily | ||
} | ||
|
||
val values: List[ClosedString] = List( | ||
FOO, | ||
BAR, | ||
) | ||
val tag: EnumTag[ClosedString] = EnumTag.ClosedStringEnum | ||
implicit val schema: Schema[ClosedString] = enumeration(tag, values).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
27 changes: 27 additions & 0 deletions
27
modules/bootstrapped/src/generated/smithy4s/example/Enums.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,27 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class Enums(closedString: ClosedString, openString: OpenString, closedInt: ClosedInt, openInt: OpenInt) | ||
|
||
object Enums extends ShapeTag.Companion[Enums] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "Enums") | ||
|
||
val hints: Hints = Hints( | ||
alloy.proto.ProtoEnabled(), | ||
).lazily | ||
|
||
// constructor using the original order from the spec | ||
private def make(closedString: ClosedString, openString: OpenString, closedInt: ClosedInt, openInt: OpenInt): Enums = Enums(closedString, openString, closedInt, openInt) | ||
|
||
implicit val schema: Schema[Enums] = struct( | ||
ClosedString.schema.required[Enums]("closedString", _.closedString).addHints(alloy.proto.ProtoIndex(1)), | ||
OpenString.schema.required[Enums]("openString", _.openString).addHints(alloy.proto.ProtoIndex(2)), | ||
ClosedInt.schema.required[Enums]("closedInt", _.closedInt).addHints(alloy.proto.ProtoIndex(3)), | ||
OpenInt.schema.required[Enums]("openInt", _.openInt).addHints(alloy.proto.ProtoIndex(4)), | ||
)(make).withId(id).addHints(hints) | ||
} |
24 changes: 24 additions & 0 deletions
24
modules/bootstrapped/src/generated/smithy4s/example/InlinedUnionWrapper.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,24 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class InlinedUnionWrapper(myInlinedUnion: Option[MyInlinedUnion] = None) | ||
|
||
object InlinedUnionWrapper extends ShapeTag.Companion[InlinedUnionWrapper] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "InlinedUnionWrapper") | ||
|
||
val hints: Hints = Hints( | ||
alloy.proto.ProtoEnabled(), | ||
).lazily | ||
|
||
// constructor using the original order from the spec | ||
private def make(myInlinedUnion: Option[MyInlinedUnion]): InlinedUnionWrapper = InlinedUnionWrapper(myInlinedUnion) | ||
|
||
implicit val schema: Schema[InlinedUnionWrapper] = struct( | ||
MyInlinedUnion.schema.optional[InlinedUnionWrapper]("myInlinedUnion", _.myInlinedUnion), | ||
)(make).withId(id).addHints(hints) | ||
} |
24 changes: 24 additions & 0 deletions
24
modules/bootstrapped/src/generated/smithy4s/example/IntListWrapper.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,24 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class IntListWrapper(ints: IntList) | ||
|
||
object IntListWrapper extends ShapeTag.Companion[IntListWrapper] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "IntListWrapper") | ||
|
||
val hints: Hints = Hints( | ||
alloy.proto.ProtoEnabled(), | ||
).lazily | ||
|
||
// constructor using the original order from the spec | ||
private def make(ints: IntList): IntListWrapper = IntListWrapper(ints) | ||
|
||
implicit val schema: Schema[IntListWrapper] = struct( | ||
IntList.schema.required[IntListWrapper]("ints", _.ints).addHints(alloy.proto.ProtoIndex(1)), | ||
)(make).withId(id).addHints(hints) | ||
} |
29 changes: 29 additions & 0 deletions
29
modules/bootstrapped/src/generated/smithy4s/example/Integers.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,29 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.int | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class Integers(int: Int, sint: Int, uint: Int, fixedUint: Int, fixedSint: Int) | ||
|
||
object Integers extends ShapeTag.Companion[Integers] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "Integers") | ||
|
||
val hints: Hints = Hints( | ||
alloy.proto.ProtoEnabled(), | ||
).lazily | ||
|
||
// constructor using the original order from the spec | ||
private def make(int: Int, sint: Int, uint: Int, fixedUint: Int, fixedSint: Int): Integers = Integers(int, sint, uint, fixedUint, fixedSint) | ||
|
||
implicit val schema: Schema[Integers] = struct( | ||
int.required[Integers]("int", _.int).addHints(alloy.proto.ProtoIndex(1)), | ||
int.required[Integers]("sint", _.sint).addHints(alloy.proto.ProtoNumType.SIGNED.widen, alloy.proto.ProtoIndex(2)), | ||
int.required[Integers]("uint", _.uint).addHints(alloy.proto.ProtoNumType.UNSIGNED.widen, alloy.proto.ProtoIndex(3)), | ||
int.required[Integers]("fixedUint", _.fixedUint).addHints(alloy.proto.ProtoNumType.FIXED.widen, alloy.proto.ProtoIndex(4)), | ||
int.required[Integers]("fixedSint", _.fixedSint).addHints(alloy.proto.ProtoNumType.FIXED_SIGNED.widen, alloy.proto.ProtoIndex(5)), | ||
)(make).withId(id).addHints(hints) | ||
} |
29 changes: 29 additions & 0 deletions
29
modules/bootstrapped/src/generated/smithy4s/example/Longs.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,29 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.long | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class Longs(long: Long, slong: Long, ulong: Long, fixedLong: Long, fixedSlong: Long) | ||
|
||
object Longs extends ShapeTag.Companion[Longs] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "Longs") | ||
|
||
val hints: Hints = Hints( | ||
alloy.proto.ProtoEnabled(), | ||
).lazily | ||
|
||
// constructor using the original order from the spec | ||
private def make(long: Long, slong: Long, ulong: Long, fixedLong: Long, fixedSlong: Long): Longs = Longs(long, slong, ulong, fixedLong, fixedSlong) | ||
|
||
implicit val schema: Schema[Longs] = struct( | ||
long.required[Longs]("long", _.long).addHints(alloy.proto.ProtoIndex(1)), | ||
long.required[Longs]("slong", _.slong).addHints(alloy.proto.ProtoNumType.SIGNED.widen, alloy.proto.ProtoIndex(2)), | ||
long.required[Longs]("ulong", _.ulong).addHints(alloy.proto.ProtoNumType.UNSIGNED.widen, alloy.proto.ProtoIndex(3)), | ||
long.required[Longs]("fixedLong", _.fixedLong).addHints(alloy.proto.ProtoNumType.FIXED.widen, alloy.proto.ProtoIndex(4)), | ||
long.required[Longs]("fixedSlong", _.fixedSlong).addHints(alloy.proto.ProtoNumType.FIXED_SIGNED.widen, alloy.proto.ProtoIndex(5)), | ||
)(make).withId(id).addHints(hints) | ||
} |
24 changes: 24 additions & 0 deletions
24
modules/bootstrapped/src/generated/smithy4s/example/MessageWrapper.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,24 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class MessageWrapper(message: Integers) | ||
|
||
object MessageWrapper extends ShapeTag.Companion[MessageWrapper] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "MessageWrapper") | ||
|
||
val hints: Hints = Hints( | ||
alloy.proto.ProtoEnabled(), | ||
).lazily | ||
|
||
// constructor using the original order from the spec | ||
private def make(message: Integers): MessageWrapper = MessageWrapper(message) | ||
|
||
implicit val schema: Schema[MessageWrapper] = struct( | ||
Integers.schema.required[MessageWrapper]("message", _.message).addHints(alloy.proto.ProtoIndex(1)), | ||
)(make).withId(id).addHints(hints) | ||
} |
73 changes: 73 additions & 0 deletions
73
modules/bootstrapped/src/generated/smithy4s/example/MyInlinedUnion.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,73 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.bijection | ||
import smithy4s.schema.Schema.boolean | ||
import smithy4s.schema.Schema.union | ||
|
||
sealed trait MyInlinedUnion extends scala.Product with scala.Serializable { self => | ||
@inline final def widen: MyInlinedUnion = this | ||
def $ordinal: Int | ||
|
||
object project { | ||
def int: Option[Int] = MyInlinedUnion.IntCase.alt.project.lift(self).map(_.int) | ||
def bool: Option[Boolean] = MyInlinedUnion.BoolCase.alt.project.lift(self).map(_.bool) | ||
} | ||
|
||
def accept[A](visitor: MyInlinedUnion.Visitor[A]): A = this match { | ||
case value: MyInlinedUnion.IntCase => visitor.int(value.int) | ||
case value: MyInlinedUnion.BoolCase => visitor.bool(value.bool) | ||
} | ||
} | ||
object MyInlinedUnion extends ShapeTag.Companion[MyInlinedUnion] { | ||
|
||
def int(int: Int): MyInlinedUnion = IntCase(int) | ||
def bool(bool: Boolean): MyInlinedUnion = BoolCase(bool) | ||
|
||
val id: ShapeId = ShapeId("smithy4s.example", "MyInlinedUnion") | ||
|
||
val hints: Hints = Hints( | ||
alloy.proto.ProtoInlinedOneOf(), | ||
).lazily | ||
|
||
final case class IntCase(int: Int) extends MyInlinedUnion { final def $ordinal: Int = 0 } | ||
final case class BoolCase(bool: Boolean) extends MyInlinedUnion { final def $ordinal: Int = 1 } | ||
|
||
object IntCase { | ||
val hints: Hints = Hints( | ||
alloy.proto.ProtoIndex(1), | ||
).lazily | ||
val schema: Schema[MyInlinedUnion.IntCase] = bijection(smithy4s.schema.Schema.int.addHints(hints), MyInlinedUnion.IntCase(_), _.int) | ||
val alt = schema.oneOf[MyInlinedUnion]("int") | ||
} | ||
object BoolCase { | ||
val hints: Hints = Hints( | ||
alloy.proto.ProtoIndex(2), | ||
).lazily | ||
val schema: Schema[MyInlinedUnion.BoolCase] = bijection(boolean.addHints(hints), MyInlinedUnion.BoolCase(_), _.bool) | ||
val alt = schema.oneOf[MyInlinedUnion]("bool") | ||
} | ||
|
||
trait Visitor[A] { | ||
def int(value: Int): A | ||
def bool(value: Boolean): A | ||
} | ||
|
||
object Visitor { | ||
trait Default[A] extends Visitor[A] { | ||
def default: A | ||
def int(value: Int): A = default | ||
def bool(value: Boolean): A = default | ||
} | ||
} | ||
|
||
implicit val schema: Schema[MyInlinedUnion] = union( | ||
MyInlinedUnion.IntCase.alt, | ||
MyInlinedUnion.BoolCase.alt, | ||
){ | ||
_.$ordinal | ||
}.withId(id).addHints(hints) | ||
} |
15 changes: 15 additions & 0 deletions
15
modules/bootstrapped/src/generated/smithy4s/example/MyInt.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,15 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Newtype | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.schema.Schema.bijection | ||
import smithy4s.schema.Schema.int | ||
|
||
object MyInt extends Newtype[Int] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "MyInt") | ||
val hints: Hints = Hints.empty | ||
val underlyingSchema: Schema[Int] = int.withId(id).addHints(hints) | ||
implicit val schema: Schema[MyInt] = bijection(underlyingSchema, asBijection) | ||
} |
15 changes: 15 additions & 0 deletions
15
modules/bootstrapped/src/generated/smithy4s/example/MyIntList.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,15 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Newtype | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.schema.Schema.bijection | ||
import smithy4s.schema.Schema.list | ||
|
||
object MyIntList extends Newtype[List[MyInt]] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "MyIntList") | ||
val hints: Hints = Hints.empty | ||
val underlyingSchema: Schema[List[MyInt]] = list(MyInt.schema).withId(id).addHints(hints) | ||
implicit val schema: Schema[MyIntList] = bijection(underlyingSchema, asBijection) | ||
} |
Oops, something went wrong.