-
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.
Support range/length refinement providers for enums (#1283)
Co-authored-by: Jakub Kozłowski <[email protected]>
- Loading branch information
Showing
4 changed files
with
124 additions
and
58 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
25 changes: 25 additions & 0 deletions
25
modules/bootstrapped/src/generated/smithy4s/example/StructureConstrainingEnum.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,25 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.struct | ||
|
||
/** @param card | ||
* FaceCard types | ||
*/ | ||
final case class StructureConstrainingEnum(letter: Option[Letters] = None, card: Option[FaceCard] = None) | ||
|
||
object StructureConstrainingEnum extends ShapeTag.Companion[StructureConstrainingEnum] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "StructureConstrainingEnum") | ||
|
||
val hints: Hints = Hints.empty | ||
|
||
implicit val schema: Schema[StructureConstrainingEnum] = struct( | ||
Letters.schema.validated(smithy.api.Length(min = Some(2L), max = None)).validated(smithy.api.Pattern(s"$$aaa$$")).optional[StructureConstrainingEnum]("letter", _.letter), | ||
FaceCard.schema.validated(smithy.api.Range(min = None, max = Some(scala.math.BigDecimal(1.0)))).optional[StructureConstrainingEnum]("card", _.card), | ||
){ | ||
StructureConstrainingEnum.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
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,15 @@ | ||
$version: "2" | ||
|
||
namespace smithy4s.example | ||
|
||
// see https://github.com/disneystreaming/smithy4s/issues/1282 | ||
// We're testing that the render code compiles correctly, which | ||
// depends on the presence of a RefinementProvider between Range | ||
// and an enumeration value. | ||
structure StructureConstrainingEnum { | ||
@length(min: 2) | ||
@pattern("$aaa$") | ||
letter: Letters | ||
@range(max: 1) | ||
card: FaceCard | ||
} |