improving-drf-endpoints
यह क्या करती है
यह स्किल AI को Django REST Framework के endpoints और serializers की समीक्षा और सुधार की प्रक्रिया सिखाती है। यह उन डेवलपर्स के लिए है जो चाहते हैं कि उनका API दस्तावेज़ और बनाया गया कोड सटीक हो।
कब इस्तेमाल करें
- ✓जब आप Django REST Framework का serializer या viewset बदल रहे हों और उसके फ़ील्ड सही प्रकार में चाहते हों।
- ✓जब बनाए गए API टाइप में अज्ञात या गलत मान दिखें और आपको कारण ढूँढना हो।
- ✓जब आप API बदलाव की समीक्षा कर रहे हों और उसके फ़ील्ड विवरण व स्कीमा जाँचना चाहें।
Skill का लिंक
https://github.com/PostHog/posthog/blob/master/.agents/skills/improving-drf-endpoints/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरे Django API serializers की समीक्षा कीजिए, ताकि बने हुए docs और टाइप में सही फ़ील्ड और विवरण दिखें।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह हर फ़ील्ड का प्रकार, help text और स्कीमा नोट्स जाँचती है, क्योंकि ये जानकारी API दस्तावेज़ और उससे बने कोड में जाती है। फिर यह serializer कोड के सुधार सुझाती है।
तकनीकी सामग्री (मूल 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 पर काम करते हैं। यह बताती है कि क्या जाँचना है, पर कोड समझना आपको ही होगा।
इसका मुख्य फ़ायदा क्या है?
साफ़ help text और सही फ़ील्ड प्रकार से बने API दस्तावेज़ और क्लाइंट कोड हर endpoint का सही विवरण देते हैं।
क्या यह किसी भी API के साथ काम करता है?
यह उन Django REST Framework APIs के लिए है जो अपनी स्कीमा drf-spectacular से बनाते हैं।
जानकारी
लेखक का मूल विवरण
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
- लाइसेंस
- —
- अपडेट की गई
- 2/11/2026
कमेंट
- …
इस repository की और skills
depot-ci
41kयह आपके एजेंट को Depot CI वर्कफ़्लो सेट अप करने, चलाने और माइग्रेट करने में मदद करती है, साथ ही रन के लॉग पढ़ने में।
depot-container-builds
41kयह आपके एजेंट को Depot के रिमोट बिल्डर पर Docker इमेज बनाने में मदद करती है, जिसमें मल्टी-प्लेटफ़ॉर्म इमेज और बिल्ड सुधार शामिल हैं।
depot-github-runners
41kयह आपके एजेंट को GitHub Actions जॉब Depot के मैनेज्ड रनर पर ले जाने, रनर का साइज़ और लेबल चुनने, और रनर सेटअप की समस्याएँ ठीक करने में मदद करती है।
editing-agents-md
41kयह आपके एजेंट को तय करने में मदद करती है कि कोई नियम AGENTS.md या CLAUDE.md में जाए या नहीं, और उसे ऐसे लिखे कि फ़ाइल भारी न हो।
मिलती-जुलती skills
api-connector-builder
280kयह आपके एजेंट को मौजूदा pattern के हिसाब से नए API connections बनाने देता है। जब बिना कोई नया तरीका बनाए एक और integration जोड़ना हो, तब इसका इस्तेमाल करें।
api-design
280kयह आपके एजेंट को best practices के हिसाब से REST APIs डिज़ाइन करने में मदद करता है। यह तय करने में काम आता है कि APIs आपस में कैसे बात करें, errors कैसे दिखें, और data को कैसे व्यवस्थित करें।
backend-patterns
280kआपके एजेंट को server-side architecture patterns और database optimization में मदद करता है। server पर चलने वाला code बनाने या review करने के लिए उपयोगी है।