Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FQNs in rendered Product and Serializable inheritance #63

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ lazy val core = projectMatrix
(ThisBuild / baseDirectory).value / "sampleSpecs" / "recursive.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "bodies.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "empty.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "product.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "weather.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "discriminated.smithy"
),
Expand Down
1 change: 0 additions & 1 deletion modules/benchmark/src/main/scala/Codecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,3 @@ object Circe {
implicit val s3ObjectCodec: Codec[S3Object] =
io.circe.generic.semiauto.deriveCodec[S3Object]
}

4 changes: 2 additions & 2 deletions modules/codegen/src/smithy4s/codegen/Renderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ private[codegen] class Renderer(compilationUnit: CompilationUnit) { self =>
val caseNames = alts.map(_.name).map(caseName)
val imports = alts.foldMap(_.tpe.imports) ++ syntaxImport
lines(
s"sealed trait $name",
s"sealed trait $name extends scala.Product with scala.Serializable",
obj(name, ext = hintKey(name, hints))(
renderId(name),
newline,
Expand Down Expand Up @@ -460,7 +460,7 @@ private[codegen] class Renderer(compilationUnit: CompilationUnit) { self =>
values: List[EnumValue],
hints: List[Hint]
): RenderResult = lines(
s"sealed abstract class $name(val value: String, val ordinal: Int) extends Product with Serializable",
s"sealed abstract class $name(val value: String, val ordinal: Int) extends scala.Product with scala.Serializable",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general thought, should we do the same for collections? I imagine a type like Vector might appear in users' smithy files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that should be default behaviour, but maybe we'll add that as an option to the rendering

obj(name, ext = s"$Enumeration_[$name]", w = hintKey(name, hints))(
renderId(name),
newline,
Expand Down
32 changes: 32 additions & 0 deletions modules/core/test/src/smithy4s/ProductSerialSmokeSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2021 Disney Streaming
*
* Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://disneystreaming.github.io/TOST-1.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package smithy4s

import weaver._

object ProductSerialSmokeSpec extends FunSuite {

test(
"Enumeration compiles when shapes called Product or Serializable exist"
) {
val product = smithy4s.example.Product
val serial = smithy4s.example.Serializable
val foo = smithy4s.example.FooEnum.FOO
expect(List(product, serial, foo).forall(_ != null))
}

}
2 changes: 1 addition & 1 deletion modules/example/src/smithy4s/example/Foo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package smithy4s.example

import smithy4s.syntax._

sealed trait Foo
sealed trait Foo extends scala.Product with scala.Serializable
object Foo {
val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "Foo")

Expand Down
2 changes: 1 addition & 1 deletion modules/example/src/smithy4s/example/LowHigh.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package smithy4s.example

import smithy4s.syntax._

sealed abstract class LowHigh(val value: String, val ordinal: Int) extends Product with Serializable
sealed abstract class LowHigh(val value: String, val ordinal: Int) extends scala.Product with scala.Serializable
object LowHigh extends smithy4s.Enumeration[LowHigh] {
val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "LowHigh")

Expand Down
4 changes: 2 additions & 2 deletions modules/example/src/smithy4s/example/ObjectService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object ObjectServiceGen extends smithy4s.Service[ObjectServiceGen, ObjectService
case PutObjectError.NoMoreSpaceCase(e) => e
}
}
sealed trait PutObjectError
sealed trait PutObjectError extends scala.Product with scala.Serializable
object PutObjectError {
val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "PutObjectError")

Expand Down Expand Up @@ -134,7 +134,7 @@ object ObjectServiceGen extends smithy4s.Service[ObjectServiceGen, ObjectService
case GetObjectError.ServerErrorCase(e) => e
}
}
sealed trait GetObjectError
sealed trait GetObjectError extends scala.Product with scala.Serializable
object GetObjectError {
val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "GetObjectError")

Expand Down
7 changes: 7 additions & 0 deletions sampleSpecs/product.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace smithy4s.example

@enum([{name: "FOO", value: "Foo"}])
string FooEnum

structure Product {}
structure Serializable {}