mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-31 18:40:07 +03:00
Add generate_schema management command.
This commit is contained in:
parent
81fa4b4f75
commit
df5db61d3a
0
rest_framework/management/__init__.py
Normal file
0
rest_framework/management/__init__.py
Normal file
0
rest_framework/management/commands/__init__.py
Normal file
0
rest_framework/management/commands/__init__.py
Normal file
36
rest_framework/management/commands/generate_schema.py
Normal file
36
rest_framework/management/commands/generate_schema.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
|
||||
from rest_framework.renderers import CoreJSONRenderer
|
||||
from rest_framework.schemas import SchemaGenerator
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Generates configured API schema for project."
|
||||
|
||||
def add_arguments(self, parser):
|
||||
# TODO
|
||||
# SchemaGenerator allows passing:
|
||||
#
|
||||
# - title
|
||||
# - url
|
||||
# - description
|
||||
# - urlconf
|
||||
# - patterns
|
||||
#
|
||||
# Don't particularly want to pass these on the command-line.
|
||||
# conf file?
|
||||
#
|
||||
# Other options to consider:
|
||||
# - indent
|
||||
# - ...
|
||||
pass
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
||||
renderer = CoreJSONRenderer()
|
||||
generator = SchemaGenerator()
|
||||
schema = generator.get_schema(request=None, public=True)
|
||||
|
||||
rendered_schema = renderer.render(schema, renderer_context={}).decode('utf8')
|
||||
|
||||
self.stdout.write(rendered_schema)
|
Loading…
Reference in New Issue
Block a user