8000 Correctly display Swagger docs when using reverse proxy by rkbeatss · Pull Request #1596 · fastapi/fastapi · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@rkbeatss
Copy link
Contributor
@rkbeatss rkbeatss commented Jun 19, 2020

addressing #1294: root_path is now included in the servers object instead of in the path prefix. should more tests be added?

@rkbeatss rkbeatss marked this pull request as draft June 19, 2020 16:31
@codecov
Copy link
codecov bot commented Jun 19, 2020

Codecov Report

Merging #1596 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            master     #1596    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          236       238     +2     
  Lines         7068      7187   +119     
==========================================
+ Hits          7068      7187   +119     
Impacted Files Coverage Δ
tests/test_deprecated_openapi_prefix.py 100.00% <ø> (ø)
tests/test_security_oauth2.py 100.00% <ø> (ø)
.../test_security_oauth2_authorization_code_bearer.py 100.00% <ø> (ø)
tests/test_security_oauth2_optional.py 100.00% <ø> (ø)
...t_tutorial/test_behind_a_proxy/test_tutorial001.py 100.00% <ø> (ø)
...t_tutorial/test_behind_a_proxy/test_tutorial002.py 100.00% <ø> (ø)
...ts/test_tutorial/test_security/test_tutorial001.py 100.00% <ø> (ø)
...ts/test_tutorial/test_security/test_tutorial003.py 100.00% <ø> (ø)
...ts/test_tutorial/test_security/test_tutorial005.py < 8000 code class="notranslate">100.00% <ø> (ø)
...tutorial/test_sub_applications/test_tutorial001.py 100.00% <ø> (ø)
... and 25 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 b87072b...5544689. Read the comment docs.

@rkbeatss rkbeatss marked this pull request as ready for review June 19, 2020 17:58
@rkbeatss rkbeatss marked this pull request as draft June 27, 2020 15:48
@rkbeatss rkbeatss marked this pull request as ready for review June 27, 2020 16:26
@tiangolo tiangolo merged commit 70a51b3 into fastapi:master Jul 10, 2020
@tiangolo
Copy link
Member

Awesome, thanks @rkbeatss ! 🚀 🍰

I updated it a bit and included an optional parameter root_path_in_servers in case someone doesn't want the auto-generated servers. And I added some docs for that.

Given this solves the generation of OpenAPI schemas and the utils no longer need the openapi_prefix, I removed that parameter that was recently added, so, back to its original form 🤦‍♂️

I also checked/confirmed that this doesn't break the functionality with OAuth2 tokens by the spec, and to make sure they all stay compatible, I made those tokenUrls relative URLs, that way those docs will keep working as-is even when behind a reverse proxy.

Thanks for your contribution! ☕ 🚀 🎉

@dontsovcmc
Copy link

I solved this issue using subapi:
root_path doesn't work for me. openapi_prefix is deprecated.

from fastapi import FastAPI

app = FastAPI()

@app.get("/app")
def read_main():
    return {"message": "Hello World from main app"}

subapi = FastAPI()

@subapi.get("/sub")
def read_sub():
    return {"message": "Hello World from sub API"}

app.mount("/subapi", subapi)

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

0