fastapi
fastapi copied to clipboard
Raw docstring #10998
Raw docstring (leading r) defeats form feed \f truncation
@ShreySinha02 @KaniKim @Kludex , I'm afraid it's not clear to me which use case #10998 is meant to address, because changing the behavior of how a raw string is parsed would mean it's no longer being treated as a raw string.
Besides, as @dolfinus pointed out in that issue, which I encourage you to link to this PR btw, both the proposed fix and this one will act out if you mention C:\files\data
in the description of the endpoint.
Either way, here's some data to help make you guys' explanations more clear.
Minimal Reproducible Example
- Make sure you have Python 3, PIP 3 and virtualenv installed on your system:
python3 -V &&
pip3 -V &&
pip3 show virtualenv
- Create a Python virtual environment and activate it:
python3 -m venv .venv &&
source .venv/bin/activate
- Set up the demo:
pip install fastapi
- Add the demo entrypoint and run it:
cat > main.py <<EOF && python main.py
from fastapi import FastAPI
from json import dump
app = FastAPI()
@app.post("/foo")
def foo(arg: int = 5) -> int:
r"""
Some function.
\f
Args:
arg: Some argument
Returns:
Some integer.
"""
return arg
@app.post("/bar")
def foo(arg: int = 5) -> int:
r"""
Some function. C:\files\data C:/files/data
\f
Args:
arg: Some argument
Returns:
Some integer.
"""
return arg
openapi_schema = app.openapi()
with open("openapi.json", "w") as file:
dump(openapi_schema, file, indent=2)
EOF
Outputs
Git Diff
# git diff v0.110.1.json pr-11149.json
diff --git a/v0.110.1.json b/pr-11149.json
index f8d2a52..249b92b 100644
--- a/v0.110.1.json
+++ b/pr-11149.json
@@ -8,7 +8,7 @@
"/foo": {
"post": {
"summary": "Foo",
- "description": "Some function.\n\n\\f\n\nArgs:\n arg: Some argument\n\nReturns:\n Some integer.",
+ "description": "Some function.",
"operationId": "foo_foo_post",
"parameters": [
{
@@ -50,7 +50,7 @@
"/bar": {
"post": {
"summary": "Foo",
- "description": "Some function. C:\\files\\data C:/files/data\n\n\\f\n\nArgs:\n arg: Some argument\n\nReturns:\n Some integer.",
+ "description": "Some function. C:",
"operationId": "foo_bar_post",
"parameters": [
{