[CSM Portal][BE] feat: accept type string enum in deployment POST/PATCH endpoints - #957
Conversation
…CH endpoints Replace integer typeKey with string type enum in the entity service and CSM portal backend deployment create/update endpoints. The entity service maps the string (e.g. "primary_production") to the SN integer choice-list key internally via deploymentTypeToKey before forwarding to Choreo, following the same pattern used by case severity and state fields. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughDeployment request schemas, OpenAPI documents, and ServiceNow handling change the deployment type field from ChangesDeployment type contract migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
entity-service/CLAUDE.md (1)
178-182: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNew SN payload guidance is accurate; update the now-contradictory request-enum naming rule.
The added string-enum→integer-key guidance correctly describes
deploymentTypeToKey. However, line 110 of this same file still instructs that request enum fields use theKey/Keyssuffix withTypeKey json:"typeKey"as an example — which contradicts this PR's migration ofCreateDeploymentRequest/UpdateDeploymentRequesttoType *DeploymentType(json:"type"). Since you're already editing this file, consider reconciling line 110 so contributors don't follow the stale convention.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@entity-service/CLAUDE.md` around lines 178 - 182, The new SN payload guidance conflicts with the older request-enum naming rule in CLAUDE.md, so update the contributor guidance to reflect the current `CreateDeploymentRequest` and `UpdateDeploymentRequest` shape instead of the stale `Key`/`Keys` convention. Reconcile the wording around request enum fields near the existing `TypeKey` example so it matches the `Type *DeploymentType` / `json:"type"` pattern, and keep the new `deploymentTypeToKey` guidance as the source of truth for SN payload integer keys.entity-service/internal/service/sn_deployment_service.go (1)
173-191: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winValidate against
deploymentTypeToKeyto avoid a silentTypeKey: 0on map drift.Validity is checked against
validDeploymentTypeswhile the integer is resolved from the separatedeploymentTypeToKeymap. If a futureDeploymentTypeconstant is added tovalidDeploymentTypesbut not todeploymentTypeToKey, the lookup at Line 191 returns the zero value and aTypeKey: 0is sent to ServiceNow with no error. Consider usingdeploymentTypeToKeyas the single source of validity to eliminate the drift risk.♻️ Resolve and validate in one lookup
- if _, ok := validDeploymentTypes[*req.Type]; !ok { - return domain.CreateDeploymentResponse{}, &apierror.ValidationError{Msg: fmt.Sprintf("invalid type %q", *req.Type)} - } + typeKey, ok := deploymentTypeToKey[*req.Type] + if !ok { + return domain.CreateDeploymentResponse{}, &apierror.ValidationError{Msg: fmt.Sprintf("invalid type %q", *req.Type)} + }- TypeKey: deploymentTypeToKey[*req.Type], + TypeKey: typeKey,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@entity-service/internal/service/sn_deployment_service.go` around lines 173 - 191, The deployment type validation in sn_deployment_service.go is split between validDeploymentTypes and deploymentTypeToKey, which can drift and allow a silent zero-value TypeKey. Update the CreateDeployment path to validate and resolve the type in one lookup using deploymentTypeToKey, and return a ValidationError when the requested type is missing from that map. Keep the fix localized around the CreateDeployment logic and the TypeKey assignment so the map remains the single source of truth.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@entity-service/CLAUDE.md`:
- Around line 178-182: The new SN payload guidance conflicts with the older
request-enum naming rule in CLAUDE.md, so update the contributor guidance to
reflect the current `CreateDeploymentRequest` and `UpdateDeploymentRequest`
shape instead of the stale `Key`/`Keys` convention. Reconcile the wording around
request enum fields near the existing `TypeKey` example so it matches the `Type
*DeploymentType` / `json:"type"` pattern, and keep the new `deploymentTypeToKey`
guidance as the source of truth for SN payload integer keys.
In `@entity-service/internal/service/sn_deployment_service.go`:
- Around line 173-191: The deployment type validation in
sn_deployment_service.go is split between validDeploymentTypes and
deploymentTypeToKey, which can drift and allow a silent zero-value TypeKey.
Update the CreateDeployment path to validate and resolve the type in one lookup
using deploymentTypeToKey, and return a ValidationError when the requested type
is missing from that map. Keep the fix localized around the CreateDeployment
logic and the TypeKey assignment so the map remains the single source of truth.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f5219db0-aa03-4548-8cda-8f120428fff8
📒 Files selected for processing (7)
apps/csm-portal/backend/internal/handler/deployments.goapps/csm-portal/backend/internal/handler/deployments_test.goapps/csm-portal/backend/openapi.yamlentity-service/CLAUDE.mdentity-service/internal/domain/entity.goentity-service/internal/service/sn_deployment_service.goentity-service/openapi.yaml
…pen-operations#957 contract) Per PR wso2-open-operations#957 the BE now accepts the string `type` enum (primary_production|staging|qa|stress|uat|development) instead of the old integer typeKey for both POST /deployments and PATCH /deployments/{id}. Type payload changes (types.ts): - BeDeploymentDetailUpdatePayload now includes `type?: BeDeploymentType` and uses a never-based discriminated union so deactivate and detail payloads are mutually exclusive and type-safe (CodeRabbit CR #1). - Add BeDeploymentCreatePayload and BeDeploymentCreateResponse for POST /deployments. EditDeploymentDialog: replace the read-only type chip ("Type changes aren't available yet") with a Select over all 6 BeDeploymentType values. Type is included in change detection and sent in the PATCH payload only when changed. Tests updated accordingly. CreateDeploymentDialog + useCreateDeployment: new dialog (name, type selector, description; projectId locked to context) and mutation hook that POST /deployments and invalidates the project deployment list. "Create deployment" button added to DeploymentsTab. DeploymentsTab: close edit/deactivate dialog before surfacing page-level error alert so the feedback is not hidden behind the modal backdrop (CodeRabbit CR wso2-open-operations#3). CaseMetaBand: cast deploymentCategory to BeDeploymentType when passing to DeploymentDetailsDialog — both unions share identical values; the cast removes the type mismatch without changing runtime behaviour (CodeRabbit CR #2).
Summary
typeKey: integerwithtype: stringenum in the entity service and CSM portal backendPOST /deploymentsandPATCH /deployments/{id}endpoints"primary_production") to the Choreo integer choice-list key via a newdeploymentTypeToKeymap before forwarding — same pattern used by case severity/state fieldsprimary_production(6),staging(3),qa(2),stress(4),uat(5),development(1)xxxToKeymap to translate domain string enumsTest plan
POST /deploymentswith"type": "primary_production"reaches Choreo withtypeKey: 6PATCH /deployments/{id}with"type": "staging"reaches Choreo withtypeKey: 3POST /deploymentswith an invalid type string returns 400go test ./...)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes