mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-01 11:00:13 +03:00
Add flags to generate_schema command
This commit is contained in:
parent
5ccdded2a8
commit
619a84f583
|
@ -9,30 +9,24 @@ class Command(BaseCommand):
|
|||
help = "Generates configured API schema for project."
|
||||
|
||||
def add_arguments(self, parser):
|
||||
# TODO
|
||||
# SchemaGenerator allows passing:
|
||||
#
|
||||
# - title
|
||||
# - url
|
||||
# - description
|
||||
#
|
||||
# Don't particularly want to pass these on the command-line.
|
||||
# conf file?
|
||||
#
|
||||
# Other options to consider:
|
||||
# - indent
|
||||
# - ...
|
||||
pass
|
||||
parser.add_argument('--title', dest="title", default=None, type=str)
|
||||
parser.add_argument('--url', dest="url", default=None, type=str)
|
||||
parser.add_argument('--description', dest="description", default=None, type=str)
|
||||
parser.add_argument('--format', dest="format", choices=['openapi', 'openapi-json', 'corejson'], default='openapi', type=str)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
assert coreapi is not None, 'coreapi must be installed.'
|
||||
|
||||
generator_class = api_settings.DEFAULT_SCHEMA_GENERATOR_CLASS()
|
||||
generator_class = api_settings.DEFAULT_SCHEMA_GENERATOR_CLASS(
|
||||
url=options['url']
|
||||
title=options['title']
|
||||
description=options['description']
|
||||
)
|
||||
generator = generator_class()
|
||||
|
||||
schema = generator.get_schema(request=None, public=True)
|
||||
|
||||
renderer = self.get_renderer('openapi')
|
||||
renderer = self.get_renderer(options['format'])
|
||||
output = renderer.render(schema)
|
||||
|
||||
self.stdout.write(output)
|
||||
|
|
Loading…
Reference in New Issue
Block a user