add --generator_class CLI option to generateschema

This commit is contained in:
Alan Crosswell 2019-06-06 12:42:43 -04:00
parent 9ac9c1b2ea
commit e49a50c6c3
No known key found for this signature in database
GPG Key ID: 55819C8ADBD81C72
2 changed files with 7 additions and 1 deletions

View File

@ -45,6 +45,7 @@ You can determine your currently installed version using `pip show`:
**Date**: [Unreleased][3.10.0-milestone] **Date**: [Unreleased][3.10.0-milestone]
* Resolve DeprecationWarning with markdown. [#6317][gh6317] * Resolve DeprecationWarning with markdown. [#6317][gh6317]
* Add `generateschema --generator_class` CLI option
## 3.9.x series ## 3.9.x series

View File

@ -1,4 +1,5 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.utils.module_loading import import_string
from rest_framework import renderers from rest_framework import renderers
from rest_framework.schemas import coreapi from rest_framework.schemas import coreapi
@ -22,9 +23,13 @@ class Command(BaseCommand):
parser.add_argument('--format', dest="format", choices=['openapi', 'openapi-json', 'corejson'], default='openapi', type=str) parser.add_argument('--format', dest="format", choices=['openapi', 'openapi-json', 'corejson'], default='openapi', type=str)
else: else:
parser.add_argument('--format', dest="format", choices=['openapi', 'openapi-json'], default='openapi', type=str) parser.add_argument('--format', dest="format", choices=['openapi', 'openapi-json'], default='openapi', type=str)
parser.add_argument('--generator_class', dest="generator_class", default=None, type=str)
def handle(self, *args, **options): def handle(self, *args, **options):
generator_class = self.get_generator_class() if options['generator_class']:
generator_class = import_string(options['generator_class'])
else:
generator_class = self.get_generator_class()
generator = generator_class( generator = generator_class(
url=options['url'], url=options['url'],
title=options['title'], title=options['title'],