- หน้าแรก
- F5 XC API Specs
- คู่มือการพัฒนา
คู่มือการพัฒนา
การตั้งค่า
หัวข้อที่มีชื่อว่า “การตั้งค่า”# 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-climake dev-install จะสร้าง virtualenv ในไดเรกทอรี .venv/ และติดตั้งโปรเจกต์พร้อมกับ dev extras (pytest, ruff, mypy)
ตัวแปรสภาพแวดล้อม
หัวข้อที่มีชื่อว่า “ตัวแปรสภาพแวดล้อม”การตรวจสอบ API แบบสด (live) ต้องการ:
export F5XC_API_URL="https://example-tenant.console.ves.volterra.io"export F5XC_API_TOKEN="your-api-token"หากไม่มีตัวแปรเหล่านี้ make validate จะทำงานในโหมด dry-run แทน
การรัน Pipeline
หัวข้อที่มีชื่อว่า “การรัน Pipeline”Pipeline แบบเต็ม
หัวข้อที่มีชื่อว่า “Pipeline แบบเต็ม”make all# Runs: download → validate → spectral-lint → reconcile → spectral-gate → releaseขั้นตอนแต่ละขั้น
หัวข้อที่มีชื่อว่า “ขั้นตอนแต่ละขั้น”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เอกสารประกอบ
หัวข้อที่มีชื่อว่า “เอกสารประกอบ”make docs-generate # Regenerate docs/01-validation-report.mdx from reportsmake docs # Build full documentation sitemake docs-serve # Local dev server with hot reloadการรันการทดสอบ
หัวข้อที่มีชื่อว่า “การรันการทดสอบ”make test # pytest with coveragemake lint # ruff check + format checkmake typecheck # mypy type checkingmake ci-test # All three (used in CI)Pre-commit hooks จะทำงานอัตโนมัติเมื่อ commit หากมีการติดตั้งไว้:
make pre-commit-install # Install git hooksmake pre-commit # Run all hooks manuallyโครงสร้างโปรเจกต์
หัวข้อที่มีชื่อว่า “โครงสร้างโปรเจกต์”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การเพิ่ม Fix Method ใหม่
หัวข้อที่มีชื่อว่า “การเพิ่ม Fix Method ใหม่”การเพิ่ม Spectral auto-fix ใหม่ให้กับ reconciler:
-
เพิ่มกฎ ใน
.spectral.yamlโดยกำหนด severity ตามต้องการ -
เปิดใช้งาน auto-fix ใน
config/validation.yamlภายใต้spectral.auto_fix:spectral:auto_fix:your-new-rule: true -
เพิ่ม fixer method ใน
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 -
ลงทะเบียน ใน dispatcher
_apply_spectral_fix:spectral_fixers = {# ... existing fixers ..."spectral:your-new-rule": self._fix_your_rule,} -
เพิ่มการทดสอบ ที่ครอบคลุม fix method ใหม่
การเพิ่มกฎ Spectral ใหม่
หัวข้อที่มีชื่อว่า “การเพิ่มกฎ Spectral ใหม่”การเพิ่มกฎ Spectral แบบกำหนดเองที่มีฟังก์ชัน JavaScript:
-
สร้างฟังก์ชันในไฟล์
spectral/functions/your-rule.jsโดย export ฟังก์ชัน default ที่รับพารามิเตอร์(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 Pipeline
หัวข้อที่มีชื่อว่า “CI Pipeline”GitHub Actions workflow (validate-and-release.yml) จะทำงานเมื่อ:
- กำหนดเวลา: ทุกวันเวลา 6:00 UTC
- Push ไปยัง main: เมื่อไฟล์ใน
scripts/,config/, หรือpyproject.tomlมีการเปลี่ยนแปลง - เรียกใช้ด้วยตนเอง: พร้อมตัวเลือกสำหรับ forced release หรือ dry-run
Workflow มีทั้งหมดสี่ jobs:
- validate — ดาวน์โหลด specs, รัน validation, Spectral lint, reconcile, Spectral gate
- check-release-needed — เปรียบเทียบ content hashes เพื่อตัดสินใจว่าจำเป็นต้อง release หรือไม่
- release — แพ็กเกจและสร้าง GitHub Release (เฉพาะเมื่อเนื้อหามีการเปลี่ยนแปลง)
- update-docs — สร้าง
01-validation-report.mdxใหม่และเปิด PR หากมีการเปลี่ยนแปลง
Job notify จะสร้าง GitHub issue หาก job ใดล้มเหลว
เวิร์กโฟลว์ Branch และ PR
หัวข้อที่มีชื่อว่า “เวิร์กโฟลว์ Branch และ PR”การเปลี่ยนแปลงทั้งหมดจะดำเนินตาม: Issue -> Branch -> PR -> CI ผ่าน -> Merge
- ชื่อ branch:
feature/<issue>-desc,fix/<issue>-desc,docs/<issue>-desc - PR ต้องลิงก์กับ issue (
Closes #Nในคำอธิบาย) - CI checks ที่จำเป็น:
Check linked issuesและLint Code Base - แนะนำให้ใช้ squash merge; branches จะถูกลบอัตโนมัติหลัง merge
ดู CONTRIBUTING.md สำหรับกฎเวิร์กโฟลว์ทั้งหมด