Skip to content

Allow api docs to be truncated and used for other purposes - #556

Merged
tiangolo merged 8 commits into
fastapi:masterfrom
svalouch:split-route-description
Oct 4, 2019
Merged

tiangolo merged 8 commits into
fastapi:masterfrom
svalouch:split-route-description

Conversation

@svalouch

Copy link
Copy Markdown
Contributor

This is essentually the same Click does:
https://click.palletsprojects.com/en/7.x/documentation/#truncating-help-texts

It allows splitting the documenting text so that the lower part may be
used to describe the function further, e.g. extracting information using
Sphinx.

This is essentually the same Click does:
https://click.palletsprojects.com/en/7.x/documentation/#truncating-help-texts

It allows splitting the documenting text so that the lower part may be
used to describe the function further, e.g. extracting information using
Sphinx.
Comment thread fastapi/routing.py Outdated
self.description = description or inspect.cleandoc(self.endpoint.__doc__ or "")
# if a form feed (page break) is found in the description text, truncate
# description text to the content preceding the first form feed
if self.description and "\f" in self.description:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check for "\f" in self.description; the first result of split will just be the whole string in that case

@dmontagu

dmontagu commented Sep 22, 2019 •

Copy link
Copy Markdown
Contributor

This seems like a nice, simple addition. Using "\f" as the splitting pattern might not have been my first choice (or at least, not the first choice I considered), but given other well-established tools use it for this purpose it seems reasonable enough to me. I can't imagine it getting in the way.

@codecov

codecov Bot commented Sep 22, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #556 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #556    +/-   ##
======================================
  Coverage     100%   100%            
======================================
  Files         251    257     +6     
  Lines        5988   6270   +282     
======================================
+ Hits         5988   6270   +282
Impacted Files Coverage Δ
fastapi/routing.py 100% <100%> (ø) ⬆️
...ration_advanced_configurations/test_tutorial003.py 100% <100%> (ø)
...th_operation_advanced_configuration/tutorial003.py 100% <100%> (ø)
...est_additional_responses_custom_validationerror.py 100% <0%> (ø) ⬆️
docs/src/app_testing/tutorial003.py 100% <0%> (ø) ⬆️
...t_query_params_str_validations/test_tutorial001.py 100% <0%> (ø) ⬆️
tests/test_custom_swagger_ui_redirect.py 100% <0%> (ø) ⬆️
docs/src/first_steps/tutorial001.py 100% <0%> (ø) ⬆️
tests/test_additional_responses_router.py 100% <0%> (ø) ⬆️
docs/src/application_configuration/tutorial001.py 100% <0%> (ø) ⬆️
... and 74 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 580cf8f...86ee517. Read the comment docs.

@svalouch

Copy link
Copy Markdown
Contributor Author

I simplified the splitting, thanks for pointing it out.
If we used other characters than \f, we need to test commonly used tools for their compatibility, that is, if they just ignore it. Sphinx is known to work with it just fine.

Comment thread tests/test_split_docstrings.py Resolved
@dmontagu

dmontagu commented Sep 22, 2019 •

Copy link
Copy Markdown
Contributor

Oh also, the formatting is wrong (in at least one of the test files) -- run ./scripts/format-imports.sh -- it should automatically fix it for you.

@svalouch

svalouch commented Sep 22, 2019 •

Copy link
Copy Markdown
Contributor Author

Okay, done. Sorry for the noise. I didn't know you could define functions without a body, but the test suite confirms it. I lean something new every day :)

@dmontagu

dmontagu commented Sep 22, 2019 •

Copy link
Copy Markdown
Contributor

The reason it works is because it has a docstring - so technically it does have a body :). At least, it has enough of one for python to not raise a syntax error. If you drop the docstring it will error.

@tiangolo
tiangolo merged commit c7dc26b into fastapi:master Oct 4, 2019
@tiangolo

tiangolo commented Oct 4, 2019

Copy link
Copy Markdown
Member

Thank you for your contribution @svalouch ! 🎉 🚀 🍰

I updated it a bit and moved the docs to the section on advanced path operation configurations.

Thanks @dmontagu for the help and comments! 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants