-
Notifications
You must be signed in to change notification settings - Fork 68
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
add hint mask construct #70
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
0f140d5
add hint mask construct
lewisjkl 36d6370
add mask syntax
lewisjkl 1f247d2
add second remove method to Hints src-3
lewisjkl e0da2d6
work on applying hint mask to schematics from protocol builders
lewisjkl 46e8159
update renderer to render hint masks
lewisjkl 0fd0120
create missing headers
lewisjkl 1898930
remove Http specific hint traits from codegen
lewisjkl 42d92a2
unify error hint in codegen
lewisjkl 790786b
get rid of mask syntax
lewisjkl b2bfd03
fun with structs
lewisjkl 97d9d3c
relocate newTypeToHintKey conversion
lewisjkl 464129c
add smithy4s.api traits to simpleRestJson protocol
lewisjkl 43bf07b
implement hints without having remove method
lewisjkl 8ff34da
update AWS module with hintMask
lewisjkl 7e92aec
Merge remote-tracking branch 'origin/main' into hint-masks
Baccata 95b5534
Only 1 struct method to implement now
Baccata e9753bd
collectFirst + foldMap
Baccata ec2facf
Add HintMask.allAllowed, revert Aws changes
Baccata bad5119
Fix benchmarks
Baccata 33d28d9
remove hintMask as parameter from CodecAPI
lewisjkl fc6c1cd
fix aws module compilation
lewisjkl d99d85b
generate headers
lewisjkl 80e5d96
fix json module compilation
lewisjkl 189e5d3
fix json benchmark
lewisjkl f11cda8
remove hintmask from AwsProtocol
lewisjkl bd33588
clean up simpleRestJson protocolDefinition traits
lewisjkl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,62 @@ | ||
/* | ||
* 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 | ||
|
||
sealed abstract class HintMask { | ||
def ++(other: HintMask): HintMask | ||
def apply(hints: Hints): Hints | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice :) |
||
} | ||
|
||
object HintMask { | ||
|
||
def allAllowed: HintMask = Permissive | ||
|
||
def empty: HintMask = apply() | ||
|
||
def apply(hintKeys: Hints.Key[_]*): HintMask = { | ||
new Impl(hintKeys.toSet) | ||
} | ||
|
||
private[this] case object Permissive extends HintMask { | ||
def ++(other: HintMask): HintMask = this | ||
def apply(hints: Hints): Hints = hints | ||
} | ||
|
||
private[this] final class Impl(val toSet: Set[Hints.Key[_]]) | ||
extends HintMask { | ||
def ++(other: HintMask): HintMask = other match { | ||
case i: Impl => new Impl(toSet ++ i.toSet) | ||
case Permissive => Permissive | ||
} | ||
|
||
def apply(hints: Hints): Hints = { | ||
val hintsToKeep = hints.all.filter(h => toSet.contains(h.key)).toSeq | ||
Hints(hintsToKeep: _*) | ||
} | ||
} | ||
|
||
private[this] final class MaskSchematic[F[_]]( | ||
schematic: Schematic[F], | ||
mask: HintMask | ||
) extends PassthroughSchematic[F](schematic) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea ! |
||
override def withHints[A](fa: F[A], hints: Hints): F[A] = | ||
schematic.withHints(fa, mask(hints)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
def mask[F[_]](schematic: Schematic[F], mask: HintMask): Schematic[F] = | ||
new MaskSchematic[F](schematic, mask) | ||
} |
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,83 @@ | ||
/* | ||
* 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 schematic._ | ||
import java.util.UUID | ||
|
||
class PassthroughSchematic[F[_]](schematic: Schematic[F]) extends Schematic[F] { | ||
def short: F[Short] = schematic.short | ||
|
||
def int: F[Int] = schematic.int | ||
|
||
def long: F[Long] = schematic.long | ||
|
||
def double: F[Double] = schematic.double | ||
|
||
def float: F[Float] = schematic.float | ||
|
||
def bigint: F[BigInt] = schematic.bigint | ||
|
||
def bigdecimal: F[BigDecimal] = schematic.bigdecimal | ||
|
||
def string: F[String] = schematic.string | ||
|
||
def boolean: F[Boolean] = schematic.boolean | ||
|
||
def uuid: F[UUID] = schematic.uuid | ||
|
||
def byte: F[Byte] = schematic.byte | ||
|
||
def bytes: F[ByteArray] = schematic.bytes | ||
|
||
def unit: F[Unit] = schematic.unit | ||
|
||
def list[S](fs: F[S]): F[List[S]] = schematic.list(fs) | ||
|
||
def set[S](fs: F[S]): F[Set[S]] = schematic.set(fs) | ||
|
||
def vector[S](fs: F[S]): F[Vector[S]] = schematic.vector(fs) | ||
|
||
def map[K, V](fk: F[K], fv: F[V]): F[Map[K, V]] = schematic.map(fk, fv) | ||
|
||
def struct[S](fields: Vector[Field[F, S, _]])( | ||
const: Vector[Any] => S | ||
): F[S] = schematic.struct(fields)(const) | ||
|
||
def union[S](first: Alt[F, S, _], rest: Vector[Alt[F, S, _]])( | ||
total: S => Alt.WithValue[F, S, _] | ||
): F[S] = schematic.union(first, rest)(total) | ||
|
||
def enumeration[A]( | ||
to: A => (String, Int), | ||
fromName: Map[String, A], | ||
fromOrdinal: Map[Int, A] | ||
): F[A] = schematic.enumeration(to, fromName, fromOrdinal) | ||
|
||
def suspend[A](f: => F[A]): F[A] = schematic.suspend(f) | ||
|
||
def bijection[A, B](f: F[A], to: A => B, from: B => A): F[B] = | ||
schematic.bijection(f, to, from) | ||
|
||
def timestamp: F[Timestamp] = schematic.timestamp | ||
|
||
def withHints[A](fa: F[A], hints: Hints): F[A] = | ||
schematic.withHints(fa, hints) | ||
|
||
def document: F[Document] = schematic.document | ||
|
||
} |
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,48 @@ | ||
package smithy4s | ||
|
||
import smithy4s.api.Discriminated | ||
import smithy.api._ | ||
import cats.kernel.Eq | ||
import smithy4s.syntax._ | ||
|
||
object HintMaskSpec extends weaver.FunSuite { | ||
|
||
private implicit val hintsEq: Eq[Hints] = (x: Hints, y: Hints) => | ||
x.toMap == y.toMap | ||
|
||
test("Hints are masked") { | ||
val hints = Hints(Discriminated("type"), Required(), HttpError(404)) | ||
val mask = HintMask(Discriminated, Required) | ||
val result = mask(hints) | ||
val expected = Hints(Discriminated("type"), Required()) | ||
expect.eql(expected, result) | ||
} | ||
|
||
test("empty mask masks all hints") { | ||
val hints = Hints(Discriminated("type"), Required(), HttpError(404)) | ||
val mask = HintMask.empty | ||
val result = mask(hints) | ||
expect.eql(Hints(), result) | ||
} | ||
|
||
type ToHints[A] = Hints | ||
|
||
object TestCompiler extends StubSchematic[ToHints] { | ||
def default[A]: Hints = Hints() | ||
|
||
override def withHints[A](fa: ToHints[A], hints: Hints): ToHints[A] = | ||
fa ++ hints | ||
} | ||
|
||
test("hint mask is applied in schematic mask") { | ||
val schema = string.withHints(Readonly(), Paginated()) | ||
val mask = HintMask(Readonly) | ||
val newSchematic = HintMask.mask(TestCompiler, mask) | ||
val result = schema.compile(newSchematic) | ||
val expected = Hints(Readonly()) | ||
expect.eql( | ||
expected, | ||
result | ||
) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍