docstrings #3101
-
|
What is the proper way to write docstrings for the swagger UI to render them properly? And more broadly, what's the appropriate way to create and publish documentation about the APIs in FastAPI? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
|
You can use Markdown (MD). """
# A Header
**bold**
*italic*
## Smaller Header
`` `
a multiline code block
`` `
`a inline codeblock` Lorem Ipsum
"""
# You have to remove the space from "`` `" |
Beta Was this translation helpful? Give feedback.
-
|
That would be ok for swagger, but if you are using a specific docstring style for external docs such as sphinx, I don´t think this approach will work. Is there a way to instruct swagger to ignore python docstrings? |
Beta Was this translation helpful? Give feedback.
-
|
Just a quick note about triple backticked-sections. If you use @router.get(
"/{data_source}/inst_vals",
summary="Instanteousd (raw) observations",
description=dedent(f"""\
## Instanteous time series observations
This returns a *paginated* response of time series data series directly from the data warehouse
(i.e., raw & unrounded/unaggregated timesteps).
The default page size is 500,000 rows. Page sizes of up to 1,000,000
can work.
The response of a call includes a "next_params" item.
When there is more data to be retrieved, that item contains the
dictionary you need to pass `requests.get` to recieve the page.
When there are no more pages of data to recieve, "next_params" will be `None`
{data_source_note}
### Python example
```python
import requests
import pandas
baseurl = "{_docstring_baseurl}"
route = "",
query_params = {{
"file_stem": "KATL",
"parameter": None,
"start_date": "2010-10-01",
"end_date": "2022-09-30",
"timezone": "US/Pacific",
"limit": 500_000, # page size
}}
rows = []
while query_params is not None:
response = requests.get(f"{{baseurl}}/ts/wx/inst_vals", params=query_params)
assert response.ok
data = response.json()
rows.append(data["results"])
# now replace the old query params with the response's "next_params"
# eventually this will be set to None and you'll kick out of the loop
query_params = data["next_params"]
df = pandas.DataFrame(rows)
```
### R Example
```R
# TDB
```
""")
)
def get_inst_vals():
passAnd I get |
Beta Was this translation helpful? Give feedback.




You can use Markdown (MD).
A Doc-String like this
looks like this: