Skip to content

Commit

Permalink
add visitor default
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisjkl committed Aug 11, 2023
1 parent f35e1fb commit 9bcacd0
Show file tree
Hide file tree
Showing 32 changed files with 350 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ object DynamoDBOperation {
def invalidEndpointException(value: InvalidEndpointException): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def internalServerError(value: InternalServerError): A = default
def invalidEndpointException(value: InvalidEndpointException): A = default
}
}

implicit val schema: UnionSchema[ListTablesError] = union(
ListTablesError.InternalServerErrorCase.alt,
ListTablesError.InvalidEndpointExceptionCase.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ object CheckedOrUnchecked extends ShapeTag.Companion[CheckedOrUnchecked] {
def raw(value: String): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def checked(value: String): A = default
def raw(value: String): A = default
}
}

implicit val schema: Schema[CheckedOrUnchecked] = union(
CheckedOrUnchecked.CheckedCase.alt,
CheckedOrUnchecked.RawCase.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ object CheckedOrUnchecked2 extends ShapeTag.Companion[CheckedOrUnchecked2] {
def raw(value: String): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def checked(value: String): A = default
def raw(value: String): A = default
}
}

implicit val schema: Schema[CheckedOrUnchecked2] = union(
CheckedOrUnchecked2.CheckedCase.alt,
CheckedOrUnchecked2.RawCase.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ object DeprecatedUnion extends ShapeTag.Companion[DeprecatedUnion] {
def p2(value: DeprecatedUnion.UnionProductCaseDeprecatedAtCallSite): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def s(value: String): A = default
def s_V2(value: String): A = default
def p(value: DeprecatedUnion.DeprecatedUnionProductCase): A = default
def p2(value: DeprecatedUnion.UnionProductCaseDeprecatedAtCallSite): A = default
}
}

implicit val schema: Schema[DeprecatedUnion] = union(
DeprecatedUnion.SCase.alt,
DeprecatedUnion.S_V2Case.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ object ErrorHandlingServiceOperation {
def eHFallbackServerError(value: EHFallbackServerError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def eHFallbackClientError(value: EHFallbackClientError): A = default
def eHServiceUnavailable(value: EHServiceUnavailable): A = default
def eHNotFound(value: EHNotFound): A = default
def eHFallbackServerError(value: EHFallbackServerError): A = default
}
}

implicit val schema: UnionSchema[ErrorHandlingOperationError] = union(
ErrorHandlingOperationError.EHFallbackClientErrorCase.alt,
ErrorHandlingOperationError.EHServiceUnavailableCase.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ object ErrorHandlingServiceExtraErrorsOperation {
def randomOtherServerErrorWithCode(value: RandomOtherServerErrorWithCode): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def randomOtherClientError(value: RandomOtherClientError): A = default
def randomOtherServerError(value: RandomOtherServerError): A = default
def randomOtherClientErrorWithCode(value: RandomOtherClientErrorWithCode): A = default
def randomOtherServerErrorWithCode(value: RandomOtherServerErrorWithCode): A = default
}
}

implicit val schema: UnionSchema[ExtraErrorOperationError] = union(
ExtraErrorOperationError.RandomOtherClientErrorCase.alt,
ExtraErrorOperationError.RandomOtherServerErrorCase.alt,
Expand Down
10 changes: 10 additions & 0 deletions modules/bootstrapped/src/generated/smithy4s/example/Foo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ object Foo extends ShapeTag.Companion[Foo] {
def bDec(value: BigDecimal): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def int(value: Int): A = default
def str(value: String): A = default
def bInt(value: BigInt): A = default
def bDec(value: BigDecimal): A = default
}
}

implicit val schema: Schema[Foo] = union(
Foo.IntCase.alt,
Foo.StrCase.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ object Food extends ShapeTag.Companion[Food] {
def salad(value: Salad): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def pizza(value: Pizza): A = default
def salad(value: Salad): A = default
}
}

implicit val schema: Schema[Food] = union(
Food.PizzaCase.alt,
Food.SaladCase.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ object ForecastResult extends ShapeTag.Companion[ForecastResult] {
def sun(value: UVIndex): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def rain(value: ChanceOfRain): A = default
def sun(value: UVIndex): A = default
}
}

implicit val schema: Schema[ForecastResult] = union(
ForecastResult.RainCase.alt,
ForecastResult.SunCase.alt,
Expand Down
23 changes: 23 additions & 0 deletions modules/bootstrapped/src/generated/smithy4s/example/KVStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ object KVStoreOperation {
def keyNotFoundError(value: KeyNotFoundError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def unauthorizedError(value: UnauthorizedError): A = default
def keyNotFoundError(value: KeyNotFoundError): A = default
}
}

implicit val schema: UnionSchema[GetError] = union(
GetError.UnauthorizedErrorCase.alt,
GetError.KeyNotFoundErrorCase.alt,
Expand Down Expand Up @@ -216,6 +224,13 @@ object KVStoreOperation {
def unauthorizedError(value: UnauthorizedError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def unauthorizedError(value: UnauthorizedError): A = default
}
}

implicit val schema: UnionSchema[PutError] = union(
PutError.UnauthorizedErrorCase.alt,
){
Expand Down Expand Up @@ -289,6 +304,14 @@ object KVStoreOperation {
def keyNotFoundError(value: KeyNotFoundError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def unauthorizedError(value: UnauthorizedError): A = default
def keyNotFoundError(value: KeyNotFoundError): A = default
}
}

implicit val schema: UnionSchema[DeleteError] = union(
DeleteError.UnauthorizedErrorCase.alt,
DeleteError.KeyNotFoundErrorCase.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ object NameCollisionOperation {
def myOpError(value: smithy4s.example.MyOpError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def myOpError(value: smithy4s.example.MyOpError): A = default
}
}

implicit val schema: UnionSchema[MyOpError] = union(
MyOpError.MyOpErrorCase.alt,
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ object ObjectServiceOperation {
def noMoreSpace(value: NoMoreSpace): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def serverError(value: ServerError): A = default
def noMoreSpace(value: NoMoreSpace): A = default
}
}

implicit val schema: UnionSchema[PutObjectError] = union(
PutObjectError.ServerErrorCase.alt,
PutObjectError.NoMoreSpaceCase.alt,
Expand Down Expand Up @@ -225,6 +233,13 @@ object ObjectServiceOperation {
def serverError(value: ServerError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def serverError(value: ServerError): A = default
}
}

implicit val schema: UnionSchema[GetObjectError] = union(
GetObjectError.ServerErrorCase.alt,
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ object OpticsUnion extends ShapeTag.Companion[OpticsUnion] {
def one(value: OpticsStructure): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def one(value: OpticsStructure): A = default
}
}

implicit val schema: Schema[OpticsUnion] = union(
OpticsUnion.OneCase.alt,
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ object OrderType extends ShapeTag.Companion[OrderType] {
def preview(value: OrderType.PreviewCase.type): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def online(value: OrderNumber): A = default
def inStore(value: OrderType.InStoreOrder): A = default
def preview(value: OrderType.PreviewCase.type): A = default
}
}

implicit val schema: Schema[OrderType] = union(
OrderType.OnlineCase.alt,
OrderType.InStoreOrder.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ object PersonContactInfo extends ShapeTag.Companion[PersonContactInfo] {
def phone(value: PersonPhoneNumber): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def email(value: PersonEmail): A = default
def phone(value: PersonPhoneNumber): A = default
}
}

implicit val schema: Schema[PersonContactInfo] = union(
PersonContactInfo.EmailCase.alt,
PersonContactInfo.PhoneCase.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ object PizzaAdminServiceOperation {
def genericClientError(value: GenericClientError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def priceError(value: PriceError): A = default
def genericServerError(value: GenericServerError): A = default
def genericClientError(value: GenericClientError): A = default
}
}

implicit val schema: UnionSchema[AddMenuItemError] = union(
AddMenuItemError.PriceErrorCase.alt,
AddMenuItemError.GenericServerErrorCase.alt,
Expand Down Expand Up @@ -314,6 +323,16 @@ object PizzaAdminServiceOperation {
def notFoundError(value: NotFoundError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def genericClientError(value: GenericClientError): A = default
def fallbackError2(value: FallbackError2): A = default
def fallbackError(value: FallbackError): A = default
def notFoundError(value: NotFoundError): A = default
}
}

implicit val schema: UnionSchema[GetMenuError] = union(
GetMenuError.GenericClientErrorCase.alt,
GetMenuError.FallbackError2Case.alt,
Expand Down Expand Up @@ -400,6 +419,13 @@ object PizzaAdminServiceOperation {
def unknownServerError(value: UnknownServerError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def unknownServerError(value: UnknownServerError): A = default
}
}

implicit val schema: UnionSchema[HealthError] = union(
HealthError.UnknownServerErrorCase.alt,
){
Expand Down Expand Up @@ -498,6 +524,13 @@ object PizzaAdminServiceOperation {
def unknownServerError(value: UnknownServerError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def unknownServerError(value: UnknownServerError): A = default
}
}

implicit val schema: UnionSchema[GetEnumError] = union(
GetEnumError.UnknownServerErrorCase.alt,
){
Expand Down Expand Up @@ -562,6 +595,13 @@ object PizzaAdminServiceOperation {
def unknownServerError(value: UnknownServerError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def unknownServerError(value: UnknownServerError): A = default
}
}

implicit val schema: UnionSchema[GetIntEnumError] = union(
GetIntEnumError.UnknownServerErrorCase.alt,
){
Expand Down Expand Up @@ -626,6 +666,13 @@ object PizzaAdminServiceOperation {
def unknownServerError(value: UnknownServerError): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def unknownServerError(value: UnknownServerError): A = default
}
}

implicit val schema: UnionSchema[CustomCodeError] = union(
CustomCodeError.UnknownServerErrorCase.alt,
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ object Podcast extends ShapeTag.Companion[Podcast] {
def audio(value: Podcast.Audio): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def video(value: Podcast.Video): A = default
def audio(value: Podcast.Audio): A = default
}
}

implicit val schema: Schema[Podcast] = union(
Podcast.Video.alt,
Podcast.Audio.alt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ object TestAdt extends ShapeTag.Companion[TestAdt] {
def two(value: TestAdt.AdtTwo): A
}

object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def one(value: TestAdt.AdtOne): A = default
def two(value: TestAdt.AdtTwo): A = default
}
}

implicit val schema: Schema[TestAdt] = union(
TestAdt.AdtOne.alt,
TestAdt.AdtTwo.alt,
Expand Down
Loading

0 comments on commit 9bcacd0

Please sign in to comment.