Skip to content

Conversation

@jbelkins
Copy link
Contributor

Description of changes

  • Adds Model and the code to create it from the AST
  • Adds SymbolProvider, to convert Smithy shapes to their Swift equivalents
  • Adds GenerationContext to hold references to codegen components
  • Deletes ASTNode. Smithy.Node is used in AST instead (with a Decodable extension) since it is entirely the same type.

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.

import protocol SmithyHTTPAuthAPI.AuthSchemeResolver
import protocol SmithyHTTPAuthAPI.AuthSchemeResolverParameters
import struct SmithyRetries.DefaultRetryStrategy
import struct SmithyRetries.ExponentialBackoffStrategy
Copy link
Contributor Author

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
//

Copy link
Contributor Author

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
//

Copy link
Contributor Author

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

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

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

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 }
}
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 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.
}
}

Copy link
Contributor Author

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 {
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 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)"
}
}

Copy link
Contributor Author

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.

@jbelkins jbelkins marked this pull request as ready for review December 17, 2025 17:48
Copy link
Contributor

@sichanyoo sichanyoo left a 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.
Copy link
Contributor

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?

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