The PostHog API docs are generated using drf-spectacular. It looks at the Django models and djangorestframework serializers.
Note: We don't automatically add new API endpoints to the sidebar. You need to add those to src/navs/index.js
You can add a help_text="Field that does x" attribute to any Model or Serializer field to help users understand what a specific field is used for:
To add a description to the top of a page, add a comment to the viewset class:
You can do the same thing for specific endpoints.
To check what any changes will roughly look like locally, you can go to http://127.0.0.1:8000/api/schema/redoc/.
Insights serializer
The serializer for insight lives here. Each time an insight gets created we check it against these serializers, and we'll send an error to Sentry (but not the user) if it doesn't match, to ensure the API docs are up to date.
Documenting custom endpoints
If you have an @action endpoint or a custom endpoint (that doesn't use DRF) you can still document by providing a serializer for the request and response.
Testing API docs locally
To test or develop the API docs locally, you need to create a personal API key (see top of this page) and then export it before running gatsby, in the same terminal window: