-
Notifications
You must be signed in to change notification settings - Fork 35
feat: Read JSON AST models into memory #1010
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
Conversation
| // | ||
| // 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.
This error just get thrown with an appropriate message if there is an error while reading an AST.
| // All Rights Reserved. | ||
| // | ||
| // 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.
This and the below AST... files are just containers for the JSON data read from the AST file.
| case boolean(Bool) | ||
| case null | ||
| } | ||
|
|
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.
Because a node in AST can be of multiple JSON types, the hand-written Decodable implementation below is provided to capture any one of them.
| // All Rights Reserved. | ||
| // | ||
| // 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.
Rather than have multiple AST shape types, for simplicity all AST shapes are read with this one ASTShape type that has all the fields of every AST shape.
When constructing the actual model from AST later, the ASTShape's type field will be used to create custom shape types and fill those types' specific fields.
| import class Foundation.FileManager | ||
| import class Foundation.JSONDecoder | ||
| import struct Foundation.URL | ||
|
|
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 type is created & called by the CLI to actually perform the codegen.
Its responsibilities
- Read the AST from the
modelFileURL(done below) - Create a model, generation context, symbol provider, etc. (TBD)
- Use the generation context to create the needed source files (TBD)
For now, it just creates an empty file at the schemas path, which is required for the build plugin to succeed.
| ), | ||
| .target( | ||
| name: "SmithyCodegenCore" | ||
| ), |
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.
Created this target for codegen components.
Eventually this may be exposed as a library, but for now it's solely a smithy-swift internal target.
| public func run() throws { | ||
| // Load the AST from the model file | ||
| let modelData = try Data(contentsOf: modelFileURL) | ||
| let astModel = try JSONDecoder().decode(ASTModel.self, from: modelData) |
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.
It does look like astModel is never used as mentioned by the automated warning. What is it for?
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.
See the comments immediately below. In a follow-up PR, ASTModel will be used to construct the actual model that is used for codegen.
Description of changes
Provides
DecodableSwift types for reading JSON AST files (i.e. the AWS service models atcodegen/sdk-codegen/aws-models) into memory.Creates a
SmithyCodegenCoremodule which uses the AST to read models into memory. Further use of the model will be in a future PR.Scope
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.