-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
Make WebSocketUpgraded public #415
Comments
because here: pub async fn web_socket(&self, ws: WebSocket) -> impl IntoResponse { ... }
^^^^^
pub async fn web_socket(self, ws: WebSocket) -> impl IntoResponse { ... } |
I get same error: |
I can't reproduce it, can you give me a repo? |
Simple code to reproduce: main.rs: use poem::{
listener::TcpListener,
web::websocket::WebSocket,
IntoEndpoint, IntoResponse, Route, Server,
};
use poem_openapi::{OpenApi, OpenApiService};
pub struct ApiV1;
#[OpenApi(prefix_path = "/example")]
impl ApiV1 {
#[oai(path = "/ws", method = "post")]
pub async fn web_socket(&self, ws: WebSocket) -> impl IntoResponse {
todo!();
}
}
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let api_service = OpenApiService::new(ApiV1, env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
.description(env!("CARGO_PKG_DESCRIPTION"))
.server("http://localhost:9000/api/v1");
let swagger = api_service.swagger_ui();
let json = api_service.spec_endpoint();
let yaml = api_service.spec_endpoint_yaml();
let app = Route::new()
.nest("/api/v1", api_service.into_endpoint())
.nest("/docs/swagger", swagger)
.nest("/docs/openapi.json", json)
.nest("/docs/openapi.yml", yaml);
Server::new(TcpListener::bind("localhost:9000"))
.run(app)
.await
} Cargo.toml [package]
name = "ws_example"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
poem = { version = "1.3", features = ["websocket"] }
poem-openapi = { version = "2.0", features = ["swagger-ui"] }
tokio = { version = "1.0", features = ["full"] } |
I'm stupid, the error is obvious. I am working on it. 😂 |
Don't worry) Thank you so mach! |
Implement `ApiResponse` for `WebSocketUpgraded<T>` #415
Fixed in #[OpenApi(prefix_path = "/example")]
impl ApiV1 {
#[oai(path = "/ws", method = "post")]
pub async fn web_socket(&self, ws: WebSocket) -> BoxWebSocketUpgraded {
ws.on_upgrade(|stream| async move {
// ....
}).boxed()
}
} poem = { git="...", features = ["websocket"] }
poem-openapi = { git="...", features = [
"swagger-ui",
"websocket", # don't forget add this feature
] } |
@sunli829 thank you so mach! |
Hello! I try do something like this:
But I get error:
impl Trait only allowed in function and inherent method return types, not in path
. Can you makestruct WebSocketUpgraded
public?The text was updated successfully, but these errors were encountered: