Skip to content

Commit c32b39b

Browse files
committed
Cleanup
1 parent 6e2519b commit c32b39b

File tree

7 files changed

+57
-57
lines changed

7 files changed

+57
-57
lines changed

Sources/Smithy/Schema/Schema.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
/// A structure which describes selected Smithy model information for a Smithy model shape.
8+
/// A class which describes selected Smithy model information for a Smithy model shape.
99
///
1010
/// Typically, the Schema contains only modeled info & properties that are relevant to
1111
/// serialization, transport bindings, and other functions performed by the SDK.
12-
public class Schema {
12+
public final class Schema: Sendable {
1313

1414
/// The Smithy shape ID for the shape described by this schema.
1515
public let id: ShapeID
16-
16+
1717
/// The type of the shape being described.
1818
public let type: ShapeType
19-
19+
2020
/// A dictionary of the described shape's trait shape IDs to Nodes with trait data.
2121
///
2222
/// Not all traits for a shape will be represented in the schema;
2323
/// typically the Schema contains only the traits relevant to the client-side SDK.
2424
public let traits: [ShapeID: Node]
25-
25+
2626
/// The member schemas for this schema, if any.
2727
///
2828
/// Typically only a schema of type Structure, Union, Enum, IntEnum, List or Map will have members.
@@ -39,7 +39,7 @@ public class Schema {
3939
/// This index is intended for use as a performance enhancement when looking up member schemas
4040
/// during deserialization.
4141
public let index: Int
42-
42+
4343
/// Creates a new Schema using the passed parameters.
4444
///
4545
/// No validation is performed on the parameters since calls to this initializer

Sources/Smithy/Schema/ShapeID.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
/// Represents a single Smithy shape ID.
99
///
1010
/// Shape ID is described in the Smithy 2.0 spec [here](https://smithy.io/2.0/spec/model.html#shape-id).
11-
public struct ShapeID: Hashable {
11+
public struct ShapeID: Sendable, Hashable {
1212
public let namespace: String
1313
public let name: String
1414
public let member: String?
15-
15+
1616
/// Creates a Shape ID for a Smithy shape.
1717
///
1818
/// This initializer does no validation of length or of allowed characters in the Shape ID;
@@ -30,7 +30,7 @@ public struct ShapeID: Hashable {
3030
}
3131

3232
extension ShapeID: CustomStringConvertible {
33-
33+
3434
/// Returns the absolute Shape ID in a single, printable string.
3535
public var description: String {
3636
if let member = self.member {

Sources/Smithy/Schema/ShapeType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
/// Reproduces the cases in Smithy [ShapeType](https://github.com/smithy-lang/smithy/blob/main/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeType.java).
9-
public enum ShapeType {
9+
public enum ShapeType: Sendable {
1010
case blob
1111
case boolean
1212
case string

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HTTPBindingProtocolGenerator.kt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ abstract class HTTPBindingProtocolGenerator(
142142
override var serviceErrorProtocolSymbol: Symbol = ClientRuntimeTypes.Http.HttpError
143143

144144
override fun generateSerializers(ctx: ProtocolGenerator.GenerationContext) {
145-
// if (usesSchemaBasedSerialization(ctx)) { return } // temporary condition
145+
// if (usesSchemaBasedSerialization(ctx)) return // temporary condition
146146
// render conformance to HttpRequestBinding for all input shapes
147147
val inputShapesWithHttpBindings: MutableSet<ShapeId> = mutableSetOf()
148148
for (operation in getHttpBindingOperations(ctx)) {
@@ -191,14 +191,14 @@ abstract class HTTPBindingProtocolGenerator(
191191
}
192192

193193
override fun generateDeserializers(ctx: ProtocolGenerator.GenerationContext) {
194-
// if (usesSchemaBasedSerialization(ctx)) { return } // temporary condition
194+
// if (usesSchemaBasedSerialization(ctx)) return // temporary condition
195195
val httpOperations = getHttpBindingOperations(ctx)
196196
val httpBindingResolver = getProtocolHttpBindingResolver(ctx, defaultContentType)
197197
httpResponseGenerator.render(ctx, httpOperations, httpBindingResolver)
198198
}
199199

200200
override fun generateCodableConformanceForNestedTypes(ctx: ProtocolGenerator.GenerationContext) {
201-
// if (usesSchemaBasedSerialization(ctx)) { return } // temporary condition
201+
// if (usesSchemaBasedSerialization(ctx)) return // temporary condition
202202
val nestedShapes =
203203
resolveShapesNeedingCodableConformance(ctx)
204204
.filter { !it.isEventStreaming }
@@ -209,12 +209,14 @@ abstract class HTTPBindingProtocolGenerator(
209209

210210
private fun usesSchemaBasedSerialization(ctx: ProtocolGenerator.GenerationContext): Boolean =
211211
// This fun is temporary; it will be eliminated when all services/protocols are moved to schema-based
212-
ctx.service.allTraits.keys.any { it.name == "rpcv2Cbor" || it.name == "awsJson1_0" || it.name == "awsJson1_1" }
212+
ctx.service.allTraits.keys
213+
.any { it.name == "rpcv2Cbor" }
213214

214215
override fun generateSchemas(ctx: ProtocolGenerator.GenerationContext) {
215-
if (!usesSchemaBasedSerialization(ctx)) { return } // temporary condition
216-
val nestedShapes = resolveShapesNeedingSchema(ctx)
217-
.filter { it.type != ShapeType.MEMBER } // Member schemas are only rendered in-line
216+
if (!usesSchemaBasedSerialization(ctx)) return // temporary condition
217+
val nestedShapes =
218+
resolveShapesNeedingSchema(ctx)
219+
.filter { it.type != ShapeType.MEMBER } // Member schemas are only rendered in-line
218220
nestedShapes.forEach { renderSchemas(ctx, it) }
219221
}
220222

@@ -240,7 +242,7 @@ abstract class HTTPBindingProtocolGenerator(
240242
ctx: ProtocolGenerator.GenerationContext,
241243
shape: Shape,
242244
) {
243-
// if (!usesSchemaBasedSerialization(ctx)) { return } // temporary condition
245+
// if (!usesSchemaBasedSerialization(ctx)) return // temporary condition
244246
if (!shape.hasTrait<NeedsReaderTrait>() && !shape.hasTrait<NeedsWriterTrait>()) {
245247
return
246248
}
@@ -400,12 +402,13 @@ abstract class HTTPBindingProtocolGenerator(
400402
}
401403

402404
private fun resolveShapesNeedingSchema(ctx: ProtocolGenerator.GenerationContext): Set<Shape> {
403-
val topLevelInputMembers = getHttpBindingOperations(ctx).flatMap {
404-
val inputShape = ctx.model.expectShape(it.input.get())
405-
inputShape.members()
406-
}
407-
.map { ctx.model.expectShape(it.target) }
408-
.toSet()
405+
val topLevelInputMembers =
406+
getHttpBindingOperations(ctx)
407+
.flatMap {
408+
val inputShape = ctx.model.expectShape(it.input.get())
409+
inputShape.members()
410+
}.map { ctx.model.expectShape(it.target) }
411+
.toSet()
409412

410413
val topLevelOutputMembers =
411414
getHttpBindingOperations(ctx)

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/serde/schema/SchemaGenerator.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class SchemaGenerator(
2525
}
2626
}
2727

28-
private fun renderSchemaStruct(shape: Shape, index: Int? = null) {
28+
private fun renderSchemaStruct(
29+
shape: Shape,
30+
index: Int? = null,
31+
) {
2932
writer.openBlock(".init(", "),") {
3033
writer.write(
3134
"id: \$L,",
@@ -68,9 +71,7 @@ class SchemaGenerator(
6871
id.member.getOrNull()?.let { writer.format(", \$S", it) } ?: "",
6972
)
7073

71-
private fun targetShape(shape: Shape): Shape? =
72-
memberShape(shape)?.let { ctx.model.expectShape(it.target) }
74+
private fun targetShape(shape: Shape): Shape? = memberShape(shape)?.let { ctx.model.expectShape(it.target) }
7375

74-
private fun memberShape(shape: Shape): MemberShape? =
75-
shape.asMemberShape().getOrNull()
76+
private fun memberShape(shape: Shape): MemberShape? = shape.asMemberShape().getOrNull()
7677
}

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/serde/schema/SchemaShapeUtils.kt

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,35 @@ fun Shape.schemaVar(writer: SwiftWriter): String =
1414
}
1515

1616
private fun ShapeId.preludeSchemaVarName(writer: SwiftWriter): String {
17-
val propertyName = when (this.name) {
18-
"Unit" -> "unitSchema"
19-
"String" -> "stringSchema"
20-
"Blob" -> "blobSchema"
21-
"Integer" -> "integerSchema"
22-
"Timestamp" -> "timestampSchema"
23-
"Boolean" -> "booleanSchema"
24-
"Float" -> "floatSchema"
25-
"Double" -> "doubleSchema"
26-
"Long" -> "longSchema"
27-
"Short" -> "shortSchema"
28-
"Byte" -> "byteSchema"
29-
"PrimitiveInteger" -> "primitiveIntegerSchema"
30-
"PrimitiveBoolean" -> "primitiveBooleanSchema"
31-
"PrimitiveFloat" -> "primitiveFloatSchema"
32-
"PrimitiveDouble" -> "primitiveDoubleSchema"
33-
"PrimitiveLong" -> "primitiveLongSchema"
34-
"PrimitiveShort" -> "primitiveShortSchema"
35-
"PrimitiveByte" -> "primitiveByteSchema"
36-
"Document" -> "documentSchema"
37-
else -> throw Exception("Unhandled prelude type converted to schemaVar: ${this.name}")
38-
}
17+
val propertyName =
18+
when (this.name) {
19+
"Unit" -> "unitSchema"
20+
"String" -> "stringSchema"
21+
"Blob" -> "blobSchema"
22+
"Integer" -> "integerSchema"
23+
"Timestamp" -> "timestampSchema"
24+
"Boolean" -> "booleanSchema"
25+
"Float" -> "floatSchema"
26+
"Double" -> "doubleSchema"
27+
"Long" -> "longSchema"
28+
"Short" -> "shortSchema"
29+
"Byte" -> "byteSchema"
30+
"PrimitiveInteger" -> "primitiveIntegerSchema"
31+
"PrimitiveBoolean" -> "primitiveBooleanSchema"
32+
"PrimitiveFloat" -> "primitiveFloatSchema"
33+
"PrimitiveDouble" -> "primitiveDoubleSchema"
34+
"PrimitiveLong" -> "primitiveLongSchema"
35+
"PrimitiveShort" -> "primitiveShortSchema"
36+
"PrimitiveByte" -> "primitiveByteSchema"
37+
"Document" -> "documentSchema"
38+
else -> throw Exception("Unhandled prelude type converted to schemaVar: ${this.name}")
39+
}
3940
return writer.format("\$N.\$L", SmithyTypes.Prelude, propertyName)
4041
}
4142

4243
private fun ShapeId.schemaVarName(): String {
4344
assert(this.member.getOrNull() == null)
4445
val namespacePortion = this.namespace.replace(".", "_")
4546
val namePortion = this.name
46-
return "schema__${namespacePortion}__${namePortion}"
47+
return "schema__${namespacePortion}__$namePortion"
4748
}

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyReadWriteTypes.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ object SmithyReadWriteTypes {
2727
val WritingClosures = runtimeSymbol("WritingClosures", SwiftDeclaration.ENUM)
2828
val ReadingClosureBox = runtimeSymbol("ReadingClosureBox", SwiftDeclaration.STRUCT)
2929
val WritingClosureBox = runtimeSymbol("WritingClosureBox", SwiftDeclaration.STRUCT)
30-
val ShapeSerializer = runtimeSymbol("ShapeSerializer", SwiftDeclaration.PROTOCOL)
31-
val ShapeDeserializer = runtimeSymbol("ShapeDeserializer", SwiftDeclaration.PROTOCOL)
32-
val SerializableStruct = runtimeSymbol("SerializableStruct", SwiftDeclaration.PROTOCOL)
33-
val DeserializableStruct = runtimeSymbol("DeserializableStruct", SwiftDeclaration.PROTOCOL)
34-
val Unit = runtimeSymbol("Unit", SwiftDeclaration.STRUCT)
3530
}
3631

3732
private fun runtimeSymbol(

0 commit comments

Comments
 (0)