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

Parsing a Path parameter with a trailing extension #381

Closed
sunli829 opened this issue Sep 2, 2022 Discussed in #380 · 3 comments
Closed

Parsing a Path parameter with a trailing extension #381

sunli829 opened this issue Sep 2, 2022 Discussed in #380 · 3 comments

Comments

@sunli829
Copy link
Collaborator

sunli829 commented Sep 2, 2022

Discussed in #380

Originally posted by phaer September 2, 2022
Hello,

I am trying to use a Route like "/notebooks/:id.pdf but, it seems that poetry interprets this as a parameter called "id.pdf" instead of an parameter "id", followed by the string ".pdf". Using a regex like /notebooks/:id<[^\\.]>.pdf does not work as expected either.

Swagger UI confirms that the parameters aren't interpreted as expected:
image

Is this something supported by poem? Am I missing something?

@sunli829
Copy link
Collaborator Author

sunli829 commented Sep 2, 2022

I reviewed the code, this is not a bug, the current matching algorithm cannot support extensions.

I need to think about how to do it. 😀

@sunli829
Copy link
Collaborator Author

sunli829 commented Sep 2, 2022

I thought about it and suggested the following solution:

#[oai(path = "/notebooks/:id")]
async fn handler(id: Path<String>) -> Result<()> {
    if id.ends_with(".svg") {
        // do something
    } else {
        Err(Error::from_status(StatusCode::NotFound))
    }
}

@sunli829 sunli829 closed this as completed Sep 2, 2022
@phaer
Copy link

phaer commented Sep 2, 2022

Thanks for the quick response! But its more a work-around than a solution in my opinion as, ideally, I'd like to have three different handlers: "/notebooks/:id", "/notebooks/:id.pdf" and "/notebooks/:id.png". With this work-around one has to cram all 3 of them into a single handler and do the rest of the matching myself.

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

No branches or pull requests

2 participants