-
Notifications
You must be signed in to change notification settings - Fork 35
feat: Add generation context #1011
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
base: epic/sbs
Are you sure you want to change the base?
Conversation
| import protocol SmithyHTTPAuthAPI.AuthSchemeResolver | ||
| import protocol SmithyHTTPAuthAPI.AuthSchemeResolverParameters | ||
| import struct SmithyRetries.DefaultRetryStrategy | ||
| import struct SmithyRetries.ExponentialBackoffStrategy |
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.
Swiftlint rearranged imports in a few files here & below.
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
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.
ShapeID has added methods for creating IDs from the string identifiers in AST, and for allowing sort-by-ShapeID.
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
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.
ASTNode has been replaced by Smithy.Node since the two types were identical.
The change is made here & in several other AST types below.
| case boolean(Bool) | ||
| case null | ||
| } | ||
| import enum Smithy.Node |
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.
ASTNode is deleted & Smithy.Node is used instead.
The Decodable extension below is applied to Smithy.Node instead of to ASTNode.
| import enum Smithy.Node | ||
| import struct Smithy.ShapeID | ||
|
|
||
| extension Model { |
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.
Here, an extension on Model is provided to create one from JSON AST.
See the ample inline comments below for details.
|
|
||
| import struct Smithy.ShapeID | ||
|
|
||
| extension ASTReference { |
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.
This is a convenience method to convert an ASTReference to a Smithy.ShapeID.
Used during conversion of JSON AST to Model.
|
|
||
| import enum Smithy.ShapeType | ||
|
|
||
| extension ASTType { |
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.
This is a convenience method to convert an ASTType to a Smithy.ShapeType.
Used during conversion of JSON AST to Model.
|
|
||
| import enum Smithy.Node | ||
| import struct Smithy.ShapeID | ||
| import enum Smithy.ShapeType |
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.
Here & below are specialized Shape types for use in the Model.
All shapes descend from a Shape base class, similar to in Smithy codegen.
| /// Protocol provided as a convenience to get members from Shapes that have them. | ||
| protocol HasMembers { | ||
| var members: [MemberShape] { get } | ||
| } |
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.
This protocol is a convenience to get members from a shape, since the specific shape types with members don't have a common superclass that does.
| [] // default. May be overridden by Shape subclasses. | ||
| } | ||
| } | ||
|
|
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.
Note below that a Shape's equality, order, etc. is determined based on its ID.
| private var errorTraitID = ShapeID("smithy.api", "error") | ||
| private var operationNameTraitID = ShapeID("swift.synthetic", "operationName") | ||
|
|
||
| public func swiftType(shape: Shape) throws -> String { |
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.
This method contains fairly complex logic to get a Swift type for a Smithy shape.
I plan to simplify this greatly in a future PR, which will implement model transforms. So maybe ignore this code for now.
| return try "\(serviceName)ClientTypes.\(shape.id.name)" | ||
| } | ||
| } | ||
|
|
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.
The code below for determining a property or enum case name for a MemberShape is lifted directly out of existing smithy-swift-codegen. The logic must match because the models themselves are still generated in smithy-swift-codegen.
sichanyoo
left a comment
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.
Read through changes & just had one nit on comment.
| /// Compared to the AST model, this model has custom shape types, members are included in the main body of shapes | ||
| /// along with other shape types, and all Shape IDs are fully-qualified | ||
| /// (i.e. members have the enclosing shape's namespace & name, along with their own member name.) | ||
| /// - Parameter astModel: The JSON AST model to be created. |
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.
nit: The JSON AST Model to be consummed / converted?
Description of changes
Modeland the code to create it from the ASTSymbolProvider, to convert Smithy shapes to their Swift equivalentsGenerationContextto hold references to codegen componentsASTNode.Smithy.Nodeis used in AST instead (with aDecodableextension) since it is entirely the same type.Scope
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.