diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f0fbfb14..fd823546a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 0.18.13 +* Enable generation of protobuf specifications from smithy specifications. * modify logic to guarantee that rendered and dynamic enum values respect the ordering from the specification. # 0.18.12 diff --git a/build.sbt b/build.sbt index 7ca7ffaaf..06067485e 100644 --- a/build.sbt +++ b/build.sbt @@ -371,6 +371,7 @@ lazy val codegen = projectMatrix Dependencies.Smithy.build, Dependencies.Alloy.core, Dependencies.Alloy.openapi, + Dependencies.Smithytranslate.proto, "com.lihaoyi" %% "os-lib" % "0.9.3", "com.lihaoyi" %% "upickle" % "3.1.5", Dependencies.collectionsCompat.value, @@ -834,6 +835,11 @@ lazy val complianceTests = projectMatrix lazy val exampleGeneratedOutput = settingKey[File]("Output directory where the generated code is going to be.") +lazy val exampleGeneratedResourcesOutput = + settingKey[File]( + "Output directory where the generated resources are going to be." + ) + /** * A project that contains generated code, which can serve as a basis for tests. */ @@ -845,7 +851,11 @@ lazy val bootstrapped = projectMatrix .settings( Test / fork := true, exampleGeneratedOutput := (ThisBuild / baseDirectory).value / "modules" / "bootstrapped" / "src" / "generated", - cleanFiles += exampleGeneratedOutput.value, + exampleGeneratedResourcesOutput := (Compile / resourceDirectory).value, + cleanFiles ++= Seq( + exampleGeneratedOutput.value, + exampleGeneratedResourcesOutput.value + ), smithy4sDependencies ++= Seq( Dependencies.Smithy.testTraits, Dependencies.Smithy.awsTraits, @@ -867,6 +877,7 @@ lazy val bootstrapped = projectMatrix "smithy4s.example.hello", "smithy4s.example.test", "smithy4s.example.package", + "smithy4s.example.protobuf", "weather", "smithy4s.example.product", "smithy4s.example.reservedNameOverride" @@ -878,7 +889,7 @@ lazy val bootstrapped = projectMatrix libraryDependencies += Dependencies.Http4s.emberServer.value, genSmithy(Compile), genSmithyOutput := exampleGeneratedOutput.value, - genSmithyResourcesOutput := (Compile / resourceDirectory).value, + genSmithyResourcesOutput := exampleGeneratedResourcesOutput.value, smithy4sSkip := List("resource"), // Ignore deprecation warnings here - it's all generated code, anyway. scalacOptions ++= Seq( diff --git a/modules/bootstrapped/resources/smithy4s.example.ReservedNameService.json b/modules/bootstrapped/resources/smithy4s.example.ReservedNameService.json deleted file mode 100644 index 013edfd7c..000000000 --- a/modules/bootstrapped/resources/smithy4s.example.ReservedNameService.json +++ /dev/null @@ -1,129 +0,0 @@ -{ - "openapi": "3.0.2", - "info": { - "title": "ReservedNameService", - "version": "1.0.0" - }, - "paths": { - "/api/list/{value}": { - "post": { - "operationId": "List", - "parameters": [ - { - "name": "value", - "in": "path", - "schema": { - "type": "integer", - "format": "int32" - }, - "required": true - } - ], - "responses": { - "204": { - "description": "List 204 response" - } - } - } - }, - "/api/map/": { - "post": { - "operationId": "Map", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/MapRequestContent" - } - } - }, - "required": true - }, - "responses": { - "204": { - "description": "Map 204 response" - } - } - } - }, - "/api/option/{value}": { - "post": { - "operationId": "Option", - "parameters": [ - { - "name": "value", - "in": "path", - "schema": { - "type": "integer", - "format": "int32" - }, - "required": true - } - ], - "responses": { - "204": { - "description": "Option 204 response" - } - } - } - }, - "/api/set/": { - "post": { - "operationId": "Set", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/SetRequestContent" - } - } - }, - "required": true - }, - "responses": { - "204": { - "description": "Set 204 response" - } - } - } - } - }, - "components": { - "schemas": { - "MapRequestContent": { - "type": "object", - "properties": { - "value": { - "$ref": "#/components/schemas/myMap" - } - }, - "required": [ - "value" - ] - }, - "SetRequestContent": { - "type": "object", - "properties": { - "set": { - "type": "array", - "items": { - "type": "integer", - "format": "int32" - }, - "uniqueItems": true - } - }, - "required": [ - "set" - ] - }, - "myMap": { - "type": "object", - "additionalProperties": { - "type": "integer", - "format": "int32" - } - } - } - } -} \ No newline at end of file diff --git a/modules/bootstrapped/resources/smithy4s.example.product.ObjectService.json b/modules/bootstrapped/resources/smithy4s.example.product.ObjectService.json deleted file mode 100644 index 694658864..000000000 --- a/modules/bootstrapped/resources/smithy4s.example.product.ObjectService.json +++ /dev/null @@ -1,154 +0,0 @@ -{ - "openapi": "3.0.2", - "info": { - "title": "ObjectService", - "version": "1.0.0" - }, - "paths": { - "/{bucketName}/{key}": { - "put": { - "operationId": "PutObject", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/PutObjectInputPayload" - } - } - }, - "required": true - }, - "parameters": [ - { - "name": "key", - "in": "path", - "schema": { - "type": "string" - }, - "required": true - }, - { - "name": "bucketName", - "in": "path", - "schema": { - "type": "string" - }, - "required": true - }, - { - "name": "paramName", - "in": "query", - "schema": { - "type": "string" - } - }, - { - "name": "X-Foo", - "in": "header", - "schema": { - "$ref": "#/components/schemas/LowHigh" - } - } - ], - "responses": { - "200": { - "description": "PutObject 200 response" - }, - "507": { - "description": "NoMoreSpace 507 response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/NoMoreSpaceResponseContent" - } - } - } - } - } - } - } - }, - "components": { - "schemas": { - "Foo": { - "description": "Helpful information for Foo\nint, bigInt and bDec are useful number constructs\nThe string case is there because.", - "oneOf": [ - { - "type": "object", - "title": "int", - "properties": { - "int": { - "type": "integer", - "format": "int32" - } - }, - "required": [ - "int" - ] - }, - { - "type": "object", - "title": "str", - "properties": { - "str": { - "type": "string", - "description": "this is a comment saying you should be careful for this case\nyou never know what lies ahead with Strings like this" - } - }, - "required": [ - "str" - ] - }, - { - "type": "object", - "title": "bInt", - "properties": { - "bInt": { - "type": "number" - } - }, - "required": [ - "bInt" - ] - }, - { - "type": "object", - "title": "bDec", - "properties": { - "bDec": { - "type": "number" - } - }, - "required": [ - "bDec" - ] - } - ] - }, - "LowHigh": { - "type": "string", - "enum": [ - "Low", - "High" - ] - }, - "NoMoreSpaceResponseContent": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "foo": { - "$ref": "#/components/schemas/Foo" - } - }, - "required": [ - "message" - ] - }, - "PutObjectInputPayload": { - "type": "string" - } - } - } -} \ No newline at end of file diff --git a/modules/bootstrapped/resources/smithy4s.hello.HelloWorldService.json b/modules/bootstrapped/resources/smithy4s.hello.HelloWorldService.json deleted file mode 100644 index 853353a26..000000000 --- a/modules/bootstrapped/resources/smithy4s.hello.HelloWorldService.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "openapi": "3.0.2", - "info": { - "title": "HelloWorldService", - "version": "1.0.0" - }, - "paths": { - "/{name}": { - "post": { - "operationId": "Hello", - "parameters": [ - { - "name": "name", - "in": "path", - "schema": { - "type": "string" - }, - "required": true - }, - { - "name": "town", - "in": "query", - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "Hello 200 response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HelloResponseContent" - } - } - } - }, - "500": { - "description": "GenericServerError 500 response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/GenericServerErrorResponseContent" - } - } - } - } - }, - "tags": [ - "testOperationTag" - ] - } - } - }, - "components": { - "schemas": { - "GenericServerErrorResponseContent": { - "type": "object", - "properties": { - "message": { - "type": "string" - } - } - }, - "HelloResponseContent": { - "type": "object", - "properties": { - "message": { - "type": "string" - } - }, - "required": [ - "message" - ] - } - } - } -} \ No newline at end of file diff --git a/modules/bootstrapped/resources/smithy4s/example/protobuf/protobuf.proto b/modules/bootstrapped/resources/smithy4s/example/protobuf/protobuf.proto new file mode 100644 index 000000000..85c04745e --- /dev/null +++ b/modules/bootstrapped/resources/smithy4s/example/protobuf/protobuf.proto @@ -0,0 +1,150 @@ +syntax = "proto3"; + +package smithy4s.example.protobuf; + +import "google/protobuf/wrappers.proto"; + +import "alloy/protobuf/types.proto"; + +message Integers { + int32 int = 1; + sint32 sint = 2; + uint32 uint = 3; + fixed32 fixedUint = 4; + sfixed32 fixedSint = 5; +} + +message Longs { + int64 long = 1; + sint64 slong = 2; + uint64 ulong = 3; + fixed64 fixedLong = 4; + sfixed64 fixedSlong = 5; +} + +message OtherScalars { + bool boolean = 1; + int32 byte = 2; + float float = 3; + double double = 4; + int32 short = 5; +} + +message WrappedScalars { + google.protobuf.Int32Value int = 1; + google.protobuf.BoolValue bool = 2; +} + +message StringWrapper { + string string = 1; +} + +message OptionalStringWrapper { + string string = 1; +} + +message BigDecimalWrapper { + string bigDecimal = 1; +} + +message UUIDWrapper { + string uuid = 1; + alloy.protobuf.CompactUUID compactUUID = 2; +} + +message MessageWrapper { + smithy4s.example.protobuf.Integers message = 1; +} + +message OptionalMessageWrapper { + smithy4s.example.protobuf.Integers message = 1; +} + +message IntListWrapper { + repeated int32 ints = 1; +} + +message WrappedStringList { + repeated string value = 1; +} + +message StringListWrapper { + repeated string strings = 1; + smithy4s.example.protobuf.WrappedStringList wrappedStrings = 2; +} + +message MyIntList { + repeated int32 value = 1; +} + +message MyIntListWrapper { + repeated int32 ints = 1; +} + +message Recursive { + smithy4s.example.protobuf.Recursive recursive = 1; +} + +message UnionWrapper { + smithy4s.example.protobuf.MyUnion myUnion = 1; +} + +message MyUnion { + oneof definition { + int32 int = 1; + bool bool = 2; + smithy4s.example.protobuf.MyIntList list = 3; + smithy4s.example.protobuf.StringMap map = 4; + } +} + +message InlinedUnionWrapper { + oneof myInlinedUnion { + int32 int = 1; + bool bool = 2; + } +} + +message StringMapWrapper { + map values = 1; +} + +message StringMap { + map value = 1; +} + +message Enums { + smithy4s.example.protobuf.ClosedString closedString = 1; + string openString = 2; + smithy4s.example.protobuf.ClosedInt closedInt = 3; + int32 openInt = 4; +} + +enum ClosedString { + CLOSEDSTRING_FOO = 0; + CLOSEDSTRING_BAR = 1; +} + +enum ClosedInt { + CLOSEDINT_FOO = 0; + CLOSEDINT_BAR = 1; +} + +message RefinedIntWrapped { + int32 int = 1; +} + +message StructureWithCustomIndexes { + int32 a = 4; + int32 b = 3; + int32 c = 2; + smithy4s.example.protobuf.UnionWithCustomIndexes d = 1; +} + +message UnionWithCustomIndexes { + oneof definition { + int32 a = 3; + int32 b = 2; + int32 c = 1; + } +} diff --git a/modules/bootstrapped/src/generated/smithy4s/example/Other.scala b/modules/bootstrapped/src/generated/smithy4s/example/Other.scala deleted file mode 100644 index 87bc8d3cc..000000000 --- a/modules/bootstrapped/src/generated/smithy4s/example/Other.scala +++ /dev/null @@ -1,30 +0,0 @@ -package smithy4s.example - -import java.util.UUID -import smithy4s.Hints -import smithy4s.Schema -import smithy4s.ShapeId -import smithy4s.ShapeTag -import smithy4s.schema.Schema.bigdecimal -import smithy4s.schema.Schema.bigint -import smithy4s.schema.Schema.struct -import smithy4s.schema.Schema.uuid - -final case class Other(bigDecimal: BigDecimal, bigInteger: BigInt, uuid: UUID) - -object Other extends ShapeTag.Companion[Other] { - val id: ShapeId = ShapeId("smithy4s.example", "Other") - - val hints: Hints = Hints( - alloy.proto.ProtoEnabled(), - ).lazily - - // constructor using the original order from the spec - private def make(bigDecimal: BigDecimal, bigInteger: BigInt, uuid: UUID): Other = Other(bigDecimal, bigInteger, uuid) - - implicit val schema: Schema[Other] = struct( - bigdecimal.required[Other]("bigDecimal", _.bigDecimal).addHints(alloy.proto.ProtoIndex(3)), - bigint.required[Other]("bigInteger", _.bigInteger).addHints(alloy.proto.ProtoIndex(4)), - uuid.required[Other]("uuid", _.uuid).addHints(alloy.proto.ProtoIndex(5)), - )(make).withId(id).addHints(hints) -} diff --git a/modules/bootstrapped/src/generated/smithy4s/example/package.scala b/modules/bootstrapped/src/generated/smithy4s/example/package.scala index dfb58c344..982e15c73 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/package.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/package.scala @@ -41,14 +41,12 @@ package object example { type Weather[F[_]] = smithy4s.kinds.FunctorAlgebra[WeatherGen, F] val Weather = WeatherGen - type MyIntList = smithy4s.example.MyIntList.Type type PublishersList = smithy4s.example.PublishersList.Type type TestString = smithy4s.example.TestString.Type type ArbitraryData = smithy4s.example.ArbitraryData.Type type PersonPhoneNumber = smithy4s.example.PersonPhoneNumber.Type type CSV = smithy4s.example.CSV.Type type CityId = smithy4s.example.CityId.Type - type WrappedStringList = smithy4s.example.WrappedStringList.Type type PersonAge = smithy4s.example.PersonAge.Type @deprecated(message = "N/A", since = "N/A") type DeprecatedString = smithy4s.example.DeprecatedString.Type @@ -103,7 +101,6 @@ package object example { type StreamedBlob = smithy4s.example.StreamedBlob.Type type TestIdRefValueMap = smithy4s.example.TestIdRefValueMap.Type type PNG = smithy4s.example.PNG.Type - type MyInt = smithy4s.example.MyInt.Type type StringWithEnumTraits = smithy4s.example.StringWithEnumTraits.Type type Name = smithy4s.example.Name.Type type ObjectKey = smithy4s.example.ObjectKey.Type diff --git a/modules/bootstrapped/src/generated/smithy4s/example/BigDecimalWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/BigDecimalWrapper.scala similarity index 83% rename from modules/bootstrapped/src/generated/smithy4s/example/BigDecimalWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/BigDecimalWrapper.scala index 629c3efea..2d7da5ad7 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/BigDecimalWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/BigDecimalWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -10,7 +10,7 @@ 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 id: ShapeId = ShapeId("smithy4s.example.protobuf", "BigDecimalWrapper") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -20,6 +20,6 @@ object BigDecimalWrapper extends ShapeTag.Companion[BigDecimalWrapper] { private def make(bigDecimal: BigDecimal): BigDecimalWrapper = BigDecimalWrapper(bigDecimal) implicit val schema: Schema[BigDecimalWrapper] = struct( - bigdecimal.required[BigDecimalWrapper]("bigDecimal", _.bigDecimal).addHints(alloy.proto.ProtoIndex(1)), + bigdecimal.required[BigDecimalWrapper]("bigDecimal", _.bigDecimal), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/ClosedInt.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/ClosedInt.scala similarity index 92% rename from modules/bootstrapped/src/generated/smithy4s/example/ClosedInt.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/ClosedInt.scala index 003f9030c..e82f98e2b 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/ClosedInt.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/ClosedInt.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Enumeration import smithy4s.Hints @@ -18,7 +18,7 @@ sealed abstract class ClosedInt(_value: String, _name: String, _intValue: Int, _ @inline final def widen: ClosedInt = this } object ClosedInt extends Enumeration[ClosedInt] with ShapeTag.Companion[ClosedInt] { - val id: ShapeId = ShapeId("smithy4s.example", "ClosedInt") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "ClosedInt") val hints: Hints = Hints.empty diff --git a/modules/bootstrapped/src/generated/smithy4s/example/ClosedString.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/ClosedString.scala similarity index 81% rename from modules/bootstrapped/src/generated/smithy4s/example/ClosedString.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/ClosedString.scala index f004e2507..c387ee3c9 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/ClosedString.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/ClosedString.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Enumeration import smithy4s.Hints @@ -18,16 +18,12 @@ sealed abstract class ClosedString(_value: String, _name: String, _intValue: Int @inline final def widen: ClosedString = this } object ClosedString extends Enumeration[ClosedString] with ShapeTag.Companion[ClosedString] { - val id: ShapeId = ShapeId("smithy4s.example", "ClosedString") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "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 - } + case object FOO extends ClosedString("FOO", "FOO", 0, Hints.empty) + case object BAR extends ClosedString("BAR", "BAR", 1, Hints.empty) val values: List[ClosedString] = List( FOO, diff --git a/modules/bootstrapped/src/generated/smithy4s/example/protobuf/CompactUUID.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/CompactUUID.scala new file mode 100644 index 000000000..deac830cd --- /dev/null +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/CompactUUID.scala @@ -0,0 +1,19 @@ +package smithy4s.example.protobuf + +import java.util.UUID +import smithy4s.Hints +import smithy4s.Newtype +import smithy4s.Schema +import smithy4s.ShapeId +import smithy4s.schema.Schema.bijection +import smithy4s.schema.Schema.uuid + +object CompactUUID extends Newtype[UUID] { + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "CompactUUID") + val hints: Hints = Hints( + alloy.proto.ProtoCompactUUID(), + alloy.UuidFormat(), + ).lazily + val underlyingSchema: Schema[UUID] = uuid.withId(id).addHints(hints) + implicit val schema: Schema[CompactUUID] = bijection(underlyingSchema, asBijection) +} diff --git a/modules/bootstrapped/src/generated/smithy4s/example/Enums.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/Enums.scala similarity index 69% rename from modules/bootstrapped/src/generated/smithy4s/example/Enums.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/Enums.scala index 6ff6e1503..9c43962bd 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/Enums.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/Enums.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -9,7 +9,7 @@ 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 id: ShapeId = ShapeId("smithy4s.example.protobuf", "Enums") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -19,9 +19,9 @@ object Enums extends ShapeTag.Companion[Enums] { 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)), + ClosedString.schema.required[Enums]("closedString", _.closedString), + OpenString.schema.required[Enums]("openString", _.openString), + ClosedInt.schema.required[Enums]("closedInt", _.closedInt), + OpenInt.schema.required[Enums]("openInt", _.openInt), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/InlinedUnionWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/InlinedUnionWrapper.scala similarity index 86% rename from modules/bootstrapped/src/generated/smithy4s/example/InlinedUnionWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/InlinedUnionWrapper.scala index 2045024ed..c4c52cc25 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/InlinedUnionWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/InlinedUnionWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -9,7 +9,7 @@ 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 id: ShapeId = ShapeId("smithy4s.example.protobuf", "InlinedUnionWrapper") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), diff --git a/modules/bootstrapped/src/generated/smithy4s/example/protobuf/IntList.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/IntList.scala new file mode 100644 index 000000000..5e29e4e70 --- /dev/null +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/IntList.scala @@ -0,0 +1,16 @@ +package smithy4s.example.protobuf + +import smithy4s.Hints +import smithy4s.Newtype +import smithy4s.Schema +import smithy4s.ShapeId +import smithy4s.schema.Schema.bijection +import smithy4s.schema.Schema.int +import smithy4s.schema.Schema.list + +object IntList extends Newtype[List[Int]] { + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "IntList") + val hints: Hints = Hints.empty + val underlyingSchema: Schema[List[Int]] = list(int).withId(id).addHints(hints) + implicit val schema: Schema[IntList] = bijection(underlyingSchema, asBijection) +} diff --git a/modules/bootstrapped/src/generated/smithy4s/example/IntListWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/IntListWrapper.scala similarity index 58% rename from modules/bootstrapped/src/generated/smithy4s/example/IntListWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/IntListWrapper.scala index ff8cbb05a..d4e2b22d6 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/IntListWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/IntListWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -6,19 +6,19 @@ import smithy4s.ShapeId import smithy4s.ShapeTag import smithy4s.schema.Schema.struct -final case class IntListWrapper(ints: IntList) +final case class IntListWrapper(ints: List[Int]) object IntListWrapper extends ShapeTag.Companion[IntListWrapper] { - val id: ShapeId = ShapeId("smithy4s.example", "IntListWrapper") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "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) + private def make(ints: List[Int]): IntListWrapper = IntListWrapper(ints) implicit val schema: Schema[IntListWrapper] = struct( - IntList.schema.required[IntListWrapper]("ints", _.ints).addHints(alloy.proto.ProtoIndex(1)), + IntList.underlyingSchema.required[IntListWrapper]("ints", _.ints), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/Integers.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/Integers.scala similarity index 69% rename from modules/bootstrapped/src/generated/smithy4s/example/Integers.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/Integers.scala index e640d489e..f3ed157f2 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/Integers.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/Integers.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -10,7 +10,7 @@ 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 id: ShapeId = ShapeId("smithy4s.example.protobuf", "Integers") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -20,10 +20,10 @@ object Integers extends ShapeTag.Companion[Integers] { 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)), + int.required[Integers]("int", _.int), + int.required[Integers]("sint", _.sint).addHints(alloy.proto.ProtoNumType.SIGNED.widen), + int.required[Integers]("uint", _.uint).addHints(alloy.proto.ProtoNumType.UNSIGNED.widen), + int.required[Integers]("fixedUint", _.fixedUint).addHints(alloy.proto.ProtoNumType.FIXED.widen), + int.required[Integers]("fixedSint", _.fixedSint).addHints(alloy.proto.ProtoNumType.FIXED_SIGNED.widen), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/Longs.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/Longs.scala similarity index 69% rename from modules/bootstrapped/src/generated/smithy4s/example/Longs.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/Longs.scala index 4d193af2e..3130bf8a2 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/Longs.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/Longs.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -10,7 +10,7 @@ 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 id: ShapeId = ShapeId("smithy4s.example.protobuf", "Longs") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -20,10 +20,10 @@ object Longs extends ShapeTag.Companion[Longs] { 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)), + long.required[Longs]("long", _.long), + long.required[Longs]("slong", _.slong).addHints(alloy.proto.ProtoNumType.SIGNED.widen), + long.required[Longs]("ulong", _.ulong).addHints(alloy.proto.ProtoNumType.UNSIGNED.widen), + long.required[Longs]("fixedLong", _.fixedLong).addHints(alloy.proto.ProtoNumType.FIXED.widen), + long.required[Longs]("fixedSlong", _.fixedSlong).addHints(alloy.proto.ProtoNumType.FIXED_SIGNED.widen), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/MessageWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MessageWrapper.scala similarity index 82% rename from modules/bootstrapped/src/generated/smithy4s/example/MessageWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/MessageWrapper.scala index 3fbf71ba7..d8786998e 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/MessageWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MessageWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -9,7 +9,7 @@ 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 id: ShapeId = ShapeId("smithy4s.example.protobuf", "MessageWrapper") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -19,6 +19,6 @@ object MessageWrapper extends ShapeTag.Companion[MessageWrapper] { 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)), + Integers.schema.required[MessageWrapper]("message", _.message), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/MyInlinedUnion.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyInlinedUnion.scala similarity index 89% rename from modules/bootstrapped/src/generated/smithy4s/example/MyInlinedUnion.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyInlinedUnion.scala index da3e871c9..bfda746f3 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/MyInlinedUnion.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyInlinedUnion.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -27,7 +27,7 @@ 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 id: ShapeId = ShapeId("smithy4s.example.protobuf", "MyInlinedUnion") val hints: Hints = Hints( alloy.proto.ProtoInlinedOneOf(), @@ -37,16 +37,12 @@ object MyInlinedUnion extends ShapeTag.Companion[MyInlinedUnion] { 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 hints: Hints = Hints.empty 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 hints: Hints = Hints.empty val schema: Schema[MyInlinedUnion.BoolCase] = bijection(boolean.addHints(hints), MyInlinedUnion.BoolCase(_), _.bool) val alt = schema.oneOf[MyInlinedUnion]("bool") } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/MyInt.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyInt.scala similarity index 79% rename from modules/bootstrapped/src/generated/smithy4s/example/MyInt.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyInt.scala index 6430c24d6..e44839cfc 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/MyInt.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyInt.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Newtype @@ -8,7 +8,7 @@ import smithy4s.schema.Schema.bijection import smithy4s.schema.Schema.int object MyInt extends Newtype[Int] { - val id: ShapeId = ShapeId("smithy4s.example", "MyInt") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "MyInt") val hints: Hints = Hints.empty val underlyingSchema: Schema[Int] = int.withId(id).addHints(hints) implicit val schema: Schema[MyInt] = bijection(underlyingSchema, asBijection) diff --git a/modules/bootstrapped/src/generated/smithy4s/example/MyIntList.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyIntList.scala similarity index 80% rename from modules/bootstrapped/src/generated/smithy4s/example/MyIntList.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyIntList.scala index 0e2d6d34b..529daca72 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/MyIntList.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyIntList.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Newtype @@ -8,7 +8,7 @@ import smithy4s.schema.Schema.bijection import smithy4s.schema.Schema.list object MyIntList extends Newtype[List[MyInt]] { - val id: ShapeId = ShapeId("smithy4s.example", "MyIntList") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "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) diff --git a/modules/bootstrapped/src/generated/smithy4s/example/MyIntListWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyIntListWrapper.scala similarity index 81% rename from modules/bootstrapped/src/generated/smithy4s/example/MyIntListWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyIntListWrapper.scala index c4f0db3d3..e8057aba5 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/MyIntListWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyIntListWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -9,7 +9,7 @@ import smithy4s.schema.Schema.struct final case class MyIntListWrapper(ints: List[MyInt]) object MyIntListWrapper extends ShapeTag.Companion[MyIntListWrapper] { - val id: ShapeId = ShapeId("smithy4s.example", "MyIntListWrapper") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "MyIntListWrapper") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -19,6 +19,6 @@ object MyIntListWrapper extends ShapeTag.Companion[MyIntListWrapper] { private def make(ints: List[MyInt]): MyIntListWrapper = MyIntListWrapper(ints) implicit val schema: Schema[MyIntListWrapper] = struct( - MyIntList.underlyingSchema.required[MyIntListWrapper]("ints", _.ints).addHints(alloy.proto.ProtoIndex(1)), + MyIntList.underlyingSchema.required[MyIntListWrapper]("ints", _.ints), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/MyUnion.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyUnion.scala similarity index 57% rename from modules/bootstrapped/src/generated/smithy4s/example/MyUnion.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyUnion.scala index b2b761b3a..78ae3a09a 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/MyUnion.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/MyUnion.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -15,43 +15,63 @@ sealed trait MyUnion extends scala.Product with scala.Serializable { self => object project { def int: Option[Int] = MyUnion.IntCase.alt.project.lift(self).map(_.int) def bool: Option[Boolean] = MyUnion.BoolCase.alt.project.lift(self).map(_.bool) + def list: Option[List[MyInt]] = MyUnion.ListCase.alt.project.lift(self).map(_.list) + def map: Option[Map[String, Int]] = MyUnion.MapCase.alt.project.lift(self).map(_.map) } def accept[A](visitor: MyUnion.Visitor[A]): A = this match { case value: MyUnion.IntCase => visitor.int(value.int) case value: MyUnion.BoolCase => visitor.bool(value.bool) + case value: MyUnion.ListCase => visitor.list(value.list) + case value: MyUnion.MapCase => visitor.map(value.map) } } object MyUnion extends ShapeTag.Companion[MyUnion] { def int(int: Int): MyUnion = IntCase(int) def bool(bool: Boolean): MyUnion = BoolCase(bool) + def list(list: List[MyInt]): MyUnion = ListCase(list) + def map(map: Map[String, Int]): MyUnion = MapCase(map) - val id: ShapeId = ShapeId("smithy4s.example", "MyUnion") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "MyUnion") val hints: Hints = Hints.empty final case class IntCase(int: Int) extends MyUnion { final def $ordinal: Int = 0 } final case class BoolCase(bool: Boolean) extends MyUnion { final def $ordinal: Int = 1 } + final case class ListCase(list: List[MyInt]) extends MyUnion { final def $ordinal: Int = 2 } + final case class MapCase(map: Map[String, Int]) extends MyUnion { final def $ordinal: Int = 3 } object IntCase { - val hints: Hints = Hints( - alloy.proto.ProtoIndex(1), - ).lazily + val hints: Hints = Hints.empty val schema: Schema[MyUnion.IntCase] = bijection(smithy4s.schema.Schema.int.addHints(hints), MyUnion.IntCase(_), _.int) val alt = schema.oneOf[MyUnion]("int") } object BoolCase { - val hints: Hints = Hints( - alloy.proto.ProtoIndex(2), - ).lazily + val hints: Hints = Hints.empty val schema: Schema[MyUnion.BoolCase] = bijection(boolean.addHints(hints), MyUnion.BoolCase(_), _.bool) val alt = schema.oneOf[MyUnion]("bool") } + object ListCase { + val hints: Hints = Hints( + alloy.proto.ProtoWrapped(), + ).lazily + val schema: Schema[MyUnion.ListCase] = bijection(MyIntList.underlyingSchema.addHints(hints), MyUnion.ListCase(_), _.list) + val alt = schema.oneOf[MyUnion]("list") + } + object MapCase { + val hints: Hints = Hints( + alloy.proto.ProtoWrapped(), + ).lazily + val schema: Schema[MyUnion.MapCase] = bijection(StringMap.underlyingSchema.addHints(hints), MyUnion.MapCase(_), _.map) + val alt = schema.oneOf[MyUnion]("map") + } trait Visitor[A] { def int(value: Int): A def bool(value: Boolean): A + def list(value: List[MyInt]): A + def map(value: Map[String, Int]): A } object Visitor { @@ -59,12 +79,16 @@ object MyUnion extends ShapeTag.Companion[MyUnion] { def default: A def int(value: Int): A = default def bool(value: Boolean): A = default + def list(value: List[MyInt]): A = default + def map(value: Map[String, Int]): A = default } } implicit val schema: Schema[MyUnion] = union( MyUnion.IntCase.alt, MyUnion.BoolCase.alt, + MyUnion.ListCase.alt, + MyUnion.MapCase.alt, ){ _.$ordinal }.withId(id).addHints(hints) diff --git a/modules/bootstrapped/src/generated/smithy4s/example/OpenInt.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/OpenInt.scala similarity index 92% rename from modules/bootstrapped/src/generated/smithy4s/example/OpenInt.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/OpenInt.scala index 569dd69b2..78a562c14 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/OpenInt.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/OpenInt.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Enumeration import smithy4s.Hints @@ -18,7 +18,7 @@ sealed abstract class OpenInt(_value: String, _name: String, _intValue: Int, _hi @inline final def widen: OpenInt = this } object OpenInt extends Enumeration[OpenInt] with ShapeTag.Companion[OpenInt] { - val id: ShapeId = ShapeId("smithy4s.example", "OpenInt") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "OpenInt") val hints: Hints = Hints( alloy.OpenEnum(), diff --git a/modules/bootstrapped/src/generated/smithy4s/example/OpenString.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/OpenString.scala similarity index 92% rename from modules/bootstrapped/src/generated/smithy4s/example/OpenString.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/OpenString.scala index 0ea8a1b03..0a28e3424 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/OpenString.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/OpenString.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Enumeration import smithy4s.Hints @@ -18,7 +18,7 @@ sealed abstract class OpenString(_value: String, _name: String, _intValue: Int, @inline final def widen: OpenString = this } object OpenString extends Enumeration[OpenString] with ShapeTag.Companion[OpenString] { - val id: ShapeId = ShapeId("smithy4s.example", "OpenString") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "OpenString") val hints: Hints = Hints( alloy.OpenEnum(), diff --git a/modules/bootstrapped/src/generated/smithy4s/example/OptionalMessageWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/OptionalMessageWrapper.scala similarity index 82% rename from modules/bootstrapped/src/generated/smithy4s/example/OptionalMessageWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/OptionalMessageWrapper.scala index 437b46ccb..05df1fc1e 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/OptionalMessageWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/OptionalMessageWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -9,7 +9,7 @@ import smithy4s.schema.Schema.struct final case class OptionalMessageWrapper(message: Option[Integers] = None) object OptionalMessageWrapper extends ShapeTag.Companion[OptionalMessageWrapper] { - val id: ShapeId = ShapeId("smithy4s.example", "OptionalMessageWrapper") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "OptionalMessageWrapper") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -19,6 +19,6 @@ object OptionalMessageWrapper extends ShapeTag.Companion[OptionalMessageWrapper] private def make(message: Option[Integers]): OptionalMessageWrapper = OptionalMessageWrapper(message) implicit val schema: Schema[OptionalMessageWrapper] = struct( - Integers.schema.optional[OptionalMessageWrapper]("message", _.message).addHints(alloy.proto.ProtoIndex(1)), + Integers.schema.optional[OptionalMessageWrapper]("message", _.message), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/OptionalStringWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/OptionalStringWrapper.scala similarity index 76% rename from modules/bootstrapped/src/generated/smithy4s/example/OptionalStringWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/OptionalStringWrapper.scala index 446a6dc99..6492db53d 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/OptionalStringWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/OptionalStringWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -10,7 +10,7 @@ import smithy4s.schema.Schema.struct final case class OptionalStringWrapper(string: Option[String] = None) object OptionalStringWrapper extends ShapeTag.Companion[OptionalStringWrapper] { - val id: ShapeId = ShapeId("smithy4s.example", "OptionalStringWrapper") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "OptionalStringWrapper") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -20,6 +20,6 @@ object OptionalStringWrapper extends ShapeTag.Companion[OptionalStringWrapper] { private def make(string: Option[String]): OptionalStringWrapper = OptionalStringWrapper(string) implicit val schema: Schema[OptionalStringWrapper] = struct( - string.optional[OptionalStringWrapper]("string", _.string).addHints(alloy.proto.ProtoIndex(1)), + string.optional[OptionalStringWrapper]("string", _.string), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/OtherScalars.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/OtherScalars.scala similarity index 61% rename from modules/bootstrapped/src/generated/smithy4s/example/OtherScalars.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/OtherScalars.scala index fa93dd047..2f7db46fc 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/OtherScalars.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/OtherScalars.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -14,7 +14,7 @@ import smithy4s.schema.Schema.struct final case class OtherScalars(boolean: Boolean, byte: Byte, float: Float, double: Double, short: Short) object OtherScalars extends ShapeTag.Companion[OtherScalars] { - val id: ShapeId = ShapeId("smithy4s.example", "OtherScalars") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "OtherScalars") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -24,10 +24,10 @@ object OtherScalars extends ShapeTag.Companion[OtherScalars] { private def make(boolean: Boolean, byte: Byte, float: Float, double: Double, short: Short): OtherScalars = OtherScalars(boolean, byte, float, double, short) implicit val schema: Schema[OtherScalars] = struct( - boolean.required[OtherScalars]("boolean", _.boolean).addHints(alloy.proto.ProtoIndex(1)), - byte.required[OtherScalars]("byte", _.byte).addHints(alloy.proto.ProtoIndex(2)), - float.required[OtherScalars]("float", _.float).addHints(alloy.proto.ProtoIndex(3)), - double.required[OtherScalars]("double", _.double).addHints(alloy.proto.ProtoIndex(4)), - short.required[OtherScalars]("short", _.short).addHints(alloy.proto.ProtoIndex(5)), + boolean.required[OtherScalars]("boolean", _.boolean), + byte.required[OtherScalars]("byte", _.byte), + float.required[OtherScalars]("float", _.float), + double.required[OtherScalars]("double", _.double), + short.required[OtherScalars]("short", _.short), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/Recursive.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/Recursive.scala similarity index 53% rename from modules/bootstrapped/src/generated/smithy4s/example/Recursive.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/Recursive.scala index 71c667cd2..20e0bf221 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/Recursive.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/Recursive.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -7,19 +7,19 @@ import smithy4s.ShapeTag import smithy4s.schema.Schema.recursive import smithy4s.schema.Schema.struct -final case class Recursive(recursive: Option[smithy4s.example.Recursive] = None) +final case class Recursive(recursive: Option[smithy4s.example.protobuf.Recursive] = None) object Recursive extends ShapeTag.Companion[Recursive] { - val id: ShapeId = ShapeId("smithy4s.example", "Recursive") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "Recursive") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), ).lazily // constructor using the original order from the spec - private def make(recursive: Option[smithy4s.example.Recursive]): Recursive = Recursive(recursive) + private def make(recursive: Option[smithy4s.example.protobuf.Recursive]): Recursive = Recursive(recursive) implicit val schema: Schema[Recursive] = recursive(struct( - smithy4s.example.Recursive.schema.optional[Recursive]("recursive", _.recursive).addHints(alloy.proto.ProtoIndex(1)), + smithy4s.example.protobuf.Recursive.schema.optional[Recursive]("recursive", _.recursive), )(make).withId(id).addHints(hints)) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/protobuf/RefinedIntWrapped.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/RefinedIntWrapped.scala new file mode 100644 index 000000000..a9289a76e --- /dev/null +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/RefinedIntWrapped.scala @@ -0,0 +1,25 @@ +package smithy4s.example.protobuf + +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 RefinedIntWrapped(int: Int) + +object RefinedIntWrapped extends ShapeTag.Companion[RefinedIntWrapped] { + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "RefinedIntWrapped") + + val hints: Hints = Hints( + alloy.proto.ProtoEnabled(), + ).lazily + + // constructor using the original order from the spec + private def make(int: Int): RefinedIntWrapped = RefinedIntWrapped(int) + + implicit val schema: Schema[RefinedIntWrapped] = struct( + int.validated(smithy.api.Range(min = Some(scala.math.BigDecimal(1.0)), max = Some(scala.math.BigDecimal(10.0)))).required[RefinedIntWrapped]("int", _.int), + )(make).withId(id).addHints(hints) +} diff --git a/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringList.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringList.scala new file mode 100644 index 000000000..69dc8b08b --- /dev/null +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringList.scala @@ -0,0 +1,16 @@ +package smithy4s.example.protobuf + +import smithy4s.Hints +import smithy4s.Newtype +import smithy4s.Schema +import smithy4s.ShapeId +import smithy4s.schema.Schema.bijection +import smithy4s.schema.Schema.list +import smithy4s.schema.Schema.string + +object StringList extends Newtype[List[String]] { + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "StringList") + val hints: Hints = Hints.empty + val underlyingSchema: Schema[List[String]] = list(string).withId(id).addHints(hints) + implicit val schema: Schema[StringList] = bijection(underlyingSchema, asBijection) +} diff --git a/modules/bootstrapped/src/generated/smithy4s/example/StringListWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringListWrapper.scala similarity index 77% rename from modules/bootstrapped/src/generated/smithy4s/example/StringListWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringListWrapper.scala index 0b2d38fe6..9a53f93a4 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/StringListWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringListWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -9,7 +9,7 @@ import smithy4s.schema.Schema.struct final case class StringListWrapper(strings: List[String], wrappedStrings: List[String]) object StringListWrapper extends ShapeTag.Companion[StringListWrapper] { - val id: ShapeId = ShapeId("smithy4s.example", "StringListWrapper") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "StringListWrapper") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -19,7 +19,7 @@ object StringListWrapper extends ShapeTag.Companion[StringListWrapper] { private def make(strings: List[String], wrappedStrings: List[String]): StringListWrapper = StringListWrapper(strings, wrappedStrings) implicit val schema: Schema[StringListWrapper] = struct( - StringList.underlyingSchema.required[StringListWrapper]("strings", _.strings).addHints(alloy.proto.ProtoIndex(1)), - WrappedStringList.underlyingSchema.required[StringListWrapper]("wrappedStrings", _.wrappedStrings).addHints(alloy.proto.ProtoIndex(2)), + StringList.underlyingSchema.required[StringListWrapper]("strings", _.strings), + WrappedStringList.underlyingSchema.required[StringListWrapper]("wrappedStrings", _.wrappedStrings), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringMap.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringMap.scala new file mode 100644 index 000000000..c384c52e0 --- /dev/null +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringMap.scala @@ -0,0 +1,17 @@ +package smithy4s.example.protobuf + +import smithy4s.Hints +import smithy4s.Newtype +import smithy4s.Schema +import smithy4s.ShapeId +import smithy4s.schema.Schema.bijection +import smithy4s.schema.Schema.int +import smithy4s.schema.Schema.map +import smithy4s.schema.Schema.string + +object StringMap extends Newtype[Map[String, Int]] { + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "StringMap") + val hints: Hints = Hints.empty + val underlyingSchema: Schema[Map[String, Int]] = map(string, int).withId(id).addHints(hints) + implicit val schema: Schema[StringMap] = bijection(underlyingSchema, asBijection) +} diff --git a/modules/bootstrapped/src/generated/smithy4s/example/StringMapWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringMapWrapper.scala similarity index 62% rename from modules/bootstrapped/src/generated/smithy4s/example/StringMapWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringMapWrapper.scala index cf4725b4e..793890959 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/StringMapWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringMapWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -6,19 +6,19 @@ import smithy4s.ShapeId import smithy4s.ShapeTag import smithy4s.schema.Schema.struct -final case class StringMapWrapper(values: Map[String, String]) +final case class StringMapWrapper(values: Map[String, Int]) object StringMapWrapper extends ShapeTag.Companion[StringMapWrapper] { - val id: ShapeId = ShapeId("smithy4s.example", "StringMapWrapper") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "StringMapWrapper") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), ).lazily // constructor using the original order from the spec - private def make(values: Map[String, String]): StringMapWrapper = StringMapWrapper(values) + private def make(values: Map[String, Int]): StringMapWrapper = StringMapWrapper(values) implicit val schema: Schema[StringMapWrapper] = struct( - StringMap.underlyingSchema.required[StringMapWrapper]("values", _.values).addHints(alloy.proto.ProtoIndex(1)), + StringMap.underlyingSchema.required[StringMapWrapper]("values", _.values), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/StringWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringWrapper.scala similarity index 76% rename from modules/bootstrapped/src/generated/smithy4s/example/StringWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringWrapper.scala index 25bee59a4..ca5cf2a92 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/StringWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StringWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -10,7 +10,7 @@ import smithy4s.schema.Schema.struct final case class StringWrapper(string: String) object StringWrapper extends ShapeTag.Companion[StringWrapper] { - val id: ShapeId = ShapeId("smithy4s.example", "StringWrapper") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "StringWrapper") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -20,6 +20,6 @@ object StringWrapper extends ShapeTag.Companion[StringWrapper] { private def make(string: String): StringWrapper = StringWrapper(string) implicit val schema: Schema[StringWrapper] = struct( - string.required[StringWrapper]("string", _.string).addHints(alloy.proto.ProtoIndex(1)), + string.required[StringWrapper]("string", _.string), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StructureWithCustomIndexes.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StructureWithCustomIndexes.scala new file mode 100644 index 000000000..de51c1293 --- /dev/null +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/StructureWithCustomIndexes.scala @@ -0,0 +1,28 @@ +package smithy4s.example.protobuf + +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 StructureWithCustomIndexes(c: Int, b: Int = 0, a: Option[Int] = None, d: Option[UnionWithCustomIndexes] = None) + +object StructureWithCustomIndexes extends ShapeTag.Companion[StructureWithCustomIndexes] { + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "StructureWithCustomIndexes") + + val hints: Hints = Hints( + alloy.proto.ProtoEnabled(), + ).lazily + + // constructor using the original order from the spec + private def make(a: Option[Int], b: Int, c: Int, d: Option[UnionWithCustomIndexes]): StructureWithCustomIndexes = StructureWithCustomIndexes(c, b, a, d) + + implicit val schema: Schema[StructureWithCustomIndexes] = struct( + int.optional[StructureWithCustomIndexes]("a", _.a).addHints(alloy.proto.ProtoIndex(4)), + int.field[StructureWithCustomIndexes]("b", _.b).addHints(smithy.api.Default(smithy4s.Document.fromDouble(0.0d)), alloy.proto.ProtoIndex(3)), + int.required[StructureWithCustomIndexes]("c", _.c).addHints(alloy.proto.ProtoIndex(2)), + UnionWithCustomIndexes.schema.optional[StructureWithCustomIndexes]("d", _.d).addHints(alloy.proto.ProtoIndex(1)), + )(make).withId(id).addHints(hints) +} diff --git a/modules/bootstrapped/src/generated/smithy4s/example/protobuf/UUIDWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/UUIDWrapper.scala new file mode 100644 index 000000000..ff7bacb3d --- /dev/null +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/UUIDWrapper.scala @@ -0,0 +1,27 @@ +package smithy4s.example.protobuf + +import java.util.UUID +import smithy4s.Hints +import smithy4s.Schema +import smithy4s.ShapeId +import smithy4s.ShapeTag +import smithy4s.schema.Schema.struct +import smithy4s.schema.Schema.uuid + +final case class UUIDWrapper(uuid: Option[UUID] = None, compactUUID: Option[CompactUUID] = None) + +object UUIDWrapper extends ShapeTag.Companion[UUIDWrapper] { + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "UUIDWrapper") + + val hints: Hints = Hints( + alloy.proto.ProtoEnabled(), + ).lazily + + // constructor using the original order from the spec + private def make(uuid: Option[UUID], compactUUID: Option[CompactUUID]): UUIDWrapper = UUIDWrapper(uuid, compactUUID) + + implicit val schema: Schema[UUIDWrapper] = struct( + uuid.optional[UUIDWrapper]("uuid", _.uuid), + CompactUUID.schema.optional[UUIDWrapper]("compactUUID", _.compactUUID), + )(make).withId(id).addHints(hints) +} diff --git a/modules/bootstrapped/src/generated/smithy4s/example/protobuf/UnionWithCustomIndexes.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/UnionWithCustomIndexes.scala new file mode 100644 index 000000000..be875e5fa --- /dev/null +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/UnionWithCustomIndexes.scala @@ -0,0 +1,85 @@ +package smithy4s.example.protobuf + +import smithy4s.Hints +import smithy4s.Schema +import smithy4s.ShapeId +import smithy4s.ShapeTag +import smithy4s.schema.Schema.bijection +import smithy4s.schema.Schema.int +import smithy4s.schema.Schema.union + +sealed trait UnionWithCustomIndexes extends scala.Product with scala.Serializable { self => + @inline final def widen: UnionWithCustomIndexes = this + def $ordinal: Int + + object project { + def a: Option[Int] = UnionWithCustomIndexes.ACase.alt.project.lift(self).map(_.a) + def b: Option[Int] = UnionWithCustomIndexes.BCase.alt.project.lift(self).map(_.b) + def c: Option[Int] = UnionWithCustomIndexes.CCase.alt.project.lift(self).map(_.c) + } + + def accept[A](visitor: UnionWithCustomIndexes.Visitor[A]): A = this match { + case value: UnionWithCustomIndexes.ACase => visitor.a(value.a) + case value: UnionWithCustomIndexes.BCase => visitor.b(value.b) + case value: UnionWithCustomIndexes.CCase => visitor.c(value.c) + } +} +object UnionWithCustomIndexes extends ShapeTag.Companion[UnionWithCustomIndexes] { + + def a(a: Int): UnionWithCustomIndexes = ACase(a) + def b(b: Int): UnionWithCustomIndexes = BCase(b) + def c(c: Int): UnionWithCustomIndexes = CCase(c) + + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "UnionWithCustomIndexes") + + val hints: Hints = Hints.empty + + final case class ACase(a: Int) extends UnionWithCustomIndexes { final def $ordinal: Int = 0 } + final case class BCase(b: Int) extends UnionWithCustomIndexes { final def $ordinal: Int = 1 } + final case class CCase(c: Int) extends UnionWithCustomIndexes { final def $ordinal: Int = 2 } + + object ACase { + val hints: Hints = Hints( + alloy.proto.ProtoIndex(3), + ).lazily + val schema: Schema[UnionWithCustomIndexes.ACase] = bijection(int.addHints(hints), UnionWithCustomIndexes.ACase(_), _.a) + val alt = schema.oneOf[UnionWithCustomIndexes]("a") + } + object BCase { + val hints: Hints = Hints( + alloy.proto.ProtoIndex(2), + ).lazily + val schema: Schema[UnionWithCustomIndexes.BCase] = bijection(int.addHints(hints), UnionWithCustomIndexes.BCase(_), _.b) + val alt = schema.oneOf[UnionWithCustomIndexes]("b") + } + object CCase { + val hints: Hints = Hints( + alloy.proto.ProtoIndex(1), + ).lazily + val schema: Schema[UnionWithCustomIndexes.CCase] = bijection(int.addHints(hints), UnionWithCustomIndexes.CCase(_), _.c) + val alt = schema.oneOf[UnionWithCustomIndexes]("c") + } + + trait Visitor[A] { + def a(value: Int): A + def b(value: Int): A + def c(value: Int): A + } + + object Visitor { + trait Default[A] extends Visitor[A] { + def default: A + def a(value: Int): A = default + def b(value: Int): A = default + def c(value: Int): A = default + } + } + + implicit val schema: Schema[UnionWithCustomIndexes] = union( + UnionWithCustomIndexes.ACase.alt, + UnionWithCustomIndexes.BCase.alt, + UnionWithCustomIndexes.CCase.alt, + ){ + _.$ordinal + }.withId(id).addHints(hints) +} diff --git a/modules/bootstrapped/src/generated/smithy4s/example/UnionWrapper.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/UnionWrapper.scala similarity index 74% rename from modules/bootstrapped/src/generated/smithy4s/example/UnionWrapper.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/UnionWrapper.scala index c82a86977..83d02c025 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/UnionWrapper.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/UnionWrapper.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -9,7 +9,7 @@ import smithy4s.schema.Schema.struct final case class UnionWrapper(myUnion: Option[MyUnion] = None) object UnionWrapper extends ShapeTag.Companion[UnionWrapper] { - val id: ShapeId = ShapeId("smithy4s.example", "UnionWrapper") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "UnionWrapper") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -19,6 +19,6 @@ object UnionWrapper extends ShapeTag.Companion[UnionWrapper] { private def make(myUnion: Option[MyUnion]): UnionWrapper = UnionWrapper(myUnion) implicit val schema: Schema[UnionWrapper] = struct( - MyUnion.schema.optional[UnionWrapper]("myUnion", _.myUnion).addHints(alloy.proto.ProtoIndex(1)), + MyUnion.schema.optional[UnionWrapper]("myUnion", _.myUnion), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/WrappedScalars.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/WrappedScalars.scala similarity index 80% rename from modules/bootstrapped/src/generated/smithy4s/example/WrappedScalars.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/WrappedScalars.scala index 08eb5530a..0bb452ced 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/WrappedScalars.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/WrappedScalars.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Schema @@ -11,7 +11,7 @@ import smithy4s.schema.Schema.struct final case class WrappedScalars(int: Option[Int] = None, bool: Option[Boolean] = None) object WrappedScalars extends ShapeTag.Companion[WrappedScalars] { - val id: ShapeId = ShapeId("smithy4s.example", "WrappedScalars") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "WrappedScalars") val hints: Hints = Hints( alloy.proto.ProtoEnabled(), @@ -21,7 +21,7 @@ object WrappedScalars extends ShapeTag.Companion[WrappedScalars] { private def make(int: Option[Int], bool: Option[Boolean]): WrappedScalars = WrappedScalars(int, bool) implicit val schema: Schema[WrappedScalars] = struct( - int.optional[WrappedScalars]("int", _.int).addHints(alloy.proto.ProtoWrapped(), alloy.proto.ProtoIndex(1)), - boolean.optional[WrappedScalars]("bool", _.bool).addHints(alloy.proto.ProtoWrapped(), alloy.proto.ProtoIndex(2)), + int.optional[WrappedScalars]("int", _.int).addHints(alloy.proto.ProtoWrapped()), + boolean.optional[WrappedScalars]("bool", _.bool).addHints(alloy.proto.ProtoWrapped()), )(make).withId(id).addHints(hints) } diff --git a/modules/bootstrapped/src/generated/smithy4s/example/WrappedStringList.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/WrappedStringList.scala similarity index 82% rename from modules/bootstrapped/src/generated/smithy4s/example/WrappedStringList.scala rename to modules/bootstrapped/src/generated/smithy4s/example/protobuf/WrappedStringList.scala index 0b40b20d0..c463154ea 100644 --- a/modules/bootstrapped/src/generated/smithy4s/example/WrappedStringList.scala +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/WrappedStringList.scala @@ -1,4 +1,4 @@ -package smithy4s.example +package smithy4s.example.protobuf import smithy4s.Hints import smithy4s.Newtype @@ -9,7 +9,7 @@ import smithy4s.schema.Schema.list import smithy4s.schema.Schema.string object WrappedStringList extends Newtype[List[String]] { - val id: ShapeId = ShapeId("smithy4s.example", "WrappedStringList") + val id: ShapeId = ShapeId("smithy4s.example.protobuf", "WrappedStringList") val hints: Hints = Hints( alloy.proto.ProtoWrapped(), ).lazily diff --git a/modules/bootstrapped/src/generated/smithy4s/example/protobuf/package.scala b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/package.scala new file mode 100644 index 000000000..345955cd1 --- /dev/null +++ b/modules/bootstrapped/src/generated/smithy4s/example/protobuf/package.scala @@ -0,0 +1,13 @@ +package smithy4s.example + +package object protobuf { + + type MyInt = smithy4s.example.protobuf.MyInt.Type + type IntList = smithy4s.example.protobuf.IntList.Type + type StringMap = smithy4s.example.protobuf.StringMap.Type + type MyIntList = smithy4s.example.protobuf.MyIntList.Type + type StringList = smithy4s.example.protobuf.StringList.Type + type CompactUUID = smithy4s.example.protobuf.CompactUUID.Type + type WrappedStringList = smithy4s.example.protobuf.WrappedStringList.Type + +} \ No newline at end of file diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/build.sbt b/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/build.sbt new file mode 100644 index 000000000..c6fbec281 --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/build.sbt @@ -0,0 +1,8 @@ +lazy val root = (project in file(".")) + .enablePlugins(Smithy4sCodegenPlugin) + .settings( + scalaVersion := "2.13.10", + libraryDependencies ++= Seq( + "com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion.value + ) + ) diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/project/build.properties b/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/project/build.properties new file mode 100644 index 000000000..46e43a97e --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.8.2 diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/project/plugins.sbt b/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/project/plugins.sbt new file mode 100644 index 000000000..b8589b92c --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/project/plugins.sbt @@ -0,0 +1,9 @@ +sys.props.get("plugin.version") match { + case Some(x) => + addSbtPlugin("com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % x) + case _ => + sys.error( + """|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin + ) +} diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/src/main/smithy/foo.smithy b/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/src/main/smithy/foo.smithy new file mode 100644 index 000000000..05bd745d1 --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/src/main/smithy/foo.smithy @@ -0,0 +1,11 @@ +$version: "2" + +namespace foo + +use alloy.proto#protoEnabled + +@protoEnabled +structure Foo { + a: String + b: Integer +} diff --git a/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/test b/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/test new file mode 100644 index 000000000..ec55fa20c --- /dev/null +++ b/modules/codegen-plugin/src/sbt-test/codegen-plugin/protobuf/test @@ -0,0 +1,4 @@ +> compile + +# Protobuf source created +-$ exists target/scala-2.13/resources_managed/foo/foo.proto diff --git a/modules/codegen/src/smithy4s/codegen/CodegenArgs.scala b/modules/codegen/src/smithy4s/codegen/CodegenArgs.scala index 115d1668b..c3e347360 100644 --- a/modules/codegen/src/smithy4s/codegen/CodegenArgs.scala +++ b/modules/codegen/src/smithy4s/codegen/CodegenArgs.scala @@ -35,6 +35,7 @@ final case class CodegenArgs( def skipScala: Boolean = skip(FileType.Scala) def skipOpenapi: Boolean = skip(FileType.Openapi) def skipResources: Boolean = skip(FileType.Resource) + def skipProto: Boolean = skip(FileType.Proto) } sealed abstract class FileType(val name: String) @@ -50,6 +51,7 @@ object FileType { case object Scala extends FileType("scala") case object Openapi extends FileType("openapi") case object Resource extends FileType("resource") + case object Proto extends FileType("proto") val values = List(Scala, Openapi, Resource) } diff --git a/modules/codegen/src/smithy4s/codegen/internals/CodegenImpl.scala b/modules/codegen/src/smithy4s/codegen/internals/CodegenImpl.scala index 08b3d23a7..689c40272 100644 --- a/modules/codegen/src/smithy4s/codegen/internals/CodegenImpl.scala +++ b/modules/codegen/src/smithy4s/codegen/internals/CodegenImpl.scala @@ -72,9 +72,17 @@ private[codegen] object CodegenImpl { self => } } else List.empty + val protoFiles = if (!args.skipProto) { + smithytranslate.proto3.SmithyToProtoCompiler.compile(model).map { + renderedProto => + val protoFile = (args.resourceOutput / renderedProto.path) + CodegenEntry.FromMemory(protoFile, renderedProto.contents) + } + } else List.empty + CodegenResult( sources = scalaFiles, - resources = openApiFiles ++ smithyResources + resources = openApiFiles ++ protoFiles ++ smithyResources ) } @@ -122,7 +130,8 @@ private[codegen] object CodegenImpl { self => "alloy.common", "alloy.proto", "smithy4s.api", - "smithy4s.meta" + "smithy4s.meta", + "smithytranslate" ) // Retrieving metadata that indicates what has already been generated by Smithy4s diff --git a/modules/docs/markdown/03-protocols/07-protobuf-grpc/01-protobuf.md b/modules/docs/markdown/03-protocols/07-protobuf-grpc/01-protobuf.md new file mode 100644 index 000000000..3d2945b3c --- /dev/null +++ b/modules/docs/markdown/03-protocols/07-protobuf-grpc/01-protobuf.md @@ -0,0 +1,10 @@ +--- +sidebar_label: Protobuf +title: Protobuf +--- + +For convenience, the smithy4s build plugins generate protobuf (`.proto`) definitions translated from smithy specifications out of the box. However, this translation is limited to the transitive closure of shapes that have the `alloy.proto#protoEnabled` or the `alloy.proto#grpc` traits. + +The location of these protobuf specifications is driven by the `smithy4sResourceDir` setting in SBT and the `smithy4sResourceOutputDir` in mill. + +The semantics of the smithy to protobuf translation are following the [alloy specification](https://github.com/disneystreaming/alloy/blob/main/docs/serialisation/protobuf.md). diff --git a/modules/docs/markdown/03-protocols/07-protobuf-grpc/_category_.json b/modules/docs/markdown/03-protocols/07-protobuf-grpc/_category_.json new file mode 100644 index 000000000..ff7764282 --- /dev/null +++ b/modules/docs/markdown/03-protocols/07-protobuf-grpc/_category_.json @@ -0,0 +1,3 @@ +{ + "label": "Protobuf and gRPC" +} diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 9832c52c1..9c6247725 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -36,6 +36,12 @@ object Dependencies { val `protocol-tests` = org % "alloy-protocol-tests" % alloyVersion } + val Smithytranslate = new { + val org = "com.disneystreaming.smithy" + val smithyTranslateVersion = "0.5.1" + val proto = org %% "smithytranslate-proto" % smithyTranslateVersion + } + val Cats = new { val core: Def.Initialize[ModuleID] = Def.setting("org.typelevel" %%% "cats-core" % "2.10.0") diff --git a/sampleSpecs/protoTest.smithy b/sampleSpecs/protoTest.smithy index 715e7fae3..6ff4e62fb 100644 --- a/sampleSpecs/protoTest.smithy +++ b/sampleSpecs/protoTest.smithy @@ -1,10 +1,15 @@ $version: "2" -namespace smithy4s.example +metadata "proto_options" = [{ + +}] +namespace smithy4s.example.protobuf use alloy#UUID use alloy#openEnum +use alloy#uuidFormat use alloy.openapi#openapiExtensions +use alloy.proto#protoCompactUUID use alloy.proto#protoEnabled use alloy.proto#protoIndex use alloy.proto#protoInlinedOneOf @@ -13,22 +18,17 @@ use alloy.proto#protoWrapped @protoEnabled structure Integers { - @protoIndex(1) @required int: Integer - @protoIndex(2) @protoNumType("SIGNED") @required sint: Integer - @protoIndex(3) @protoNumType("UNSIGNED") @required uint: Integer - @protoIndex(4) @protoNumType("FIXED") @required fixedUint: Integer - @protoIndex(5) @protoNumType("FIXED_SIGNED") @required fixedSint: Integer @@ -36,22 +36,17 @@ structure Integers { @protoEnabled structure Longs { - @protoIndex(1) @required long: Long - @protoIndex(2) @protoNumType("SIGNED") @required slong: Long - @protoIndex(3) @protoNumType("UNSIGNED") @required ulong: Long - @protoIndex(4) @protoNumType("FIXED") @required fixedLong: Long - @protoIndex(5) @protoNumType("FIXED_SIGNED") @required fixedSlong: Long @@ -59,82 +54,70 @@ structure Longs { @protoEnabled structure OtherScalars { - @protoIndex(1) @required boolean: Boolean @required - @protoIndex(2) byte: Byte @required - @protoIndex(3) float: Float @required - @protoIndex(4) double: Double @required - @protoIndex(5) short: Short } @protoEnabled structure WrappedScalars { - @protoIndex(1) @protoWrapped int: Integer - @protoIndex(2) @protoWrapped bool: Boolean } @protoEnabled structure StringWrapper { - @protoIndex(1) @required string: String } @protoEnabled structure OptionalStringWrapper { - @protoIndex(1) string: String } @protoEnabled structure BigDecimalWrapper { - @protoIndex(1) @required bigDecimal: BigDecimal } +@uuidFormat +@protoCompactUUID +string CompactUUID + @protoEnabled -structure Other { - @protoIndex(3) - @required - bigDecimal: BigDecimal - @required - @protoIndex(4) - bigInteger: BigInteger - @protoIndex(5) - @required +structure UUIDWrapper { uuid: UUID + compactUUID: CompactUUID +} + +list IntList { + member: Integer } @protoEnabled structure MessageWrapper { - @protoIndex(1) @required message: Integers } @protoEnabled structure OptionalMessageWrapper { - @protoIndex(1) message: Integers } @protoEnabled structure IntListWrapper { - @protoIndex(1) @required ints: IntList } @@ -150,10 +133,8 @@ list WrappedStringList { @protoEnabled structure StringListWrapper { - @protoIndex(1) @required strings: StringList - @protoIndex(2) @required wrappedStrings: WrappedStringList } @@ -166,28 +147,27 @@ list MyIntList { @protoEnabled structure MyIntListWrapper { - @protoIndex(1) @required ints: MyIntList } @protoEnabled structure Recursive { - @protoIndex(1) recursive: Recursive } @protoEnabled structure UnionWrapper { - @protoIndex(1) myUnion: MyUnion } union MyUnion { - @protoIndex(1) int: Integer - @protoIndex(2) bool: Boolean + @protoWrapped + list: MyIntList + @protoWrapped + map: StringMap } @protoEnabled @@ -197,15 +177,82 @@ structure InlinedUnionWrapper { @protoInlinedOneOf union MyInlinedUnion { - @protoIndex(1) int: Integer - @protoIndex(2) bool: Boolean } @protoEnabled structure StringMapWrapper { - @protoIndex(1) @required values: StringMap } + +map StringMap { + key: String + value: Integer +} + +@protoEnabled +structure Enums { + @required + closedString: ClosedString + @required + openString: OpenString + @required + closedInt: ClosedInt + @required + openInt: OpenInt +} + +enum ClosedString { + FOO + BAR +} + +@openEnum +enum OpenString { + FOO + BAR +} + +intEnum ClosedInt { + @protoIndex(0) + FOO = 0 + @protoIndex(1) + BAR = 1 +} + +@openEnum +intEnum OpenInt { + FOO = 0 + BAR = 1 +} + +@protoEnabled +structure RefinedIntWrapped { + @required + @range(min: 1, max: 10) + int: Integer +} + +@protoEnabled +structure StructureWithCustomIndexes { + @protoIndex(4) + a: Integer + @protoIndex(3) + b: Integer = 0 + @protoIndex(2) + @required + c: Integer + @protoIndex(1) + d: UnionWithCustomIndexes +} + +union UnionWithCustomIndexes { + @protoIndex(3) + a: Integer + @protoIndex(2) + b: Integer + @protoIndex(1) + c: Integer +}