Skip to content

Conversation

@jbelkins
Copy link
Contributor

@jbelkins jbelkins commented Dec 12, 2025

Description of changes

Provides Decodable Swift types for reading JSON AST files (i.e. the AWS service models at codegen/sdk-codegen/aws-models) into memory.

Creates a SmithyCodegenCore module which uses the AST to read models into memory. Further use of the model will be in a future PR.

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

//
// SPDX-License-Identifier: Apache-2.0
//

Copy link
Contributor Author

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
//
Copy link
Contributor Author

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
}

Copy link
Contributor Author

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
//
Copy link
Contributor Author

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

Copy link
Contributor Author

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"
),
Copy link
Contributor Author

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.

@jbelkins jbelkins marked this pull request as ready for review December 12, 2025 20:59
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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@jbelkins jbelkins merged commit 514b911 into epic/sbs Dec 15, 2025
30 checks passed
@jbelkins jbelkins deleted the jbe/add_ast branch December 15, 2025 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants