Skip to content
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

Prefix all Service Libraries with AWS #218

Closed
fabianfett opened this issue Jan 16, 2020 · 3 comments
Closed

Prefix all Service Libraries with AWS #218

fabianfett opened this issue Jan 16, 2020 · 3 comments
Milestone

Comments

@fabianfett
Copy link
Contributor

fabianfett commented Jan 16, 2020

Original title:
Namespaces don't work if Facade struct has same name as Library

Origin of the issue:
fabianfett/swift-lambda-runtime#25

The code that breaks

import NIO
import DynamoDB
import AWSSDKSwiftCore
import LambdaRuntime

func configureDynamoDB(group: EventLoopGroup, environment: Environment) -> DynamoDB {
    return DynamoDB(
         accessKeyId: environment.accessKeyId,
         secretAccessKey: environment.secretAccessKey,
         sessionToken: environment.sessionToken,
         region: Region(rawValue: environment.region),
         eventLoopGroupProvider: .shared(group)
    )
}

LambdaRuntime must be imported because of the Environment type. Since LambdaRuntime also holds a DynamoDB type, the compiler emits an error:

'DynamoDB' is ambiguous for type lookup in this context

There are two issues here:

LambdaRuntime Issue

Since the package LambdaRuntime has the same name as the class LambdaRuntime.DynamoDB the compiler can not differentiate between the namespace and the class. Trying to access: LambdaRuntime.DynamoDB leads to the following error:

'DynamoDB' is not a member type of 'LambdaRuntime'

For that reason, I will rename LambdaRuntime the class to Runtime. With this LambdaRuntime always refers to the package/namespace and not a struct. This is already in progress with:

fabianfett/swift-lambda-runtime#26

With this fix done, we can now access LambdaRuntime.DynamoDB without problems.

AWSSDKSwift Issue

Even though we can specify LambdaRuntime.DynamoDB we still can not specify DynamoDB.DynamoDB since we still can't access the namespace. The whole Swift namespace is broken as long as a type has the same name as the library. IMHO we should start a rename here to prevent those naming collisions where one can not fallback on the namespaces. I know this is breaking. But it's also a great feature to not fall apart in the moment of naming collisions.

import NIO
import DynamoDB
import AWSSDKSwiftCore
import LambdaRuntime

func configureDynamoDB(group: EventLoopGroup, environment: Environment) -> DynamoDB {
    return DynamoDB(
         accessKeyId: environment.accessKeyId,
         secretAccessKey: environment.secretAccessKey,
         sessionToken: environment.sessionToken,
         region: Region(rawValue: environment.region),
         eventLoopGroupProvider: .shared(group)
    )
}

For easy reproduction this is the Package.swift I used.

// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "LambdaEventsTest",
    products: [
      .executable(name: "LambdaEventsTest", targets: ["LambdaEventsTest"])
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.9.0")),
        .package(url: "https://github.com/swift-aws/aws-sdk-swift.git", .upToNextMajor(from: "4.0.0")),
        .package(url: "https://github.com/fabianfett/swift-lambda-runtime", .upToNextMajor(from: "0.4.0")),
    ],
    targets: [
        .target(
            name: "LambdaEventsTest",
            dependencies: ["DynamoDB", "NIO", "LambdaRuntime"]),
        .testTarget(
            name: "LambdaEventsTestTests",
            dependencies: ["LambdaEventsTest"]),
    ]
)

This issue went undiscovered since I haven't used both frameworks in a single file yet.

@fabianfett
Copy link
Contributor Author

Verified the issue with @weissi on vapor discord chat:

Yes
That’s why in the sswg we try to make sure that module and type names never clash
It’s unfortunate though 😭
Maybe you want to file a Swift bug, there might already be one but I don’t think so

@fabianfett fabianfett changed the title Namespaces don't work if Facade struct has same name as Library Prefix all Service Libraries with AWS Jan 16, 2020
@fabianfett
Copy link
Contributor Author

Also this resolves name clashes with: https://github.com/LiveUI/S3

@adam-fowler
Copy link
Member

fixed in #225

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

No branches or pull requests

2 participants