-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/eng 378 axum wasm multiple handlers per endpoint (#588)
* refactor: clean up if let * feat: move method validation, add test for it * test: add test for chained endpoint handlers * feat: chain endpoints with the same address * feat: duplicate method error, handler chain bug fix chaining handlers with a full type path caused a bug where a `,` was inserted, I think the reason is that `path` types can't be followed by `.`. Importing all the routing methods in `app` works, but it is not ideal * refactor: remove some clones * refactor: remove unwrap Co-authored-by: Pieter <[email protected]> * feat: use BTreeMap for building endpoint chains * fix: only add namespace to first handler in chain * fix: skip rustfmt for quote in app_to_token test rustfmt will add a comma to the expected output, which will also be done in the expanded macro output, but not in the stringified output * refactor: revert btreemap change * docs: document why we sort the endpoint chains --------- Co-authored-by: Pieter <[email protected]>
- Loading branch information
Showing
5 changed files
with
237 additions
and
48 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,16 @@ | ||
shuttle_codegen::app! { | ||
#[shuttle_codegen::endpoint(method = get, route = "/hello")] | ||
async fn hello() -> &'static str { | ||
"Hello, World!" | ||
} | ||
|
||
#[shuttle_codegen::endpoint(method = post, route = "/hello")] | ||
async fn goodbye() -> &'static str { | ||
"Goodbye, World!" | ||
} | ||
|
||
#[shuttle_codegen::endpoint(method = post, route = "/hello")] | ||
async fn goodbye() -> &'static str { | ||
"Goodbye, World!" | ||
} | ||
} |
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,14 @@ | ||
error: only one method of each type is allowed per route | ||
|
||
= help: Remove one of the post methods on the "/hello" route. | ||
|
||
--> tests/ui/next/duplicate-methods.rs:12:42 | ||
| | ||
12 | #[shuttle_codegen::endpoint(method = post, route = "/hello")] | ||
| ^^^^ | ||
|
||
error[E0601]: `main` function not found in crate `$CRATE` | ||
--> tests/ui/next/duplicate-methods.rs:16:2 | ||
| | ||
16 | } | ||
| ^ consider adding a `main` function to `$DIR/tests/ui/next/duplicate-methods.rs` |
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,11 @@ | ||
shuttle_codegen::app! { | ||
#[shuttle_codegen::endpoint(method = pet, route = "/hello")] | ||
async fn hello() -> &'static str { | ||
"Hello, World!" | ||
} | ||
|
||
#[shuttle_codegen::endpoint(method =, route = "/hello")] | ||
async fn hello() -> &'static str { | ||
"Hello, World!" | ||
} | ||
} |
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,29 @@ | ||
error: method is not supported | ||
|
||
= help: Try one of the following: `get`, `post`, `delete`, `put`, `options`, `head`, `trace` or `patch` | ||
|
||
--> tests/ui/next/invalid-method.rs:2:42 | ||
| | ||
2 | #[shuttle_codegen::endpoint(method = pet, route = "/hello")] | ||
| ^^^ | ||
|
||
error: no method provided | ||
|
||
= help: Add a method to your endpoint: `method = get` | ||
|
||
--> tests/ui/next/invalid-method.rs:2:32 | ||
| | ||
2 | #[shuttle_codegen::endpoint(method = pet, route = "/hello")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: expected expression | ||
--> tests/ui/next/invalid-method.rs:7:41 | ||
| | ||
7 | #[shuttle_codegen::endpoint(method =, route = "/hello")] | ||
| ^ | ||
|
||
error[E0601]: `main` function not found in crate `$CRATE` | ||
--> tests/ui/next/invalid-method.rs:11:2 | ||
| | ||
11 | } | ||
| ^ consider adding a `main` function to `$DIR/tests/ui/next/invalid-method.rs` |