-
Notifications
You must be signed in to change notification settings - Fork 35
Schema-based serialization working branch #998
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
Draft
jbelkins
wants to merge
103
commits into
epic/sbs
Choose a base branch
from
jbe/swift_codegen_schema
base: epic/sbs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 23 commits
Commits
Show all changes
103 commits
Select commit
Hold shift + click to select a range
495f2e1
Disable input/output serializers
jbelkins ca5b331
add ShapeID, doc comments
jbelkins 212120e
Re-enable serde code
jbelkins fcdf1bf
Cleanup
jbelkins b2152c2
Merge branch 'main' into jbe/add_schema
jbelkins 88f7be9
Merge branch 'main' into jbe/add_schema
jbelkins aa823be
feat: Add Swift-native codegen plugin
jbelkins e817d55
Fix lint
jbelkins 6a9c537
Make service trait optional
jbelkins 33cc093
Fix ktlint again
jbelkins 6b54575
Refactor code generator plugin
jbelkins ae474f1
Convert smithy model info file to .json
jbelkins 70f7669
Fix Swift 5.9 URL initializer
jbelkins 3d623e6
Code cleanup
jbelkins d535e66
Revert disabling of schemas
jbelkins 52f9532
Schemas generate for entire SDK
jbelkins 1fa7fbd
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 70e8a15
Fix method name renderSchema
jbelkins b1548a7
Fix swiftlint
jbelkins 94a901d
Fix ktlint
jbelkins 54a4300
Fix SmithyCodegenCoreTests
jbelkins 6b860df
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 1eb996b
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 3fd9854
Cleanup
jbelkins 64dd13a
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 6a65655
Fixes
jbelkins db5b76a
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 64eeff9
More codegen added
jbelkins 953e1d9
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 260e5ca
Serializes to string
jbelkins 2e73154
Serializes maps & lists to string
jbelkins 0a3b8c6
Fix rendered string for structure
jbelkins 05d8088
Convert ShapeSerializer methods to throwing
jbelkins dbfb2af
Add deser code
jbelkins b19ab8c
Clarify doc comment
jbelkins d99a7c0
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 811c8cc
Comments, fix swiftlint
jbelkins 1005d47
Refine serializer interfaces
jbelkins 707ab1a
refactor, added codec
jbelkins 46b0808
Separate methods named sdkId, prune model to one service
jbelkins bf7b1b3
Protocol tests now run
jbelkins 6550aab
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 5ecb766
CBOR serialization passes protocol tests
jbelkins 7a2eb11
All CBOR protocol tests pass, with local CRT changes
jbelkins 82196f9
Fix swiftlint, ktlint, refactor
jbelkins 6a07b2d
Added ClientProtocol
jbelkins aab0ecc
immediateDescendant refactor
jbelkins ee07905
Add query compatibility extensions
jbelkins faba2fc
Enable query mode
jbelkins 9929a5f
Convert schemas to struct
jbelkins 1257136
Add query compatibility, fix tests
jbelkins 9ac9104
Fix Swift unit tests
jbelkins 0abd9bc
No model info file for non-schema based svcs
jbelkins 30c3184
TypeRegistry sendable
jbelkins 36348a3
DeserializableShape: Sendable
jbelkins 8ff310f
Refactor query compatible from TypeRegistry to ClientProtocol impl
jbelkins 5908312
Fix swiftlint, rename
jbelkins 1ba6543
Move query compatibility logic out
jbelkins 8cb08ab
Fixes & model transforms so all but 6 svcs build
jbelkins 87e8112
Whole SDK builds schema-based code now
jbelkins fe5aa9f
Fix compile warnings
jbelkins 49cf3c6
Code cleanup
jbelkins 7ce66d4
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 4f961f7
Fix lint
jbelkins 797ddd1
Simplify deser interfaces, test StringSerializer
jbelkins 8ee1e87
Add clarifying comments on force unwraps
jbelkins 4b2d01f
Merge branch 'jbe/codegen_core' into jbe/swift_codegen_schema
jbelkins 67a016b
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 3e47875
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 3b423c5
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 367ab7d
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins b2b2351
CBOR uses plugin for path
jbelkins 15d5e8d
Restore deprecations, fix lint
jbelkins 1ab0a7f
Fix build for all services
jbelkins 8256563
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 29c0786
Internal clients generate compiling code
jbelkins f4f8a81
Fix lint
jbelkins 4971dfc
Fix broken tests
jbelkins 9e8d3cd
AWS JSON svcs build with schema-based
jbelkins f90b41d
Fix SmithyModelInfo whitespace
jbelkins 61bed21
Fix lint
jbelkins ff47f1f
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins bcd6dc7
Fix trailing comma in Package.swift
jbelkins 85b016d
AWSJSON protocol tests now pass
jbelkins 1686cdb
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 09818e2
Pin swift-argument-parser while awaiting resolution of Swift 5.x issues
jbelkins ef21da0
Merge branch 'epic/sbs' into jbe/swift_codegen_schema
jbelkins 1126577
Code cleanup, fix tests
jbelkins cfbca36
Fix lint
jbelkins 4d43f12
Fix Swift 6 compile issue
jbelkins eec5714
More Swift 6 fixes
jbelkins ae04109
More Swift 6 fixes
jbelkins b2ee536
Even more Swift 6 fixes
jbelkins ac75b38
Get client name from settings sdkId
jbelkins 242814d
Fix event stream protocol test build
jbelkins 24a1bb9
Disable initial response integration
jbelkins d4109c1
Fix ktlint
jbelkins 9fe9d83
Only add operations CLI param if operations is non empty
jbelkins b3c3a03
Remove timeout on smithy-swift CI
jbelkins a4f284a
feat: Add operation and type registry codegen
jbelkins 52a642c
Fix SmithyCodegenCoreTests
jbelkins 3eb8e82
Add support for service closure renames
jbelkins b1b4b55
Merge branch 'jbe/operations_and_type_registry' into jbe/swift_codege…
jbelkins 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 hidden or 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 hidden or 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,21 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| /// The trait IDs that should be copied into schemas. Other traits are omitted for brevity. | ||
| /// | ||
| /// This list can be expanded as features are added to Smithy/SDK that use them. | ||
| public let permittedTraitIDs: Set<String> = [ | ||
| "smithy.api#sparse", | ||
| "smithy.api#input", | ||
| "smithy.api#output", | ||
| "smithy.api#error", | ||
| "smithy.api#enumValue", | ||
| "smithy.api#jsonName", | ||
| "smithy.api#required", | ||
| "smithy.api#default", | ||
| "smithy.api#timestampFormat", | ||
| ] |
This file contains hidden or 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 hidden or 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,14 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
jbelkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public struct ASTError: Error { | ||
| public let localizedDescription: String | ||
|
|
||
| init(_ localizedDescription: String) { | ||
| self.localizedDescription = localizedDescription | ||
| } | ||
| } | ||
This file contains hidden or 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,11 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| struct ASTMember: Decodable { | ||
| let target: String | ||
| let traits: [String: ASTNode]? | ||
| } |
This file contains hidden or 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,12 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| struct ASTModel: Decodable { | ||
| let smithy: String | ||
| let metadata: ASTNode? | ||
| let shapes: [String: ASTShape] | ||
| } |
This file contains hidden or 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,45 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| /// Contains the value of a Smithy Node, as used in a JSON AST. | ||
| /// | ||
| /// Smithy node data is basically the same as the data that can be stored in JSON. | ||
| /// The root of a Smithy node may be of any type, i.e. unlike JSON, the root element is not limited to object or list. | ||
| /// | ||
| /// See the definition of node value in the Smithy spec: https://smithy.io/2.0/spec/model.html#node-values | ||
| enum ASTNode: Sendable { | ||
| case object([String: ASTNode]) | ||
| case list([ASTNode]) | ||
| case string(String) | ||
| case number(Double) | ||
| case boolean(Bool) | ||
| case null | ||
| } | ||
|
|
||
| extension ASTNode: Decodable { | ||
|
|
||
| init(from decoder: any Decoder) throws { | ||
| let container = try decoder.singleValueContainer() | ||
| if container.decodeNil() { | ||
| self = .null | ||
| } else if let bool = try? container.decode(Bool.self) { | ||
| self = .boolean(bool) | ||
| } else if let int = try? container.decode(Int.self) { | ||
| self = .number(Double(int)) | ||
| } else if let double = try? container.decode(Double.self) { | ||
| self = .number(double) | ||
| } else if let string = try? container.decode(String.self) { | ||
| self = .string(string) | ||
| } else if let array = try? container.decode([ASTNode].self) { | ||
| self = .list(array) | ||
| } else if let dictionary = try? container.decode([String: ASTNode].self) { | ||
| self = .object(dictionary) | ||
| } else { | ||
| throw ASTError("Undecodable value in AST node") | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,10 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| struct ASTReference: Decodable { | ||
| let target: String | ||
| } |
This file contains hidden or 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,31 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| struct ASTShape: Decodable { | ||
| let type: ASTType | ||
| let traits: [String: ASTNode]? | ||
| let member: ASTMember? | ||
| let key: ASTMember? | ||
| let value: ASTMember? | ||
| let members: [String: ASTMember]? | ||
| let version: String? | ||
| let operations: [ASTReference]? | ||
| let resources: [ASTReference]? | ||
| let errors: [ASTReference]? | ||
| let rename: [String: String]? | ||
| let identifiers: [String: ASTReference]? | ||
| let properties: [String: ASTReference]? | ||
| let create: ASTReference? | ||
| let put: ASTReference? | ||
| let read: ASTReference? | ||
| let update: ASTReference? | ||
| let delete: ASTReference? | ||
| let list: ASTReference? | ||
| let collectionOperations: [ASTReference]? | ||
| let input: ASTReference? | ||
| let output: ASTReference? | ||
| } |
This file contains hidden or 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,37 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| enum ASTType: String, Decodable { | ||
| // These cases are all the Smithy shape types | ||
| case blob | ||
| case boolean | ||
| case string | ||
| case timestamp | ||
| case byte | ||
| case short | ||
| case integer | ||
| case long | ||
| case float | ||
| case document | ||
| case double | ||
| case bigDecimal | ||
| case bigInteger | ||
| case `enum` | ||
| case intEnum | ||
| case list | ||
| case set | ||
| case map | ||
| case structure | ||
| case union | ||
| case member | ||
| case service | ||
| case resource | ||
| case operation | ||
|
|
||
| // Special for AST, added 'apply' case | ||
| case apply | ||
| } |
This file contains hidden or 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,30 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| import struct Foundation.Data | ||
| import struct Foundation.URL | ||
|
|
||
| public struct CodeGenerator { | ||
| let modelFileURL: URL | ||
| let schemasFileURL: URL? | ||
|
|
||
| public init(modelFileURL: URL, schemasFileURL: URL?) { | ||
| self.modelFileURL = modelFileURL | ||
| self.schemasFileURL = schemasFileURL | ||
| } | ||
|
|
||
| public func run() throws { | ||
| // Load the model from the model file | ||
| let model = try Model(modelFileURL: modelFileURL) | ||
|
|
||
| // If a schema file URL was provided, generate it | ||
| if let schemasFileURL { | ||
| let schemaContents = try SmithySchemaCodegen().generate(model: model) | ||
| try Data(schemaContents.utf8).write(to: schemasFileURL) | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,14 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| struct CodegenError: Error { | ||
| let localizedDescription: String | ||
|
|
||
| init(_ localizedDescription: String) { | ||
| self.localizedDescription = localizedDescription | ||
| } | ||
| } |
This file contains hidden or 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,87 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| import struct Foundation.Data | ||
| import class Foundation.JSONDecoder | ||
| import struct Foundation.URL | ||
|
|
||
| public class Model { | ||
| public let version: String | ||
| public let metadata: Node? | ||
| public let shapes: [ShapeID: Shape] | ||
|
|
||
| public convenience init(modelFileURL: URL) throws { | ||
| let modelData = try Data(contentsOf: modelFileURL) | ||
| let astModel = try JSONDecoder().decode(ASTModel.self, from: modelData) | ||
| try self.init(astModel: astModel) | ||
| } | ||
|
|
||
| init(astModel: ASTModel) throws { | ||
| self.version = astModel.smithy | ||
| self.metadata = astModel.metadata?.modelNode | ||
| let idToShapePairs = try astModel.shapes.map { try Self.shapePair(id: $0.key, astShape: $0.value) } | ||
| let idToMemberShapePairs = try astModel.shapes.flatMap { astShape in | ||
| try Self.memberShapePairs(id: astShape.key, astShape: astShape.value) | ||
| } | ||
| self.shapes = Dictionary(uniqueKeysWithValues: idToShapePairs + idToMemberShapePairs) | ||
|
|
||
| // self is now initialized, perform post-initialization wireup | ||
|
|
||
| // set the Shapes with references back to this model | ||
| self.shapes.values.forEach { $0.model = self } | ||
|
|
||
| // set the memberIDs for each Shape | ||
| self.shapes.values.filter { $0.type != .member }.forEach { shape in | ||
| let namespace = shape.id.namespace | ||
| let name = shape.id.name | ||
| let memberIDs: [ShapeID] = Array(self.shapes.keys) | ||
| let filteredMemberIDs = memberIDs.filter { | ||
| $0.namespace == namespace && $0.name == name && $0.member != nil | ||
| } | ||
| shape.memberIDs = filteredMemberIDs.sorted() | ||
| } | ||
| } | ||
|
|
||
| private static func shapePair(id: String, astShape: ASTShape) throws -> (ShapeID, Shape) { | ||
| let shapeID = try ShapeID(id) | ||
| let idToTraitPairs = try astShape.traits?.map { (try ShapeID($0.key), $0.value.modelNode) } ?? [] | ||
| let shape = Shape( | ||
| id: shapeID, | ||
| type: astShape.type.modelType, | ||
| traits: Dictionary(uniqueKeysWithValues: idToTraitPairs), | ||
| targetID: nil | ||
| ) | ||
| return (shapeID, shape) | ||
| } | ||
|
|
||
| private static func memberShapePairs(id: String, astShape: ASTShape) throws -> [(ShapeID, Shape)] { | ||
| var baseMembers = (astShape.members ?? [:]) | ||
| if let member = astShape.member { | ||
| baseMembers["member"] = member | ||
| } | ||
| if let key = astShape.key { | ||
| baseMembers["key"] = key | ||
| } | ||
| if let value = astShape.value { | ||
| baseMembers["value"] = value | ||
| } | ||
| return try baseMembers.map { astMember in | ||
| let memberID = ShapeID(id: try ShapeID(id), member: astMember.key) | ||
| let traitPairs = try astMember.value.traits?.map { (try ShapeID($0.key), $0.value.modelNode) } | ||
| let traits = Dictionary(uniqueKeysWithValues: traitPairs ?? []) | ||
| let targetID = try ShapeID(astMember.value.target) | ||
| return (memberID, Shape(id: memberID, type: .member, traits: traits, targetID: targetID)) | ||
| } | ||
| } | ||
|
|
||
| func expectShape(id: ShapeID) throws -> Shape { | ||
| guard let shape = shapes[id] else { | ||
| throw ModelError("ShapeID \(id) was expected in model but not found") | ||
| } | ||
| return shape | ||
| } | ||
| } |
This file contains hidden or 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,14 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| public struct ModelError: Error { | ||
| public let localizedDescription: String | ||
|
|
||
| init(_ localizedDescription: String) { | ||
| self.localizedDescription = localizedDescription | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.