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

Fix empty path component in route registration #13

Merged
merged 3 commits into from
Jan 9, 2024

Conversation

marius-se
Copy link
Contributor

Currently all routes registered through this library will have an empty path component:
Example:
"/users" got split into ["", "users"]. With this PR "/users" will now be split into ["users"] only!

@MahdiBM
Copy link
Collaborator

MahdiBM commented Dec 5, 2023

@swift-server-bot test this please

Copy link
Collaborator

@MahdiBM MahdiBM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👌

@MahdiBM
Copy link
Collaborator

MahdiBM commented Dec 5, 2023

@0xTim I probably don't have access to ask the bot to run the tests 🤔

@0xTim
Copy link
Member

0xTim commented Dec 5, 2023

@swift-server-bot test

@0xTim
Copy link
Member

0xTim commented Dec 5, 2023

@swift-server-bot please test

@0xTim
Copy link
Member

0xTim commented Dec 5, 2023

@swift-server-bot test this please

@0xTim
Copy link
Member

0xTim commented Dec 5, 2023

@tomerd how do we trigger CI? 😅

@marius-se
Copy link
Contributor Author

I think @swift-server-bot is oof? 😆

@tomerd
Copy link
Contributor

tomerd commented Dec 5, 2023

@swift-server-bot test this please

@0xTim
Copy link
Member

0xTim commented Dec 5, 2023

@marius-se as the error says - do you want to fix the Equatable conformance in RoutingKit?

@MahdiBM
Copy link
Collaborator

MahdiBM commented Dec 5, 2023

I'm not at my desk, but as I see this, you could either not use the equtable conformance or use #if $Retroactive to use @retroactive where the feature exists, and not use that when it doesn't like in 5.9. Both are fine by me.

@MahdiBM
Copy link
Collaborator

MahdiBM commented Dec 5, 2023

Correction: the spelling is #if $RetroactiveAttribute.

@0xTim
Copy link
Member

0xTim commented Dec 5, 2023

We should fix the underlying issue since this is adding the conformance - we shouldn't be extending types we don't own to protocols we don't own. I didn't realise this was a new error but it's definitely a valid one, and one that Vapor is going to get screwed by 😅

@MahdiBM
Copy link
Collaborator

MahdiBM commented Dec 5, 2023

@0xTim I was also worrying about that when I first reviewed, but @marius-se did it the "fine" way which is to only add it to Tests. That's why I'm fine with it existing. Totally removing it is also fine and might be slightly better as well.

@marius-se
Copy link
Contributor Author

marius-se commented Dec 6, 2023

Sooooo... which option do you want me to proceed with 😆

  1. Fix in Routing Kit
  2. Fix in test (adding retroactively thing)
  3. Remove conformance and manually compare

(I'm happy with all three solutions)

@MahdiBM
Copy link
Collaborator

MahdiBM commented Dec 6, 2023

I think we can proceed with the third option and it should be fine 🙂
maybe something like:

let path = try XCTUnwrap(app.routes.all.first?.path)
XCTAssertTrue(path == ["hello", ":name"], "Unexpected path: \(path)")

But implementing == as a global function, not as a Equatable conformance to the type:

func == (lhs: [PathComponent], rhs: [PathComponent]) -> Bool {
    lhs.count == rhs.count &&
    zip(lhs, rhs).allSatisfy { 
        /// Logic for `$0 == $1`, the same as you wrote for the Equatable conformance
    }
}

<Untested code alert, might not compile as-is>

@MahdiBM
Copy link
Collaborator

MahdiBM commented Dec 6, 2023

Or actually i didn't notice Tim recommending to fix the conformance in RoutingKit

do you want to fix the Equatable conformance in RoutingKit?

That's fine by me too.
Generally all 3 ways are fine. Fixing the conformance in RoutingKit or using the third way are probably better though.

@0xTim
Copy link
Member

0xTim commented Dec 6, 2023

You can hack it in for the tests, but I see no issue with adding it directly to RoutingKit as well

@MahdiBM
Copy link
Collaborator

MahdiBM commented Jan 6, 2024

@marius-se I think this should not be much of a problem now that the RoutingKit PR is merged.

@MahdiBM
Copy link
Collaborator

MahdiBM commented Jan 8, 2024

@swift-server-bot test this please

@MahdiBM
Copy link
Collaborator

MahdiBM commented Jan 8, 2024

@0xTim 🫣

@0xTim
Copy link
Member

0xTim commented Jan 9, 2024

@swift-server-bot test this please

@0xTim
Copy link
Member

0xTim commented Jan 9, 2024

@swift-server-bot please test

@0xTim
Copy link
Member

0xTim commented Jan 9, 2024

@MahdiBM feel free to merge and release once CI is green

@MahdiBM MahdiBM merged commit f89da92 into swift-server:main Jan 9, 2024
2 checks passed
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.

None yet

4 participants