feat: add validate command for API7 EE backend#432
Conversation
Add a new 'validate' subcommand that validates local ADC configuration against the server-side /apisix/admin/configs/validate API. This performs comprehensive server-side validation (JSON Schema, plugin check_schema, duplicate ID detection) as a dry-run without persisting any changes. Changes: - SDK: Add BackendValidateResult, BackendValidationError interfaces and optional validate()/supportValidate() methods to Backend interface - backend-api7: Implement Validator class that transforms ADC hierarchical configuration to flat backend-native format and POSTs to validate endpoint - backend-api7: Add supportValidate() with version gating (>= 3.9.10) - CLI: Add ValidateTask with version checking and error formatting - CLI: Add validate command with -f, --no-lint options - E2E: Add validate test suite with valid/invalid/multi-error/dry-run cases APISIX and standalone backend support will follow in a separate PR.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds backend validation end-to-end: new CLI Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI Command
participant Task as Validate Task
participant Backend as BackendAPI7
participant Validator as Validator Class
participant API as APISIX Admin API
CLI->>Task: run validate with options
Task->>Backend: supportValidate()
Backend->>Backend: version() & semver check
Backend-->>Task: support true/false
alt supported
Task->>Backend: validate(config)
Backend->>Validator: new Validator(...).validate(config)
Validator->>API: POST /apisix/admin/configs/validate
alt 200 OK
API-->>Validator: 200 {…}
Validator-->>Backend: { success: true, errors: [] }
else 400 Bad Request
API-->>Validator: 400 { error_msg, errors }
Validator-->>Backend: { success: false, errorMessage, errors }
end
Backend-->>Task: BackendValidateResult
Task->>Task: format errors & throw if !success
else not supported
Task-->>Task: throw unsupported error
end
Task-->>CLI: return success or exit with error
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
libs/backend-api7/e2e/validate.e2e-spec.ts (1)
10-13: Unused imports:syncEvents,createEvent,deleteEvent.These utilities are imported but not used in any test case.
♻️ Proposed fix
import { conditionalDescribe, generateHTTPSAgent, semverCondition, - syncEvents, - createEvent, - deleteEvent, } from './support/utils';🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libs/backend-api7/e2e/validate.e2e-spec.ts` around lines 10 - 13, The import list includes unused symbols syncEvents, createEvent, and deleteEvent; remove these three identifiers from the import statement (or, if they were intended to be used, add the appropriate test cases that call syncEvents, createEvent, and deleteEvent) so the test file no longer contains unused imports—update the import line where syncEvents, createEvent, deleteEvent are listed to only import the utilities actually used.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@libs/backend-api7/src/validator.ts`:
- Around line 113-118: The current mapping for config.ssls computes sslId as
ssl.id ?? ADCSDK.utils.generateId(ssl.snis?.[0] ?? '') which will call
generateId('') when snis is undefined or an empty array; change the logic in the
block that builds body.ssls (the map that sets sslId and calls
fromADC.transformSSL) to explicitly detect missing/empty ssl.snis and handle it
safely: either require/validate presence of snis (log a warning and skip or
throw), or derive a non-empty id using a safer seed (e.g., use a random/unique
value or serialize the ssl object) instead of ''. Ensure you reference
config.ssls, ssl.snis, ADCSDK.utils.generateId, sslId and fromADC.transformSSL
when making the change so no empty-string seed is passed to generateId.
---
Nitpick comments:
In `@libs/backend-api7/e2e/validate.e2e-spec.ts`:
- Around line 10-13: The import list includes unused symbols syncEvents,
createEvent, and deleteEvent; remove these three identifiers from the import
statement (or, if they were intended to be used, add the appropriate test cases
that call syncEvents, createEvent, and deleteEvent) so the test file no longer
contains unused imports—update the import line where syncEvents, createEvent,
deleteEvent are listed to only import the utilities actually used.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ccc2e6a2-01a4-4230-8913-b42d44c6bdbe
📒 Files selected for processing (8)
apps/cli/src/command/index.tsapps/cli/src/command/validate.command.tsapps/cli/src/tasks/index.tsapps/cli/src/tasks/validate.tslibs/backend-api7/e2e/validate.e2e-spec.tslibs/backend-api7/src/index.tslibs/backend-api7/src/validator.tslibs/sdk/src/backend/index.ts
What
Add a
validatesubcommand that validates local ADC configuration against the server-side/apisix/admin/configs/validateAPI provided by API7 EE Dashboard. This performs comprehensive server-side validation (JSON Schema, plugin check_schema, duplicate ID detection) as a dry-run — nothing is persisted.Why
The existing
lintcommand only checks ADC's own Zod schema. It can't catch issues like invalid plugin configs, schema violations defined by the backend, or duplicate resource IDs. The validate API fills this gap by running the same validation that would happen during a real sync, without any side effects.Changes
SDK (
libs/sdk/src/backend/index.ts)BackendValidateResultandBackendValidationErrorinterfacesvalidate()andsupportValidate()methods toBackendinterfacebackend-api7 (
libs/backend-api7/src/)Validatorclass that transforms ADC hierarchical configuration to flat backend-native format and POSTs to the validate endpointsupportValidate()with version gating (>= 3.9.10)validate()method onBackendAPI7CLI (
apps/cli/src/)ValidateTaskwith version checking and user-friendly error formattingvalidatecommand:adc validate -f adc.yaml [--no-lint] [--backend api7ee]E2E Tests (
libs/backend-api7/e2e/validate.e2e-spec.ts)conditionalDescribe(semverCondition(gte, '3.9.10'))Usage
Scope
This PR covers API7 EE backend only. APISIX and standalone backend support will follow in a separate PR.
Summary by CodeRabbit
New Features
Tests