8000 feat: add servers option for OpenAPI by mikaello · Pull Request #1547 · fastapi/fastapi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

feat: add servers option for OpenAPI #1547

Merged
merged 7 commits into from
Jun 14, 2020
Merged

feat: add servers option for OpenAPI #1547

merged 7 commits into from
Jun 14, 2020

Conversation

mikaello
Copy link
Contributor
@mikaello mikaello commented Jun 10, 2020

Closes/related to #872

The missing server option has been a drawback when it comes to the swagger UI (e.g. provide prod and test servers) and portability of the openapi.json to services that is based on knowing the servers.

Example usage:

from fastapi import FastAPI
from fastapi.openapi.models import Server

server1 = Server(url="http://example.com", description="optional description")
server2 = Server(url="http://test.com")

app = FastAPI(servers=[server1, server2])

@app.get("/")
async def root():
    return {"message": "Hello World"}

It would also work to just pass a dictionary, but then the typechecker won't be happy:

from fastapi import FastAPI

app = FastAPI(servers=[{"url": "http://example.com", "description": "test"}])

@codecov
Copy link
codecov bot commented Jun 10, 2020

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1547   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          234       235    +1     
  Lines         7004      7022   +18     
=========================================
+ Hits          7004      7022   +18     
Impacted Files Coverage Δ
fastapi/applications.py 100.00% <100.00%> (ø)
fastapi/openapi/models.py 100.00% <100.00%> (ø)
fastapi/openapi/utils.py 100.00% <100.00%> (ø)
tests/test_openapi_servers.py 100.00% <100.00%> (ø)

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 34c857b...3699101. Read the comment docs.

@tiangolo tiangolo merged commit b591de2 into fastapi:master Jun 14, 2020
@tiangolo
Copy link
Member

Thanks! 🚀

I updated it a bit to receive dicts by default. To not force users to import another class and create instances to be able to set the parameter. And added a test for it ✔️

Thanks for your contribution! 🎉 ☕

@mikaello mikaello deleted the add-servers-option-for-openapi branch June 15, 2020 07:28
@mikaello
Copy link
Contributor Author

Thanks for updating the branch, I agree that dict is better as default.

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.

2 participants
0