-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace drf-yasg with drf_spectacular
- Loading branch information
Showing
13 changed files
with
272 additions
and
78 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
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
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
36 changes: 36 additions & 0 deletions
36
src/olympia/amo/management/commands/generate_js_swagger_files.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,36 @@ | ||
from pathlib import Path | ||
|
||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
from django.http import HttpRequest | ||
from django.utils.encoding import force_str | ||
|
||
from drf_spectacular.views import SpectacularSwaggerSplitView | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Generate static swagger files' | ||
requires_system_checks = [] # Can be ran without the database up yet. | ||
|
||
def handle(self, *args, **options): | ||
fake_request = HttpRequest() | ||
fake_request.method = 'GET' | ||
fake_request.META = { | ||
'SERVER_NAME': '.mozilla.org', | ||
'SERVER_PORT': '80', | ||
} | ||
|
||
# Add a script parameter to the request to get the swagger UI JS | ||
fake_request.GET['script'] = '1' | ||
|
||
root = Path(settings.STATIC_BUILD_PATH) / 'js' / 'swagger' | ||
|
||
if not root.exists(): | ||
root.mkdir(parents=True) | ||
|
||
response = SpectacularSwaggerSplitView.as_view()(fake_request) | ||
response.render() | ||
filename = root / 'swagger_ui.js' | ||
with open(filename, 'w') as f: | ||
with open(filename, 'w') as f: | ||
f.write(force_str(response.content)) |
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
Oops, something went wrong.