Skip to content
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

♻ Strip empty whitespace from description extracted from docstrings #2821

Merged
merged 2 commits into from Aug 23, 2022

Conversation

and-semakin
Copy link
Contributor

What I want to achieve is to receive a clearer description field in auto-generated OpenAPI docs. For example, for this endpoint:

@app.get("/example")
async def example():
    """Example endpoint to test auto-generated OpenAPI docs.

    Well, it's just a dumb endpoint without any logic inside.

    \f

    :return: empty dict
    """
    return {}

I would like to get not these docs:

  /example:
    get:
      description: 'Example endpoint to test auto-generated OpenAPI docs.


        Well, it''s just a dumb endpoint without any logic inside.


        '
      operationId: example_example_get
      responses:
        '200':
          content:
            application/json:
              schema: {}
          description: Successful Response
      summary: Example

But these (without trailing spacing characters):

  /example:
    get:
      description: 'Example endpoint to test auto-generated OpenAPI docs.


        Well, it''s just a dumb endpoint without any logic inside.'
      operationId: example_example_get
      responses:
        '200':
          content:
            application/json:
              schema: {}
          description: Successful Response
      summary: Example

I know that it doesn't make any difference in Swagger UI but anyway, why storing redundant characters? 😅

@codecov
Copy link

codecov bot commented Feb 16, 2021

Codecov Report

Merging #2821 (f46b045) into master (f8f5281) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #2821   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          533       533           
  Lines        13755     13755           
=========================================
  Hits         13755     13755           
Impacted Files Coverage Δ
...ration_advanced_configurations/test_tutorial004.py 100.00% <ø> (ø)
fastapi/routing.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 8b9f8ea at: https://602bf5579f36d459122ced3d--fastapi.netlify.app

@tiangolo tiangolo changed the title Strip description derived from route's docstring ♻ Strip empty whitespace from description extracted from docstrings Aug 23, 2022
@tiangolo
Copy link
Owner

Yep, this looks fine. Thanks for your contribution! 🍰

@tiangolo tiangolo enabled auto-merge (squash) August 23, 2022 13:45
@tiangolo tiangolo merged commit f6808e7 into tiangolo:master Aug 23, 2022
@and-semakin and-semakin deleted the strip_openapi_description branch August 23, 2022 16:28
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.

None yet

2 participants