-
Notifications
You must be signed in to change notification settings - Fork 0
Generate structs for tuples #9
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,15 +70,15 @@ object SmithyConverter: | |
| val parts = List(common.mkString, outlier).sorted | ||
| s"${parts(0)}Or${parts(1)}" | ||
| else if suffix.nonEmpty then suffix.mkString + "Union" | ||
| else s"Union_${MurmurHash3.indexedSeqHash(types, 0)}" | ||
| else s"Union_${Math.abs(MurmurHash3.indexedSeqHash(types, 0))}" | ||
|
|
||
| private def extractTypeName(t: Type): String = t match | ||
| case Type.ReferenceType(name) => name.value | ||
| case Type.BaseType(base) => base.toString.capitalize | ||
| case Type.ArrayType(inner) => s"ListOf${extractTypeName(inner)}" | ||
| case Type.MapType(k, v) => s"MapOf${extractTypeName(k)}To${extractTypeName(v)}" | ||
| case Type.StringLiteralType(_) | Type.BooleanLiteralType(_) => "Literal" | ||
| case Type.StructureLiteralType(StructureLiteral(props, _)) => s"Literal${MurmurHash3.indexedSeqHash(props, 0)}" | ||
| case Type.StructureLiteralType(StructureLiteral(props, _)) => s"Literal${Math.abs(MurmurHash3.indexedSeqHash(props, 0))}" | ||
| case _ => "" | ||
|
|
||
| private def splitPascal(s: String): List[String] = | ||
|
|
@@ -193,18 +193,27 @@ object SmithyConverter: | |
| case TupleType(items) => | ||
| for | ||
| items_ <- items.traverse(t => smithyType(t, namespace)) | ||
| unifiedType = items_.distinct match | ||
| case Seq(one) => one | ||
| case _ => ShapeId.from("smithy.api#String") // TODO: fallback | ||
| listId = ShapeId.fromParts(namespace, s"TupleOf${unifiedType.getName}") | ||
| tupleId = ShapeId.fromParts(namespace, s"TupleOf${items_.map(_.getName).mkString}") | ||
| result <- State[Set[Shape], ShapeId] { shapes => | ||
| val listShape = ListShape | ||
| val tupleBuilder = StructureShape | ||
| .builder() | ||
| .id(listId) | ||
| .id(tupleId) | ||
| .addTrait(TupleTrait.builder().build()) | ||
| .member(MemberShape.builder().id(listId.withMember("member")).target(unifiedType).build()) | ||
| .build() | ||
| (shapes + listShape, listId) | ||
|
|
||
| items_.zipWithIndex.foreach { case (m, i) => | ||
| tupleBuilder.addMember( | ||
| MemberShape | ||
| .builder() | ||
| .id(tupleId.withMember(s"_$i")) | ||
|
Contributor
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. I think we'll want some meaningful names for these. Probably using a mechanism similar to neandertech/langoustine#204
Contributor
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. e.g.
Contributor
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. but I'm happy to make it a ticket
Contributor
Author
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. yeah let's leave it for later |
||
| .target(m) | ||
| .addTrait( | ||
| new RequiredTrait.Provider().createTrait(RequiredTrait.ID, Node.objectNode) | ||
| ) | ||
| .build() | ||
| ) | ||
| } | ||
|
|
||
| (shapes + tupleBuilder.build(), tupleId) | ||
| } | ||
| yield result | ||
|
|
||
|
|
@@ -237,7 +246,7 @@ object SmithyConverter: | |
| } | ||
|
|
||
| case StructureLiteralType(StructureLiteral(properties, false)) => | ||
| val id = ShapeId.fromParts(namespace, s"InlineStruct${MurmurHash3.indexedSeqHash(properties, 0)}") | ||
| val id = ShapeId.fromParts(namespace, s"InlineStruct${Math.abs(MurmurHash3.indexedSeqHash(properties, 0))}") | ||
| structureMembers(id, properties) | ||
| .map(_.foldLeft(StructureShape.builder().id(id)) { case (acc, item) => acc.addMember(item) }.build()) | ||
| .flatMap { structureShape => | ||
|
|
||
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.
negative hashes are my passion