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

Name clashes with NIOHTTP1 #118

Open
adam-fowler opened this issue Jun 8, 2020 · 17 comments
Open

Name clashes with NIOHTTP1 #118

adam-fowler opened this issue Jun 8, 2020 · 17 comments
Assignees
Labels
enhancement New feature or request ⚠️ needs-major-version-bump For PRs that when merged cause a bump of the major version, ie. x.0.0 -> (x+1).0.0
Milestone

Comments

@adam-fowler
Copy link
Member

Currently AWSLambdaEvents defines public symbols HTTPHeaders, HTTPMethod and HTTPResponseStatus. These clash with the symbols of the same name in NIOHTTP1. While you can differentiate between the two sets by prepending NIOHTTP1., I'm not sure modules should be defining symbols with the same name as NIO equivalents.

@adam-fowler
Copy link
Member Author

What's wrong with using the NIOPHTTP1 versions of these objects, they are already imported by AWSLambdaRuntimeCore?

@tomerd tomerd added the discussion for things that need discussion label Jun 12, 2020
@tomerd
Copy link
Contributor

tomerd commented Jun 12, 2020

nio's versions are a bit different from the ones in AWSLambdaEvents, the latter are designed for JSON payload decoding/encoding

we could consider adding a prefix to more easily disambiguate.

@tomerd tomerd changed the title Symbol clashes with NIOHTTP1 Name clashes with NIOHTTP1 Jun 12, 2020
@weissi
Copy link
Contributor

weissi commented Jun 15, 2020

I'd add prefixes too.

@fabianfett
Copy link
Member

@weissi Do you have any recommendations in mind?

@weissi
Copy link
Contributor

weissi commented Jun 16, 2020

ALR* [A]WS [L]amba [R]untime? Maybe you already have some sort of common prefix? In SwiftNIO of course we use NIO for that purpose.

@weissi
Copy link
Contributor

weissi commented Jun 16, 2020

Of course that makes the type names a bit ugly. How are the users most commonly interfacing with those types?

@fabianfett
Copy link
Member

normally we namespace under the Lambda

@weissi
Copy link
Contributor

weissi commented Jun 16, 2020

sounds good Lambda*?

@fabianfett
Copy link
Member

fabianfett commented Jun 16, 2020

well i'd put them in Lambda.* then

but that's not really the point since they are not connected to the lambda runtime but to the aws event. Maybe we should namespace them in AWSHTTPTypes. But this could also create a naming conflict with the AWS SDK.

@adam-fowler
Copy link
Member Author

@fabianfett There isnt any AWSHTTPTypes and I'm not intending to add any. Even if I did, we'll be able to discriminate between them using the framework name. I'm trying to use the NIO types as much as possible

@helje5
Copy link

helje5 commented Jul 30, 2020

the latter are designed for JSON payload decoding/encoding

what? :-)

Apart from all the duping, wouldn’t you want to use the NIO types in the public API?
(not that this is necessary, but if you want, you could still use those types internally)

This is not about things like a V2.Request but about the basic http types.

Note that this even has functional implications (and duping), e.g. header lookup is not CI?

@tomerd
Copy link
Contributor

tomerd commented Jul 30, 2020

@helje5 IIRC the main issues was that we would need to be extending these types to add functionality to them (Codable conformance mainly IIRC). rule of thumb we have been following in library development is to avoid extending public types from other libraries (SwiftNIO in this case) as it may lead to conflicts with other libraries that may do the same.

cc @weissi @fabianfett

@helje5
Copy link

helje5 commented Jul 30, 2020

You don't need to extend the types to decode them (yes, Codable can only be added to the original type itself, but that is not required here). You can decode the necessary data in init(decoder:) and then construct the actual model. Kinda similar to this:

https://github.com/SwiftBlocksUI/SwiftBlocksUI/blob/develop/Sources/SlackBlocksModel/InteractiveRequest/BlockActions.swift#L92

As mentioned in the Slack, a reasonable argument for the duping is that NIO isn't actually necessary for Lambdas. Don't know.

@tomerd
Copy link
Contributor

tomerd commented Jul 30, 2020

You don't need to extend the types to decode them (yes, Codable can only be added to the original type itself, but that is not required here). You can decode the necessary data in init(decoder:) and then construct the actual model. Kinda similar to this:

I guess if we decide to adopt the NIO types after all we could also use property wrappers

As mentioned in the Slack, a reasonable argument for the duping is that NIO isn't actually necessary for Lambdas. Don't know.

that too. personally, I don't love leaking types where not necessary. there is the argument of copying so we need to trade that off

in the case of HTTPHeaders, there is also a set of mutability functionality that comes with that type that may not makes sense to expose in the Lambda request use case which is more immutable in nature

@helje5
Copy link

helje5 commented Jul 30, 2020

there is the argument of copying so we need to trade that off
They are not even plain copies, e.g. the AWS method is a struct (which is actually the better choice), while the NIO one is an enum w/ an associated type. It's crap and weird if you need to convert them back.

Wrt HTTPHeaders, the NIO ones are actually better than the plain Dict you have in AWS because the latter doesn't account for the header case insensitivity.
Yes, AWS breaks out headers in weird ways (single/multi value), but there is no real reason to not combine them back into NIO headers after decoding.

I don't get the mutability thing. NIOHeaders are a regular CoW struct just like Dictionary, right?

In the end it really depends on whether you consider NIO a must have dependency or not. If it is, it's weird not to use its HTTP header types. If not (and they are good arguments for dropping it IMO for this specific thing), I think it's OK to keep it the way it is.

@fabianfett fabianfett added the ⚠️ needs-major-version-bump For PRs that when merged cause a bump of the major version, ie. x.0.0 -> (x+1).0.0 label Aug 3, 2020
@tomerd tomerd added enhancement New feature or request and removed discussion for things that need discussion labels Aug 6, 2020
@tomerd tomerd added this to the 1.0.0 milestone Aug 6, 2020
@sebsto
Copy link
Contributor

sebsto commented May 29, 2024

@adam-fowler now that we adopted Swift HTTP Types in Lambda Events, is this still an issue ?

@adam-fowler
Copy link
Member Author

HTTPHeaders is still there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ⚠️ needs-major-version-bump For PRs that when merged cause a bump of the major version, ie. x.0.0 -> (x+1).0.0
Projects
None yet
Development

No branches or pull requests

6 participants