-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sdk): api path- collision with
/{proxy+}
(#6543)
fixed: #5943 #5210 tf-aws <img width="311" alt="image" src="https://github.com/winglang/wing/assets/39455181/78bb858e-888a-4e4e-a18a-f060f9166eb6"> aws-cdk <img width="242" alt="image" src="https://github.com/winglang/wing/assets/39455181/17a4b68d-b92c-4246-b456-a8bd01676434"> (the delete test passed in the next run- it was only failing because something in the env couldn't be destroyed) <img width="351" alt="image" src="https://github.com/winglang/wing/assets/39455181/f2aa4217-162a-4ec7-9d19-ea27abba882d"> and the cycle one doesn't work on main as well :) ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] Description explains motivation and solution - [ ] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
- Loading branch information
Showing
14 changed files
with
803 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
bring cloud; | ||
bring http; | ||
bring expect; | ||
|
||
let api = new cloud.Api(); | ||
|
||
let handler = inflight (req: cloud.ApiRequest): cloud.ApiResponse => { | ||
return { | ||
body: "id is {req.vars.tryGet("id") ?? "unknown"}", | ||
}; | ||
}; | ||
|
||
api.get("/:id", handler); | ||
api.get("/:id/comments", handler); | ||
|
||
|
||
try { | ||
// sibling path same method | ||
api.get("/:username/something", handler); | ||
expect.equal(false); | ||
} catch e { | ||
expect.equal(e, "Endpoint for path '/:username/something' and method 'GET' conflicts with existing sibling endpoint for path '/:id'- try to match the parameter names to avoid this error."); | ||
} | ||
|
||
try { | ||
// sibling path different method | ||
api.post("/:username", handler); | ||
expect.equal(false); | ||
} catch e { | ||
expect.equal(e, "Endpoint for path '/:username' and method 'POST' conflicts with existing sibling endpoint for path '/:id'- try to match the parameter names to avoid this error."); | ||
} | ||
|
||
|
||
|
||
test "path vars at endpoint root are working as expected" { | ||
let resWithId = http.get("{api.url}/123"); | ||
expect.ok(resWithId.ok); | ||
expect.equal(resWithId.body, "id is 123"); | ||
|
||
let resWithComments = http.get("{api.url}/123/comments"); | ||
expect.ok(resWithComments.ok); | ||
expect.equal(resWithComments.body, "id is 123"); | ||
|
||
let unknownRes = http.get("{api.url}/123/comments/unknown-path"); | ||
expect.equal(unknownRes.status, 404); | ||
expect.match(unknownRes.body, "Error"); | ||
|
||
let unknownRes2 = http.get("{api.url}/123/unknown-path"); | ||
expect.equal(unknownRes2.status, 404); | ||
expect.match(unknownRes2.body, "Error"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.