-
-
Notifications
You must be signed in to change notification settings - Fork 331
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Expected Behavior
use poem::{
listener::TcpListener,
web::{Path},
Route, Server,
handler
};
use poem_openapi::{
payload::PlainText,
param::Path as ApiPath,
OpenApi, OpenApiService,
};
#[handler]
async fn get_user(
Path(username): Path<String>,
) -> PlainText<String> {
PlainText("This works and can get the input".to_string())
}
struct Api {}
#[OpenApi]
impl Api {
#[oai(method = "get", path = "/:username")]
async fn fetch_user(
&self,
ApiPath(username): ApiPath<String>,
) -> PlainText<String> {
// This gives: failed to parse path `username`: Type "string" expects an input value.
PlainText("This doesnt work and cant extract the input".to_string())
}
#[oai(path = "/", method = "get")]
async fn index(&self) -> PlainText<&'static str> {
PlainText("Hello World")
}
}
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let api_service = OpenApiService::new(
Api {},
"My API",
env!("CARGO_PKG_VERSION"),
)
.server(format!("http://localhost:1234/api"))
.description("A simple API")
.summary("Information API");
let openapi_ui = api_service.swagger_ui();
let app = Route::new()
.at("/:username", get_user)
.nest("/api", api_service)
.nest("/openapi", openapi_ui);
println!("Starting server on port 1234...");
Server::new(TcpListener::bind(format!("0.0.0.0:1234")))
.run(app)
.await?;
Ok(())
}
Actual Behavior
GET http://localhost:1234/api/izelnakri:
failed to parse path username
: Type "string" expects an input value.
GET http://localhost:1234/izelnakri:
This one works
Steps to Reproduce the Problem
- Run the code yourself
Specifications
- Version: LATEST = poem v3.1.10, poem-openapi v5.1.14
- Platform: Linux omnibook 6.14.5 add README #1-NixOS SMP PREEMPT_DYNAMIC Fri May 2 06:02:16 UTC 2025 x86_64 GNU/Linux
We need better tests for all the types in open
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working