[QUESTION] How to get rid of question marks in openapi.json paths when using `/?` to fix the trailing slash issue?
See original GitHub issueFirst check
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
Description
How can I get rid of question marks in openapi.json paths when using /?
to fix the trailing slash issue?
We’re seeing this exact thing, that is the question marks that we’ve added to “fix” the trailing slash issue appears in the generated openapi.json paths.
Additional context
Image from the other issue:
This happens when you have endpoints like these:
@router.get("/budgets/?")
@router.post("/budgets/?")
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
OpenApi Annotations causing double slash - Stack Overflow
After compiling the documentation json file, I open it and this action is listed as follows:
Read more >Trailing slash in RESTful API
It is accessing the dog resource, the trailing slash should be ignored which means it should get a forbidden response for trying to...
Read more >Trailing slashes on URLs: Contentious or settled?
My implementation was, when given a trailing slash, check if the recource is a directory (as this is what the trailing slash signifies)...
Read more >OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
The field name MUST begin with a forward slash ( / ). The path is appended (no relative URL resolution) to the expanded...
Read more >Nginx Remove Trailing Question Mark From URL - Server Fault
I've done that for trailing slashes like this: #redirect all trailing slash URL's to the respective non trailing slash rewrite ^/(.*)/$ /$1 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can extend the api and overwrite each endpoint as part of that operation. I would be concerned that this is a band-aid over a known issue but will get you what you want
https://fastapi.tiangolo.com/advanced/extending-openapi/
You should be able to iterate thru what get’s initially generated and alter the lines you want removing the ?
Thanks for the help here everyone! 👏 🙇
Thanks for reporting back and closing the issue 👍
Just for completeness, you should be able to declare your path operations with just
/something/
and have the version not ending in/
redirected automatically, that would probably be the default for most cases.