awslabs / aws-sdk-swift

Apache License 2.0
400 stars 80 forks source link

AWSIoTFleetwise fails to build due to recursive unions #1234

Closed jbelkins closed 11 months ago

jbelkins commented 11 months ago

Describe the bug

Due to a recent model change in the AWSIoTFleetwise service, the following compile error (and a couple similar ones) occurs:

/__w/aws-sdk-swift/aws-sdk-swift/Sources/Services/AWSIoTFleetWise/models/Models.swift:8481:19: error: value type 'IoTFleetWiseClientTypes.MessageSignal' has infinite size
    public struct MessageSignal: Swift.Equatable {
                  ^
/__w/aws-sdk-swift/aws-sdk-swift/Sources/Services/AWSIoTFleetWise/models/Models.swift:8484:20: note: cycle beginning here: IoTFleetWiseClientTypes.StructuredMessage? -> (some(_:): IoTFleetWiseClientTypes.StructuredMessage) -> (structuredmessagelistdefinition(_:): IoTFleetWiseClientTypes.StructuredMessageListDefinition) -> (memberType: IoTFleetWiseClientTypes.StructuredMessage?)
        public var structuredMessage: IoTFleetWiseClientTypes.StructuredMessage?
                   ^
/__w/aws-sdk-swift/aws-sdk-swift/Sources/Services/AWSIoTFleetWise/models/Models.swift:10662:17: error: recursive enum 'IoTFleetWiseClientTypes.StructuredMessage' is not marked 'indirect'
    public enum StructuredMessage: Swift.Equatable {
                ^
           indirect 
/__w/aws-sdk-swift/aws-sdk-swift/Sources/Services/AWSIoTFleetWise/models/Models.swift:10666:14: note: cycle beginning here: IoTFleetWiseClientTypes.StructuredMessageListDefinition -> (memberType: IoTFleetWiseClientTypes.StructuredMessage?) -> (some(_:): IoTFleetWiseClientTypes.StructuredMessage)
        case structuredmessagelistdefinition(IoTFleetWiseClientTypes.StructuredMessageListDefinition)
             ^
/__w/aws-sdk-swift/aws-sdk-swift/Sources/Services/AWSIoTFleetWise/models/Models.swift:10701:19: error: value type 'IoTFleetWiseClientTypes.StructuredMessageFieldNameAndDataTypePair' has infinite size
    public struct StructuredMessageFieldNameAndDataTypePair: Swift.Equatable {
                  ^
/__w/aws-sdk-swift/aws-sdk-swift/Sources/Services/AWSIoTFleetWise/models/Models.swift:10704:20: note: cycle beginning here: IoTFleetWiseClientTypes.StructuredMessage? -> (some(_:): IoTFleetWiseClientTypes.StructuredMessage) -> (structuredmessagelistdefinition(_:): IoTFleetWiseClientTypes.StructuredMessageListDefinition) -> (memberType: IoTFleetWiseClientTypes.StructuredMessage?)
        public var dataType: IoTFleetWiseClientTypes.StructuredMessage?
                   ^
/__w/aws-sdk-swift/aws-sdk-swift/Sources/Services/AWSIoTFleetWise/models/Models.swift:10768:20: error: value type 'IoTFleetWiseClientTypes.StructuredMessageListDefinition' cannot have a stored property that recursively contains it
        public var memberType: IoTFleetWiseClientTypes.StructuredMessage?
                   ^
/__w/aws-sdk-swift/aws-sdk-swift/Sources/Services/AWSIoTFleetWise/models/Models.swift:10768:20: note: cycle beginning here: IoTFleetWiseClientTypes.StructuredMessage? -> (some(_:): IoTFleetWiseClientTypes.StructuredMessage) -> (structuredmessagelistdefinition(_:): IoTFleetWiseClientTypes.StructuredMessageListDefinition)
        public var memberType: IoTFleetWiseClientTypes.StructuredMessage?
                   ^

Smithy permits such a structure. The rules on recursive models are described here: https://smithy.io/2.0/spec/aggregate-types.html#recursive-shape-definitions

The failure is due to the use of recursive enumerations, which are permitted but not yet supported by the Swift SDK.

This is already a known issue, tracked here in the form of a failed / disabled protocol test: https://github.com/awslabs/aws-sdk-swift/issues/1096

Expected Behavior

Recursive enums should compile successfully, and associated protocol tests should pass.

Current Behavior

Compile fails with messages similar to above when recursive enums are modeled.

Reproduction Steps

Pull latest models using the codegen/sdk-codegen/scripts/updatemodels.sh script Code-generate the SDK Attempt to build the AWSIoTFleetwise service

Possible Solution

Add recursion detection to enums, add the indirect keyword when appropriate

Additional Information/Context

No response

AWS SWIFT SDK version used

Latest / main

Compiler and Version used

Latest

Operating System and version

Latest

jbelkins commented 11 months ago

Released in AWS SDK for Swift 0.32.0