-
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 #280 from disneystreaming/render-import-fix
fix imports for newtypes from other packages
- Loading branch information
Showing
10 changed files
with
143 additions
and
15 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.example.common.BrandList | ||
import smithy4s.schema.Schema._ | ||
|
||
case class AddBrandsInput(brands: Option[List[String]] = None) | ||
object AddBrandsInput extends smithy4s.ShapeTag.Companion[AddBrandsInput] { | ||
val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "AddBrandsInput") | ||
|
||
val hints : smithy4s.Hints = smithy4s.Hints.empty | ||
|
||
implicit val schema: smithy4s.Schema[AddBrandsInput] = struct( | ||
BrandList.underlyingSchema.optional[AddBrandsInput]("brands", _.brands), | ||
){ | ||
AddBrandsInput.apply | ||
}.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.schema.Schema._ | ||
|
||
trait BrandServiceGen[F[_, _, _, _, _]] { | ||
self => | ||
|
||
def addBrands(brands: Option[List[String]] = None) : F[AddBrandsInput, Nothing, Unit, Nothing, Nothing] | ||
|
||
def transform[G[_, _, _, _, _]](transformation : smithy4s.Transformation[F, G]) : BrandServiceGen[G] = new Transformed(transformation) | ||
class Transformed[G[_, _, _, _, _]](transformation : smithy4s.Transformation[F, G]) extends BrandServiceGen[G] { | ||
def addBrands(brands: Option[List[String]] = None) = transformation[AddBrandsInput, Nothing, Unit, Nothing, Nothing](self.addBrands(brands)) | ||
} | ||
} | ||
|
||
object BrandServiceGen extends smithy4s.Service[BrandServiceGen, BrandServiceOperation] { | ||
|
||
def apply[F[_]](implicit F: smithy4s.Monadic[BrandServiceGen, F]): F.type = F | ||
|
||
val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "BrandService") | ||
|
||
val hints : smithy4s.Hints = smithy4s.Hints.empty | ||
|
||
val endpoints = List( | ||
AddBrands, | ||
) | ||
|
||
val version: String = "1" | ||
|
||
def endpoint[I, E, O, SI, SO](op : BrandServiceOperation[I, E, O, SI, SO]) = op match { | ||
case AddBrands(input) => (input, AddBrands) | ||
} | ||
|
||
object reified extends BrandServiceGen[BrandServiceOperation] { | ||
def addBrands(brands: Option[List[String]] = None) = AddBrands(AddBrandsInput(brands)) | ||
} | ||
|
||
def transform[P[_, _, _, _, _]](transformation: smithy4s.Transformation[BrandServiceOperation, P]): BrandServiceGen[P] = reified.transform(transformation) | ||
|
||
def transform[P[_, _, _, _, _], P1[_, _, _, _, _]](alg: BrandServiceGen[P], transformation: smithy4s.Transformation[P, P1]): BrandServiceGen[P1] = alg.transform(transformation) | ||
|
||
def asTransformation[P[_, _, _, _, _]](impl : BrandServiceGen[P]): smithy4s.Transformation[BrandServiceOperation, P] = new smithy4s.Transformation[BrandServiceOperation, P] { | ||
def apply[I, E, O, SI, SO](op : BrandServiceOperation[I, E, O, SI, SO]) : P[I, E, O, SI, SO] = op match { | ||
case AddBrands(AddBrandsInput(brands)) => impl.addBrands(brands) | ||
} | ||
} | ||
case class AddBrands(input: AddBrandsInput) extends BrandServiceOperation[AddBrandsInput, Nothing, Unit, Nothing, Nothing] | ||
object AddBrands extends smithy4s.Endpoint[BrandServiceOperation, AddBrandsInput, Nothing, Unit, Nothing, Nothing] { | ||
val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example", "AddBrands") | ||
val input: smithy4s.Schema[AddBrandsInput] = AddBrandsInput.schema.addHints(smithy4s.internals.InputOutput.Input.widen) | ||
val output: smithy4s.Schema[Unit] = unit.addHints(smithy4s.internals.InputOutput.Output.widen) | ||
val streamedInput : smithy4s.StreamingSchema[Nothing] = smithy4s.StreamingSchema.nothing | ||
val streamedOutput : smithy4s.StreamingSchema[Nothing] = smithy4s.StreamingSchema.nothing | ||
val hints : smithy4s.Hints = smithy4s.Hints( | ||
smithy.api.Http(smithy.api.NonEmptyString("POST"), smithy.api.NonEmptyString("/brands"), Some(200)), | ||
) | ||
def wrap(input: AddBrandsInput) = AddBrands(input) | ||
} | ||
} | ||
|
||
sealed trait BrandServiceOperation[Input, Err, Output, StreamedInput, StreamedOutput] |
11 changes: 11 additions & 0 deletions
11
modules/example/src/smithy4s/example/common/BrandList.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,11 @@ | ||
package smithy4s.example.common | ||
|
||
import smithy4s.Newtype | ||
import smithy4s.schema.Schema._ | ||
|
||
object BrandList extends Newtype[List[String]] { | ||
val id: smithy4s.ShapeId = smithy4s.ShapeId("smithy4s.example.common", "BrandList") | ||
val hints : smithy4s.Hints = smithy4s.Hints.empty | ||
val underlyingSchema : smithy4s.Schema[List[String]] = list(string).withId(id).addHints(hints) | ||
implicit val schema : smithy4s.Schema[BrandList] = bijection(underlyingSchema, BrandList(_), (_ : BrandList).value) | ||
} |
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,7 @@ | ||
package smithy4s.example | ||
|
||
package object common { | ||
|
||
type BrandList = smithy4s.example.common.BrandList.Type | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace smithy4s.example | ||
|
||
use smithy4s.example.common#BrandList | ||
|
||
service BrandService { | ||
version: "1", | ||
operations: [AddBrands] | ||
} | ||
|
||
@http(method: "POST", uri: "/brands", code: 200) | ||
operation AddBrands { | ||
input: AddBrandsInput | ||
} | ||
|
||
structure AddBrandsInput { | ||
brands: BrandList | ||
} |
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,5 @@ | ||
namespace smithy4s.example.common | ||
|
||
list BrandList { | ||
member: String | ||
} |