-
Notifications
You must be signed in to change notification settings - Fork 170
feat(api): Implement dfr-spectacular for OpenAPI spec generation #1378
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
base: feat/add-api
Are you sure you want to change the base?
Changes from 1 commit
8923bdc
6858c01
7b39c9b
173cf07
af6e010
2ab979b
b83db1b
99a6c68
73a7dbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from pathlib import Path | ||
|
|
||
| from django.core.management import BaseCommand, call_command | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| """Generate the OpenAPI schema file from DRF endpoints.""" | ||
|
|
||
| help = "Generate openapi.yaml using drf-spectacular." | ||
|
|
||
| def add_arguments(self, parser): | ||
| """Add optional CLI arguments.""" | ||
| parser.add_argument( | ||
| "--file", | ||
| default=None, | ||
| help="Output path for the schema file. Defaults to repository openapi.yaml.", # noqa: E501 | ||
| ) | ||
| parser.add_argument( | ||
| "--validate", | ||
| action="store_true", | ||
| help="Validate generated schema during export.", | ||
| ) | ||
|
|
||
| def handle(self, *args, **options): # noqa: ARG002 | ||
| """Generate OpenAPI file using spectacular command.""" | ||
| if options["file"]: | ||
| output_path = Path(options["file"]).expanduser().resolve() | ||
| else: | ||
| repo_root = Path(__file__).resolve().parents[4] | ||
| output_path = repo_root / "openapi.yaml" | ||
|
|
||
| output_path.parent.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| call_command( | ||
| "spectacular", | ||
| file=str(output_path), | ||
| validate=options["validate"], | ||
| color=True, | ||
| ) | ||
|
|
||
| self.stdout.write( | ||
| self.style.SUCCESS(f"OpenAPI schema generated: {output_path}"), | ||
| ) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -114,6 +114,7 @@ def secret(key, default=undefined, **kwargs): | |||||
| "django.contrib.sessions", | ||||||
| "django.contrib.messages", | ||||||
| "django.contrib.staticfiles", | ||||||
| "api", | ||||||
| "app", | ||||||
| "events", | ||||||
| "integrations", | ||||||
|
|
@@ -131,7 +132,6 @@ def secret(key, default=undefined, **kwargs): | |||||
| "allauth.socialaccount", | ||||||
| "django.contrib.humanize", | ||||||
| "rest_framework", | ||||||
| "api", | ||||||
| "drf_spectacular", | ||||||
| ] | ||||||
|
|
||||||
|
|
@@ -143,11 +143,10 @@ def secret(key, default=undefined, **kwargs): | |||||
| "api.authentication.BearerAuthentication", | ||||||
| "api.authentication.APIKeyAuthentication", | ||||||
| ], | ||||||
| "DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",), | ||||||
| "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", | ||||||
| "DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",), | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| APPEND_SLASH = True | ||||||
|
|
||||||
| MIDDLEWARE = [ | ||||||
|
|
@@ -352,6 +351,31 @@ def secret(key, default=undefined, **kwargs): | |||||
|
|
||||||
| TRACK_TIME = config("TRACK_TIME", default=True, cast=bool) | ||||||
|
|
||||||
| SPECTACULAR_ENABLE_SERVE = config( | ||||||
| "SPECTACULAR_ENABLE_SERVE", | ||||||
| default=DEBUG, | ||||||
| cast=bool, | ||||||
| ) | ||||||
|
|
||||||
| SPECTACULAR_SETTINGS = { | ||||||
| "TITLE": "Yamtrack API", | ||||||
| "DESCRIPTION": "OpenAPI schema for Yamtrack's API", | ||||||
| "VERSION": "0.0.25", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version string is hardcoded here, but a
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe when the API will be stable, not now |
||||||
| "LICENSE": { | ||||||
| "name": "GNU AFFERO GENERAL PUBLIC LICENSE v3.0", | ||||||
| "url": "https://github.com/FuzzyGrim/Yamtrack/blob/dev/LICENSE", | ||||||
| }, | ||||||
| "SCHEMA_PATH_PREFIX": "/api/v1", | ||||||
| "SORT_OPERATIONS": True, | ||||||
| "COMPONENT_SPLIT_REQUEST": True, | ||||||
| "SERVERS": [ | ||||||
| { | ||||||
| "url": "http://localhost:8000/", | ||||||
| "description": "Local development server", | ||||||
| }, | ||||||
| ], | ||||||
| } | ||||||
|
|
||||||
| TZ = zoneinfo.ZoneInfo(TIME_ZONE) | ||||||
|
|
||||||
| IMG_NONE = "https://www.themoviedb.org/assets/2/v4/glyphicons/basic/glyphicons-basic-38-picture-grey-c2ebdbb057f2a7614185931650f8cee23fa137b93812ccb132b9df511df1cfac.svg" | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.