question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] How to get rid of question marks in openapi.json paths when using `/?` to fix the trailing slash issue?

See original GitHub issue

First 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:

docs with question mark

This happens when you have endpoints like these:

@router.get("/budgets/?")
@router.post("/budgets/?")

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chris-allnuttcommented, Apr 25, 2020

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 ?

0reactions
tiangolocommented, May 23, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found