mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40: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."
|
help = "Generates configured API schema for project."
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
# TODO
|
parser.add_argument('--title', dest="title", default=None, type=str)
|
||||||
# SchemaGenerator allows passing:
|
parser.add_argument('--url', dest="url", default=None, type=str)
|
||||||
#
|
parser.add_argument('--description', dest="description", default=None, type=str)
|
||||||
# - title
|
parser.add_argument('--format', dest="format", choices=['openapi', 'openapi-json', 'corejson'], default='openapi', type=str)
|
||||||
# - url
|
|
||||||
# - description
|
|
||||||
#
|
|
||||||
# Don't particularly want to pass these on the command-line.
|
|
||||||
# conf file?
|
|
||||||
#
|
|
||||||
# Other options to consider:
|
|
||||||
# - indent
|
|
||||||
# - ...
|
|
||||||
pass
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
assert coreapi is not None, 'coreapi must be installed.'
|
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()
|
generator = generator_class()
|
||||||
|
|
||||||
schema = generator.get_schema(request=None, public=True)
|
schema = generator.get_schema(request=None, public=True)
|
||||||
|
|
||||||
renderer = self.get_renderer('openapi')
|
renderer = self.get_renderer(options['format'])
|
||||||
output = renderer.render(schema)
|
output = renderer.render(schema)
|
||||||
|
|
||||||
self.stdout.write(output)
|
self.stdout.write(output)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user