Skip to content

Commit

Permalink
Merge branch 'master' into 1914
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlockhart authored Mar 4, 2020
2 parents b9e4bb0 + aad9f95 commit b499543
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 1,177 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ up_detached: compose_stop compose_build
generate_docs: compose_build
$(COMPOSE) run app sh -c "$(GENERATE_DOCS)"

eslint_fix: test_build
$(COMPOSE) run app sh -c "$(ESLINT_FIX)"

black_fix: test_build
$(COMPOSE) run app sh -c "$(BLACK_FIX)"

code_format: compose_build
$(COMPOSE) run app sh -c "$(BLACK_FIX)&&$(ESLINT_FIX)"

Expand Down
23 changes: 15 additions & 8 deletions app/experimenter/base/management/commands/generate-docs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import io
import os
import logging
import json

from django.conf import settings
from django.core.management import call_command
from django.template.loader import render_to_string
from django.core.management.base import BaseCommand

from rest_framework.schemas.openapi import SchemaGenerator


logger = logging.getLogger()

Expand All @@ -22,15 +22,22 @@ def handle(self, *args, **options):
self.generate_docs(options)

@staticmethod
def read_json_doc():
output = io.StringIO()
call_command("generateschema", "--format=openapi-json", stdout=output)
output.seek(0)
return output.read()
def generateSchema():
generator = SchemaGenerator(title="Experimenter API")
schema = generator.get_schema()
paths = schema["paths"]
for path in paths:
if "/api/v1/" in path:
for method in paths[path]:
paths[path][method]["tags"] = ["public"]
elif "/api/v2/" in path:
for method in paths[path]:
paths[path][method]["tags"] = ["private"]
return json.dumps(schema, indent=2)

@staticmethod
def generate_docs(options):
api_json = Command.read_json_doc()
api_json = Command.generateSchema()
docs_dir = os.path.join(settings.BASE_DIR, "docs")
schema_json_path = os.path.join(docs_dir, "openapi-schema.json")
swagger_html_path = os.path.join(docs_dir, "swagger-ui.html")
Expand Down
Loading

0 comments on commit b499543

Please # to comment.