-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
✨ Extract descriptions of parameters and responses from docstring #13767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
📝 Docs preview for commit 0e5dca3 at: https://6c93d271.fastapitiangolo.pages.dev |
|
📝 Docs preview for commit 64f8856 at: https://3cd9cf8d.fastapitiangolo.pages.dev |
|
📝 Docs preview for commit 8683d33 at: https://c9dc173d.fastapitiangolo.pages.dev |
|
📝 Docs preview for commit 0226b66 at: https://99c0a14b.fastapitiangolo.pages.dev |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Just a personal opinion, I am not a maintainer but as a FastAPI user:
|
Were using mkdocs with Modern MISP. Documenting only the API would leave out integral parts of the software, doing documentation mixed (openapi for api, rest mkdocs) would be error-prone. Also if I'm using api functions outside the api, how should i document them?
I agree with the later part, however, making it optional would require much additional code and i doubt the benefit would outweigh it.
Could you elaborate that? I don't understand it. |
|
@JustKiddingCode, let's first wait for Sebastián to look at this PR and validate the idea. |
|
This pull request has a merge conflict that needs to be resolved. |
This pull request implements parsing docstrings via griffe and sets the relevant openapi descriptions to the corresponding docstring part.
The openapi has 3 description fields: the route itself, each parameter and the response.
With docstrings, you can only set one: The route itself. You can set the description for parameter and response using attributes in the router or annotations.
If I describe the function with all arguments, e.g. to build a documentation via mkdocs, the arguments that get autofilled by depends will appear in the openapi spec. If I want the description in the openapi spec and in the docstring there will be redundancy. Doing it only in the fastapi part, it will not be part of mkdocs (or similar).
As described by #3225, using docstrings is complicated, because the structure is not standardized. So I solve this using griffe, which can parse the most common formats (google, numpy, sphinx). Currently i set it to google format, but the plan is to make this configurable. However, if the description is set by fastapi attributes, this will take precedence.
will be converted to:
Before i continue to work on this, i want to know if adding a dependency is ok. If so, i would allow to set the parse format of the docstring (griffe supports google, numpy and sphinx).