forked from tiangolo/fastapi
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Enable configuring Swagger UI parameters (tiangolo#2568)
Co-authored-by: Artem Ivanov <artem@worklife.io> Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
- Loading branch information
1 parent
fb9bd72
commit f421f09
Showing
12 changed files
with
251 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from fastapi import FastAPI | ||
|
||
app = FastAPI(swagger_ui_parameters={"syntaxHighlight": False}) | ||
|
||
|
||
@app.get("/users/{username}") | ||
async def read_user(username: str): | ||
return {"message": f"Hello {username}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from fastapi import FastAPI | ||
|
||
app = FastAPI(swagger_ui_parameters={"syntaxHighlight.theme": "obsidian"}) | ||
|
||
|
||
@app.get("/users/{username}") | ||
async def read_user(username: str): | ||
return {"message": f"Hello {username}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from fastapi import FastAPI | ||
|
||
app = FastAPI(swagger_ui_parameters={"deepLinking": False}) | ||
|
||
|
||
@app.get("/users/{username}") | ||
async def read_user(username: str): | ||
return {"message": f"Hello {username}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/test_tutorial/test_extending_openapi/test_tutorial003.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from docs_src.extending_openapi.tutorial003 import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_swagger_ui(): | ||
response = client.get("/docs") | ||
assert response.status_code == 200, response.text | ||
assert ( | ||
'"syntaxHighlight": false' in response.text | ||
), "syntaxHighlight should be included and converted to JSON" | ||
assert ( | ||
'"dom_id": "#swagger-ui"' in response.text | ||
), "default configs should be preserved" | ||
assert "presets: [" in response.text, "default configs should be preserved" | ||
assert ( | ||
"SwaggerUIBundle.presets.apis," in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
"SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"layout": "BaseLayout",' in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"deepLinking": true,' in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"showExtensions": true,' in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"showCommonExtensions": true,' in response.text | ||
), "default configs should be preserved" | ||
|
||
|
||
def test_get_users(): | ||
response = client.get("/users/foo") | ||
assert response.status_code == 200, response.text | ||
assert response.json() == {"message": "Hello foo"} |
44 changes: 44 additions & 0 deletions
44
tests/test_tutorial/test_extending_openapi/test_tutorial004.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from docs_src.extending_openapi.tutorial004 import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_swagger_ui(): | ||
response = client.get("/docs") | ||
assert response.status_code == 200, response.text | ||
assert ( | ||
'"syntaxHighlight": false' not in response.text | ||
), "not used parameters should not be included" | ||
assert ( | ||
'"syntaxHighlight.theme": "obsidian"' in response.text | ||
), "parameters with middle dots should be included in a JSON compatible way" | ||
assert ( | ||
'"dom_id": "#swagger-ui"' in response.text | ||
), "default configs should be preserved" | ||
assert "presets: [" in response.text, "default configs should be preserved" | ||
assert ( | ||
"SwaggerUIBundle.presets.apis," in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
"SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"layout": "BaseLayout",' in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"deepLinking": true,' in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"showExtensions": true,' in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"showCommonExtensions": true,' in response.text | ||
), "default configs should be preserved" | ||
|
||
|
||
def test_get_users(): | ||
response = client.get("/users/foo") | ||
assert response.status_code == 200, response.text | ||
assert response.json() == {"message": "Hello foo"} |
44 changes: 44 additions & 0 deletions
44
tests/test_tutorial/test_extending_openapi/test_tutorial005.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from docs_src.extending_openapi.tutorial005 import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_swagger_ui(): | ||
response = client.get("/docs") | ||
assert response.status_code == 200, response.text | ||
assert ( | ||
'"deepLinking": false,' in response.text | ||
), "overridden configs should be preserved" | ||
assert ( | ||
'"deepLinking": true' not in response.text | ||
), "overridden configs should not include the old value" | ||
assert ( | ||
'"syntaxHighlight": false' not in response.text | ||
), "not used parameters should not be included" | ||
assert ( | ||
'"dom_id": "#swagger-ui"' in response.text | ||
), "default configs should be preserved" | ||
assert "presets: [" in response.text, "default configs should be preserved" | ||
assert ( | ||
"SwaggerUIBundle.presets.apis," in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
"SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"layout": "BaseLayout",' in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"showExtensions": true,' in response.text | ||
), "default configs should be preserved" | ||
assert ( | ||
'"showCommonExtensions": true,' in response.text | ||
), "default configs should be preserved" | ||
|
||
|
||
def test_get_users(): | ||
response = client.get("/users/foo") | ||
assert response.status_code == 200, response.text | ||
assert response.json() == {"message": "Hello foo"} |