improving-drf-endpoints
하는 일
이 스킬은 Django REST Framework 엔드포인트와 시리얼라이저를 검토하고 고치는 과정을 AI에게 안내합니다. API 문서와 자동 생성 코드를 정확하게 만들려는 개발자를 위한 것입니다.
사용하는 경우
- ✓Django REST Framework 시리얼라이저나 뷰셋을 편집하면서 필드 타입을 올바르게 지정하고 싶을 때.
- ✓생성된 API 타입에 알 수 없거나 잘못된 값이 보여서 원인을 찾아야 할 때.
- ✓API 변경을 검토하면서 필드 설명과 스키마를 확인하고 싶을 때.
스킬 링크
https://github.com/PostHog/posthog/blob/master/.agents/skills/improving-drf-endpoints/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“생성된 문서와 타입에 올바른 필드와 설명이 나오도록 제 Django API 시리얼라이저를 검토해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
각 필드의 타입, 도움말 텍스트, 스키마 메모를 확인합니다. 이 정보는 API 문서와 그로부터 생성된 코드로 전달되기 때문입니다. 그다음 시리얼라이저 코드의 수정안을 제안합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Improving DRF Endpoints
Before you propose a contract test against the generated OpenAPI schema, check things already tried. Six PRs took that idea, and none merged.
Overview
Serializer fields are the source of truth for PostHog's entire type pipeline:
Django serializer → drf-spectacular → OpenAPI JSON → Orval → Zod schemas → MCP tools
Every help_text, every field type, every @extend_schema annotation flows downstream.
A missing help_text means an agent guessing at parameters.
A bare ListField() means z.unknown() in the generated Zod schema.
Getting the serializer right means every consumer — frontend types, MCP tools, API docs — gets correct types and descriptions automatically.
When to use
- Editing or reviewing any file that defines a
SerializerorViewSet - Fixing OpenAPI spec warnings or generated type issues
- Preparing an endpoint for MCP tool exposure
- Code review of API changes
Audit checklist
Triage: check the generated output first
Before diving into Python, look at the committed generated types to see what's broken. Find the generated files for the endpoint's product:
- Core API:
frontend/src/generated/core/ - Product APIs:
products/<product>/frontend/generated/
Each has two files:
api.schemas.ts— TypeScript interfaces derived from serializers. Search for the serializer name and look forunknowntypes (bareListField/JSONField), missing JSDoc descriptions (missinghelp_text), or overly genericRecord<string, unknown>shapes.api.ts— API client functions. Check if the endpoint's operation exists at all — if missing, the viewset method likely lacks@extend_schema.
This tells you exactly which fields and endpoints to prioritize.
Serializer fields
Work through this list for every serializer and viewset you touch.
- Every field has
help_text— describes purpose, format, constraints, valid values - No bare
ListField()orDictField()— always specifychild=with a typed serializer or field - No bare
JSONField()— create a custom field class with@extend_schema_field(TypedSchema) SerializerMethodFieldhas@extend_schema_fieldon itsget_*methodChoiceFieldhas explicitchoices=with all valid values listed- Define choices as a class —
models.TextChoicesin a product's internal modules,LabeledStrEnumorLabeledIntEnumfromposthog/enums.pyin facade contract files (backend/facade/contracts.py,backend/facade/enums.py), which must not import Django. The OpenAPI component is named after the class either way (EarlyAccessFeature.Stage->EarlyAccessFeatureStageEnum, viaChoicesEnumNameOverridesinposthog/openapi/enum_names.py), so a class-backed enum never collides on field names likeformat,type,status,kind. PassX.choicestochoices=, and to name a labeled enum on aSerializerMethodFielduse@extend_schema_field(ChoiceField(choices=X.choices)), not a return type hint. Inlinechoices=[...]lists have no class to read, collide with existing choices, and fail CI under--fail-on-warn; an explicitENUM_NAME_OVERRIDESentry inposthog/settings/web.pyis the fallback for choice sets no class can carry (see serializer-fields.md) - Read vs write serializers are separate when input shape differs from output
- Every success response is backed by a serializer — returning raw dicts or untyped lists means no generated types downstream
See serializer-fields.md for patterns and examples.
Viewset and action annotations
- Every custom
@actionhas@extend_schemaor@validated_request— without it, drf-spectacular discovers zero parameters - Plain
ViewSetmethods have schema annotations —ModelViewSetwithserializer_classis auto-discovered; plainViewSetis not @extend_schemais on the actual method (get,post,create,list), not on a helper or the class itself- Error responses are typed — use
OpenApiResponse(response=ErrorSerializer), notOpenApiTypes.OBJECT - List endpoints declare pagination — reset with
pagination_class=Noneon custom actions that don't paginate - Prefer
@validated_requestover manualserializer.is_valid()+@extend_schema— it handles both in one decorator - **ViewSets o
자주 묻는 질문
Django를 알아야 사용할 수 있나요?
네. Django REST Framework로 이미 작업하는 개발자를 위한 것입니다. 무엇을 확인해야 할지는 설명하지만, 코드를 이해하고 있어야 합니다.
가장 큰 장점은 무엇인가요?
명확한 도움말 텍스트와 올바른 필드 타입 덕분에 생성된 API 문서와 클라이언트 코드가 각 엔드포인트를 정확하게 설명합니다.
모든 API에서 작동하나요?
drf-spectacular로 스키마를 생성하는 Django REST Framework API를 대상으로 합니다.
상세 정보
작성자의 원본 설명
Use when editing, reviewing, or auditing DRF viewsets and serializers in PostHog. Triggers on files in posthog/api/, products/*/backend/api/, products/*/backend/presentation/, or any file importing rest_framework. Covers field typing, schema annotations, enum collision fixes, and OpenAPI spec quality — everything that flows downstream into generated TypeScript types and MCP tools.
repo: PostHog/posthog
인기도
- GitHub 스타
- 41k
- 순위
- #6815
- 라이선스
- —
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
depot-ci
41k에이전트가 GitHub Actions 대안인 Depot CI 워크플로를 설정하고 실행하도록 돕습니다. 기존 워크플로 이전과 실행 로그 읽기를 포함합니다.
depot-container-builds
41k에이전트가 Depot 원격 빌더에서 Docker 이미지를 빌드하도록 돕습니다. 다중 플랫폼 이미지, 레지스트리 푸시, 빌드 실패 수정을 포함합니다.
depot-github-runners
41k에이전트가 GitHub Actions 작업을 Depot 관리형 러너로 옮기고, 러너 크기와 라벨을 고르도록 돕습니다.
editing-agents-md
41k에이전트가 규칙을 AGENTS.md나 CLAUDE.md 중 어디에 둘지 정하고, 파일을 키우지 않으면서 잘 지켜지도록 쓰게 돕습니다.
비슷한 스킬
api-connector-builder
280k에이전트가 기존 패턴을 따라 새로운 API 연결을 만들도록 합니다. 새로운 방식을 도입하지 않고 연동을 하나 더 추가할 때 씁니다.
api-design
280k에이전트가 모범 사례에 따라 REST API를 설계하도록 돕습니다. API가 통신하는 방식, 오류를 보여 주는 방식, 데이터를 정리하는 방식을 정하는 데 유용합니다.
backend-patterns
280k에이전트가 서버 쪽 아키텍처 패턴과 데이터베이스 최적화를 다루도록 돕습니다. 서버에서 실행되는 코드를 만들거나 검토할 때 유용합니다.