0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-22 08:40:03 +01:00

Add API documentation

This commit is contained in:
Tim Glaser 2020-02-13 22:50:44 -08:00
parent 5b216172d5
commit 4e59812b6b
5 changed files with 29 additions and 3 deletions

View File

@ -164,4 +164,7 @@ REST_FRAMEWORK = {
}
# You can pass a comma deliminated list of domains with which users can sign up to this service
RESTRICT_SIGNUPS = os.environ.get('RESTRICT_SIGNUPS', False)
RESTRICT_SIGNUPS = os.environ.get('RESTRICT_SIGNUPS', False)
if os.environ.get('INCLUDE_DOCS', False):
INSTALLED_APPS.push('drf_yasg')

View File

@ -12,6 +12,23 @@ from .models import Team, User
import json
import posthoganalytics
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
schema_view = get_schema_view(
openapi.Info(
title="PostHog API",
default_version='v1',
description="PostHog's API allows you to do anything you can do in the PostHog frontend.",
contact=openapi.Contact(email="hey@posthog.com"),
license=openapi.License(name="MIT License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)
def render_template(template_name: str, request, context=None) -> HttpResponse:
template = get_template(template_name)
html = template.render(context, request=request)
@ -101,6 +118,11 @@ urlpatterns = [
path('login', login_view, name='login'),
path('signup', signup_view, name='signup'),
path('setup_admin', setup_admin, name='setup_admin'),
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
# react frontend
re_path(r'^.*', decorators.login_required(home)),

View File

@ -25,7 +25,7 @@ USER root
COPY requirements.txt /code/
# install dependencies but ignore any we don't need for dev environment
RUN pip install $(grep -ivE "psycopg2|ipdb|mypy|ipython|ipdb|pip|djangorestframework-stubs|django-stubs|ipython-genutils|mypy-extensions|Pygments|typed-ast|jedi" requirements.txt) --no-cache-dir --compile\
RUN pip install $(grep -ivE "drf-yasg|spsycopg2|ipdb|mypy|ipython|ipdb|pip|djangorestframework-stubs|django-stubs|ipython-genutils|mypy-extensions|Pygments|typed-ast|jedi" requirements.txt) --no-cache-dir --compile\
&& pip install psycopg2-binary --no-cache-dir --compile\
&& pip uninstall ipython-genutils pip -y \
&& rm -rf /usr/local/lib/python3.8/site-packages/numpy/core/tests \

View File

@ -5,7 +5,7 @@ WORKDIR /code
COPY requirements.txt /code/
# install dependencies but ignore any we don't need for dev environment
RUN pip install $(grep -ivE "psycopg2|ipdb|mypy|ipython|ipdb|pip|djangorestframework-stubs|django-stubs|ipython-genutils|mypy-extensions|Pygments|typed-ast|jedi" requirements.txt) --no-cache-dir --compile\
RUN pip install $(grep -ivE "drf-yasg|psycopg2|ipdb|mypy|ipython|ipdb|pip|djangorestframework-stubs|django-stubs|ipython-genutils|mypy-extensions|Pygments|typed-ast|jedi" requirements.txt) --no-cache-dir --compile\
&& pip install psycopg2-binary --no-cache-dir --compile\
&& pip uninstall ipython-genutils pip -y
COPY frontend/ /code/frontend

View File

@ -12,6 +12,7 @@ django-loginas==0.3.8
django-stubs==1.4.0
djangorestframework==3.11.0
djangorestframework-stubs==1.1.0
drf-yasg==1.17.0
freezegun==0.3.14
gunicorn==20.0.4
idna==2.8