- الرئيسية
- F5 XC API Specs
- دليل التطوير
دليل التطوير
الإعداد
Section titled “الإعداد”# Clone and install dev dependenciesgit clone https://github.com/f5-sales-demo/api-specs.gitcd api-specsmake dev-install
# Install Spectral CLI (required for linting stages)npm install -g @stoplight/spectral-cliيقوم make dev-install بإنشاء بيئة افتراضية في .venv/ ويثبّت المشروع مع الحزم الإضافية للتطوير (pytest، ruff، mypy).
متغيرات البيئة
Section titled “متغيرات البيئة”يتطلب التحقق المباشر من واجهة برمجة التطبيقات ما يلي:
export F5XC_API_URL="https://example-tenant.console.ves.volterra.io"export F5XC_API_TOKEN="your-api-token"بدون هذه المتغيرات، يعود make validate إلى وضع التشغيل التجريبي (dry-run).
تشغيل خط الأنابيب
Section titled “تشغيل خط الأنابيب”خط الأنابيب الكامل
Section titled “خط الأنابيب الكامل”make all# Runs: download → validate → spectral-lint → reconcile → spectral-gate → releaseالمراحل الفردية
Section titled “المراحل الفردية”make download # Fetch upstream specsmake validate # Run live API tests (requires API token)make validate-dry # Dry run (no API calls)make spectral-lint # Spectral discover mode on original specsmake reconcile # Apply fixes from both reportsmake spectral-gate # Spectral quality gate on reconciled specsmake release # Build release packageالتوثيق
Section titled “التوثيق”make docs-generate # Regenerate docs/01-validation-report.mdx from reportsmake docs # Build full documentation sitemake docs-serve # Local dev server with hot reloadتشغيل الاختبارات
Section titled “تشغيل الاختبارات”make test # pytest with coveragemake lint # ruff check + format checkmake typecheck # mypy type checkingmake ci-test # All three (used in CI)تعمل خطافات ما قبل الالتزام (pre-commit hooks) تلقائيًا عند كل التزام إذا تم تثبيتها:
make pre-commit-install # Install git hooksmake pre-commit # Run all hooks manuallyهيكل المشروع
Section titled “هيكل المشروع”scripts/ download.py # Stage 1: Fetch specs from F5 validate.py # Stage 2: Live API testing spectral_lint.py # Stage 3/5: Spectral linting adapter reconcile.py # Stage 4: Apply fixes to specs release.py # Stage 6: Package release generate_docs.py # Generate MDX from reports utils/ auth.py # F5 XC API authentication constraint_validator.py # Constraint testing + Discrepancy types report_generator.py # Report formatting schemathesis_runner.py # Schemathesis test orchestration spec_loader.py # Spec I/O + JSON formatting
config/ validation.yaml # Pipeline configuration endpoints.yaml # Baseline endpoints for live testing
spectral/ functions/ f5-path-params.js # Custom Spectral function
docs/ # Starlight MDX documentationtests/ # pytest test suiterelease/specs/ # Output: reconciled spec filesreports/ # Output: validation and Spectral reportsإضافة طريقة إصلاح جديدة
Section titled “إضافة طريقة إصلاح جديدة”لإضافة إصلاح تلقائي جديد لـ Spectral إلى أداة التوفيق (reconciler):
-
أضف القاعدة إلى
.spectral.yamlمع مستوى الخطورة المطلوب. -
فعّل الإصلاح التلقائي في
config/validation.yamlتحتspectral.auto_fix:spectral:auto_fix:your-new-rule: true -
أضف طريقة الإصلاح إلى
SpecReconcilerفيscripts/reconcile.py:def _fix_your_rule(self, spec: dict, discrepancy: Discrepancy) -> dict | None:"""Fix description."""# Modify spec in place# Return spec if changed, None if no change neededreturn spec -
سجّلها في موزّع
_apply_spectral_fix:spectral_fixers = {# ... existing fixers ..."spectral:your-new-rule": self._fix_your_rule,} -
أضف اختبارات تغطي طريقة الإصلاح الجديدة.
إضافة قاعدة Spectral جديدة
Section titled “إضافة قاعدة Spectral جديدة”لإضافة قاعدة Spectral مخصصة مع دالة JavaScript:
-
أنشئ الدالة في
spectral/functions/your-rule.js. قم بتصدير دالة افتراضية تستقبل(targetVal, options, context)وتُرجع مصفوفة من كائنات{message, path}. -
سجّلها في
spectral-pipeline.yaml:functions:- f5-path-params- your-rulerules:your-rule:description: "What it checks"message: "{{error}}"severity: errorgiven: "$.paths[*]"then:function: your-rule
خط أنابيب التكامل المستمر (CI)
Section titled “خط أنابيب التكامل المستمر (CI)”يعمل سير عمل GitHub Actions (validate-and-release.yml) في الحالات التالية:
- مجدول: يوميًا في الساعة 6 صباحًا بتوقيت UTC
- الدفع إلى main: عند تغيير
scripts/أوconfig/أوpyproject.toml - التشغيل اليدوي: مع خيارات للإصدار الإجباري أو التشغيل التجريبي
يحتوي سير العمل على أربع مهام:
- validate — تنزيل المواصفات، تشغيل التحقق، فحص Spectral، التوفيق، بوابة جودة Spectral
- check-release-needed — مقارنة تجزئات المحتوى لتحديد ما إذا كان الإصدار مطلوبًا
- release — تجميع وإنشاء إصدار GitHub (فقط إذا تغيّر المحتوى)
- update-docs — إعادة إنشاء
01-validation-report.mdxوفتح طلب سحب (PR) إذا تغيّر
تقوم مهمة notify بإنشاء تذكرة (issue) على GitHub إذا فشلت أي مهمة.
سير عمل الفروع وطلبات السحب
Section titled “سير عمل الفروع وطلبات السحب”تتبع جميع التغييرات النمط التالي: تذكرة -> فرع -> طلب سحب -> نجاح CI -> دمج.
- أسماء الفروع:
feature/<issue>-desc،fix/<issue>-desc،docs/<issue>-desc - يجب أن تربط طلبات السحب بتذكرة (
Closes #Nفي الوصف) - فحوصات CI المطلوبة:
Check linked issuesوLint Code Base - يُفضّل الدمج بالضغط (squash merge)؛ تُحذف الفروع تلقائيًا بعد الدمج
راجع CONTRIBUTING.md للاطلاع على قواعد سير العمل الكاملة.