Skip to content

[CSM Portal][BE] feat: accept type string enum in deployment POST/PATCH endpoints - #957

Merged
cloby99 merged 1 commit into
wso2-open-operations:v2from
Rashmika998:feat/deployment-type-string-enum
Jun 26, 2026
Merged

cloby99 merged 1 commit into
wso2-open-operations:v2from
Rashmika998:feat/deployment-type-string-enum

Conversation

@Rashmika998

@Rashmika998 Rashmika998 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace typeKey: integer with type: string enum in the entity service and CSM portal backend POST /deployments and PATCH /deployments/{id} endpoints
  • The entity service SN service maps the incoming string (e.g. "primary_production") to the Choreo integer choice-list key via a new deploymentTypeToKey map before forwarding — same pattern used by case severity/state fields
  • Valid values: primary_production (6), staging (3), qa (2), stress (4), uat (5), development (1)
  • Added CLAUDE.md guidance: SN payload structs must use the integer key types Choreo expects; add a xxxToKey map to translate domain string enums

Test plan

  • POST /deployments with "type": "primary_production" reaches Choreo with typeKey: 6
  • PATCH /deployments/{id} with "type": "staging" reaches Choreo with typeKey: 3
  • POST /deployments with an invalid type string returns 400
  • CSM portal backend handler tests pass (go test ./...)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Deployment create and update requests now use a readable environment type value instead of a numeric key.
    • Supported deployment types include production, staging, QA, stress, UAT, and development.
  • Bug Fixes

    • Updated deployment request validation so update payloads clearly require one of the allowed detail fields, improving API consistency.
    • Test coverage was adjusted to match the new deployment type format.

…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>
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Deployment request schemas, OpenAPI documents, and ServiceNow handling change the deployment type field from typeKey to string type across portal and entity-service code.

Changes

Deployment type contract migration

Layer / File(s) Summary
Portal deployment contract and test fixture
apps/csm-portal/backend/openapi.yaml, apps/csm-portal/backend/internal/handler/deployments.go, apps/csm-portal/backend/internal/handler/deployments_test.go
The portal OpenAPI payloads and handler comment use type instead of typeKey, and the POST deployment test body now sends the string environment type.
Entity-service request schemas
entity-service/openapi.yaml, entity-service/internal/domain/entity.go
CreateDeploymentRequest and UpdateDeploymentRequest switch their deployment field from TypeKey to typed Type pointers, and the matching OpenAPI schemas require the string enum type.
ServiceNow deployment translation
entity-service/internal/service/sn_deployment_service.go, entity-service/CLAUDE.md
Create and update deployment handling validate req.Type, map it through deploymentTypeToKey, and send the integer TypeKey in ServiceNow payloads; the integration notes add the same field-shape guidance.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • cloby99

Poem

A rabbit hopped through schema snow,
From typeKey tall to type I go.
I tucked each key in burrowed maps,
And thumped through tests with happy taps. 🐇🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description only includes a summary and test plan, missing most required template sections like purpose, goals, approach, release note, and security checks. Fill out the full template, especially Purpose, Goals, Approach, Release note, Documentation, Security checks, and any applicable sections.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately reflects the main change to deployment endpoint type handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Rashmika998 Rashmika998 self-assigned this Jun 26, 2026
@Rashmika998 Rashmika998 added Type/Improvement Marks enhancements or improvements to existing features Area/Backend Entity Service App/CSM Portal labels Jun 26, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
entity-service/CLAUDE.md (1)

178-182: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

New 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 the Key/Keys suffix with TypeKey json:"typeKey" as an example — which contradicts this PR's migration of CreateDeploymentRequest/UpdateDeploymentRequest to Type *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 win

Validate against deploymentTypeToKey to avoid a silent TypeKey: 0 on map drift.

Validity is checked against validDeploymentTypes while the integer is resolved from the separate deploymentTypeToKey map. If a future DeploymentType constant is added to validDeploymentTypes but not to deploymentTypeToKey, the lookup at Line 191 returns the zero value and a TypeKey: 0 is sent to ServiceNow with no error. Consider using deploymentTypeToKey as 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3a98caa and ed9003a.

📒 Files selected for processing (7)
  • apps/csm-portal/backend/internal/handler/deployments.go
  • apps/csm-portal/backend/internal/handler/deployments_test.go
  • apps/csm-portal/backend/openapi.yaml
  • entity-service/CLAUDE.md
  • entity-service/internal/domain/entity.go
  • entity-service/internal/service/sn_deployment_service.go
  • entity-service/openapi.yaml

rksk added a commit to rksk/os-cs-tools that referenced this pull request Jun 26, 2026
…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).
@cloby99
cloby99 merged commit 3d18ddf into wso2-open-operations:v2 Jun 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

App/CSM Portal Area/Backend Entity Service Type/Improvement Marks enhancements or improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants