Browse Source

fix/fix typos in docs and source code, fix status_code priority in _build_response_args

pull/15699/head
sadreammm 1 month ago
parent
commit
e94779490d
  1. 2
      docs/en/docs/deployment/https.md
  2. 2
      docs/en/docs/environment-variables.md
  3. 2
      docs/en/docs/project-generation.md
  4. 2
      docs/en/docs/tutorial/body.md
  5. 2
      fastapi/datastructures.py
  6. 2
      fastapi/openapi/docs.py
  7. 4
      fastapi/param_functions.py
  8. 9
      fastapi/routing.py
  9. 4
      fastapi/security/oauth2.py
  10. 1
      tests/test_custom_swagger_ui_redirect.py
  11. 1
      tests/test_no_swagger_ui_redirect.py

2
docs/en/docs/deployment/https.md

@ -192,7 +192,7 @@ All this renewal process, while still serving the app, is one of the main reason
## Proxy Forwarded Headers { #proxy-forwarded-headers } ## Proxy Forwarded Headers { #proxy-forwarded-headers }
When using a proxy to handle HTTPS, your **application server** (for example Uvicorn via FastAPI CLI) doesn't known anything about the HTTPS process, it communicates with plain HTTP with the **TLS Termination Proxy**. When using a proxy to handle HTTPS, your **application server** (for example Uvicorn via FastAPI CLI) doesn't know anything about the HTTPS process, it communicates with plain HTTP with the **TLS Termination Proxy**.
This **proxy** would normally set some HTTP headers on the fly before transmitting the request to the **application server**, to let the application server know that the request is being **forwarded** by the proxy. This **proxy** would normally set some HTTP headers on the fly before transmitting the request to the **application server**, to let the application server know that the request is being **forwarded** by the proxy.

2
docs/en/docs/environment-variables.md

@ -291,7 +291,7 @@ This information will be useful when learning about [Virtual Environments](virtu
With this you should have a basic understanding of what **environment variables** are and how to use them in Python. With this you should have a basic understanding of what **environment variables** are and how to use them in Python.
You can also read more about them in the [Wikipedia for Environment Variable](https://en.wikipedia.org/wiki/Environment_variable). You can also read more about them in the [Wikipedia for Environment Variables](https://en.wikipedia.org/wiki/Environment_variable).
In many cases it's not very obvious how environment variables would be useful and applicable right away. But they keep showing up in many different scenarios when you are developing, so it's good to know about them. In many cases it's not very obvious how environment variables would be useful and applicable right away. But they keep showing up in many different scenarios when you are developing, so it's good to know about them.

2
docs/en/docs/project-generation.md

@ -1,6 +1,6 @@
# Full Stack FastAPI Template { #full-stack-fastapi-template } # Full Stack FastAPI Template { #full-stack-fastapi-template }
Templates, while typically come with a specific setup, are designed to be flexible and customizable. This allows you to modify and adapt them to your project's requirements, making them an excellent starting point. 🏁 Templates, while they typically come with a specific setup, are designed to be flexible and customizable. This allows you to modify and adapt them to your project's requirements, making them an excellent starting point. 🏁
You can use this template to get started, as it includes a lot of the initial set up, security, database and some API endpoints already done for you. You can use this template to get started, as it includes a lot of the initial set up, security, database and some API endpoints already done for you.

2
docs/en/docs/tutorial/body.md

@ -12,7 +12,7 @@ To declare a **request** body, you use [Pydantic](https://docs.pydantic.dev/) mo
To send data, you should use one of: `POST` (the more common), `PUT`, `DELETE` or `PATCH`. To send data, you should use one of: `POST` (the more common), `PUT`, `DELETE` or `PATCH`.
Sending a body with a `GET` request has an undefined behavior in the specifications, nevertheless, it is supported by FastAPI, only for very complex/extreme use cases. Sending a body with a `GET` request has undefined behavior in the specifications, nevertheless, it is supported by FastAPI, only for very complex/extreme use cases.
As it is discouraged, the interactive docs with Swagger UI won't show the documentation for the body when using `GET`, and proxies in the middle might not support it. As it is discouraged, the interactive docs with Swagger UI won't show the documentation for the body when using `GET`, and proxies in the middle might not support it.

2
fastapi/datastructures.py

@ -182,5 +182,5 @@ def Default(value: DefaultType) -> DefaultType:
# Sentinel for "parameter not provided" in Param/FieldInfo. # Sentinel for "parameter not provided" in Param/FieldInfo.
# Typed as None to satisfy ty # Typed as None to satisfy type checkers
_Unset = Default(None) _Unset = Default(None)

2
fastapi/openapi/docs.py

@ -135,7 +135,7 @@ def get_swagger_ui_html(
] = None, ] = None,
) -> HTMLResponse: ) -> HTMLResponse:
""" """
Generate and return the HTML that loads Swagger UI for the interactive Generate and return the HTML that loads Swagger UI for the interactive
API docs (normally served at `/docs`). API docs (normally served at `/docs`).
You would only call this function yourself if you needed to override some parts, You would only call this function yourself if you needed to override some parts,

4
fastapi/param_functions.py

@ -518,7 +518,7 @@ def Query( # noqa: N802
RegEx pattern for strings. RegEx pattern for strings.
Read more about it in the Read more about it in the
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#add-regular-expressions [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#add-regular-expressions)
""" """
), ),
] = None, ] = None,
@ -639,7 +639,7 @@ def Query( # noqa: N802
This affects the generated OpenAPI (e.g. visible at `/docs`). This affects the generated OpenAPI (e.g. visible at `/docs`).
Read more about it in the Read more about it in the
[FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#exclude-parameters-from-openapi [FastAPI docs about Query parameters](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#exclude-parameters-from-openapi)
""" """
), ),
] = True, ] = True,

9
fastapi/routing.py

@ -338,12 +338,9 @@ def _build_response_args(
} }
# If status_code was set, use it, otherwise use the default from the # If status_code was set, use it, otherwise use the default from the
# response class, in the case of redirect it's 307 # response class, in the case of redirect it's 307
current_status_code = ( if status_code is not None:
status_code if status_code else solved_result.response.status_code response_args["status_code"] = status_code
) elif solved_result.response.status_code:
if current_status_code is not None:
response_args["status_code"] = current_status_code
if solved_result.response.status_code:
response_args["status_code"] = solved_result.response.status_code response_args["status_code"] = solved_result.response.status_code
return response_args return response_args

4
fastapi/security/oauth2.py

@ -112,7 +112,7 @@ class OAuth2PasswordRequestForm:
```python ```python
"items:read items:write users:read profile openid" "items:read items:write users:read profile openid"
```` ```
would represent the scopes: would represent the scopes:
@ -278,7 +278,7 @@ class OAuth2PasswordRequestFormStrict(OAuth2PasswordRequestForm):
```python ```python
"items:read items:write users:read profile openid" "items:read items:write users:read profile openid"
```` ```
would represent the scopes: would represent the scopes:

1
tests/test_custom_swagger_ui_redirect.py

@ -19,7 +19,6 @@ def test_swagger_ui():
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.headers["content-type"] == "text/html; charset=utf-8" assert response.headers["content-type"] == "text/html; charset=utf-8"
assert "swagger-ui-dist" in response.text assert "swagger-ui-dist" in response.text
print(client.base_url)
assert ( assert (
f"oauth2RedirectUrl: window.location.origin + '{swagger_ui_oauth2_redirect_url}'" f"oauth2RedirectUrl: window.location.origin + '{swagger_ui_oauth2_redirect_url}'"
in response.text in response.text

1
tests/test_no_swagger_ui_redirect.py

@ -17,7 +17,6 @@ def test_swagger_ui():
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
assert response.headers["content-type"] == "text/html; charset=utf-8" assert response.headers["content-type"] == "text/html; charset=utf-8"
assert "swagger-ui-dist" in response.text assert "swagger-ui-dist" in response.text
print(client.base_url)
assert "oauth2RedirectUrl" not in response.text assert "oauth2RedirectUrl" not in response.text

Loading…
Cancel
Save