Add flags to generate_schema command

This commit is contained in:
Tom Christie 2018-10-03 13:56:18 +01:00
parent 5ccdded2a8
commit 619a84f583

View File

@ -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)