Skip to content

[Customer Entity] Improve case API response consistency for ServiceNow data source - #934

Merged
Rashmika998 merged 10 commits into
wso2-open-operations:v2from
cloby99:task/entity-service
Jun 24, 2026
Merged

Rashmika998 merged 10 commits into
wso2-open-operations:v2from
cloby99:task/entity-service

Conversation

@cloby99

@cloby99 cloby99 commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Add all cases/search fields to GET /cases/{id} response (CaseView now extends SearchCaseView fields: catalog, catalogItem, assignedTeam, conversation, caseType, engagementType)
  • Rename caseTypetype in both search and detail responses; map SN caseType sysids to domain enum values (case, service_request, etc.)
  • Rename support case type enum to case across migration, validation, and OpenAPI spec
  • Return null instead of empty strings/objects for absent fields: deployedProduct, deployment, product, UserRef sub-fields, CaseView.DeployedProductDetails

Summary by CodeRabbit

  • New Features

    • Case records now support the case type by default, including search and create flows.
    • Case details and search results now expose more optional metadata when available, including type, engagement type, catalog info, assigned team, and conversation links.
  • Bug Fixes

    • Empty values are now omitted or returned as null instead of appearing as blank strings.
    • Case details and search results more consistently hide missing related records.
    • Severity handling now matches the updated case-type behavior.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@cloby99, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 8 minutes and 23 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 29454b7f-6c06-4cfc-861d-8d0b1a3b7c66

📥 Commits

Reviewing files that changed from the base of the PR and between 28bdd73 and 0f5b881.

📒 Files selected for processing (4)
  • entity-service/internal/domain/entity.go
  • entity-service/internal/repository/case_repo.go
  • entity-service/internal/service/sn_case_service.go
  • entity-service/openapi.yaml
📝 Walkthrough

Walkthrough

Renames the case type value from "support" to "case" across the Postgres migration, domain structs, service validation, ServiceNow sysid mapping, and OpenAPI contract. Also expands CaseView and SearchCaseView with additional nullable pointer fields, refactors repository scanning to use intermediate variables, and adds a no-empty-string serialization convention.

Changes

Case type rename and nullable field expansion

Layer / File(s) Summary
DB schema, domain structs, and OpenAPI contracts
entity-service/migrations/000008_create_cases.up.sql, entity-service/internal/domain/entity.go, entity-service/openapi.yaml, entity-service/CLAUDE.md
case_type_enum value, column default, and check constraint renamed from 'support' to 'case'. UserRef gains omitempty on all JSON tags. CaseView adds Type, EngagementType pointer fields and converts DeployedProductDetails, ProductDetails, and four new link refs (Catalog, CatalogItem, AssignedTeam, Conversation) to nullable pointers. SearchCaseView renames caseType to type and makes Deployment/DeployedProduct optional pointers. OpenAPI schemas updated to match new enums, nullable fields, and revised descriptions. CLAUDE.md adds the no-empty-string convention.
ServiceNow case-type mapping and conditional field population
entity-service/internal/service/sn_case_service.go
Removes "support" from snCaseTypeMap, introduces snCaseTypeSysidMap and snCaseTypeToDomain helper (defaults to "case" for nil/unrecognized sysids). Updates CreateCase validation to require "case". In GetCaseByID and SearchCases, DeployedProductDetails, Deployment, and DeployedProduct are now set conditionally only when UUID conversion yields a non-empty value.
Postgres service validation and repository scan refactor
entity-service/internal/service/case_service.go, entity-service/internal/repository/case_repo.go
validCaseType map and CreateCase validation updated to accept "case" instead of "support". GetCaseByID and SearchCases in the repository refactored to scan deployed-product and deployment values into intermediate variables before constructing the nullable pointer fields.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

Type/Improvement, Area/Backend

Suggested reviewers

  • Rashmika998

Poem

🐇 No more "support", it's "case" today,
Empty strings are banned — pointers lead the way!
omitempty guards each nullable ref,
snCaseTypeToDomain defaults with no fuss left.
The rabbit hops forward, the schema aligns — 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only includes a brief Summary and omits most required template sections like Purpose, Goals, Approach, tests, and release note. Fill in the required sections from the template, especially Purpose, Goals, Approach, Release note, Documentation, tests, and Security checks.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: improving case API response consistency for the ServiceNow data source.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

@cloby99

cloby99 commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
entity-service/internal/repository/case_repo.go (1)

120-127: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Populate the new detail type and engagementType fields for Postgres cases.

CaseView now exposes these fields and SearchCases already returns them, but GetCaseByID still doesn’t select c.type / c.engagement_type, so Postgres detail responses serialize them as null. Add the columns to this SELECT/Scan path and assign cv.Type / cv.EngagementType.

Also applies to: 151-165

🤖 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/repository/case_repo.go` around lines 120 - 127,
Populate the new CaseView detail fields in the Postgres GetCaseByID query path.
Update the SELECT built in case_repo.go and the matching Scan/assignment logic
in GetCaseByID to include c.type and c.engagement_type, then assign the values
to cv.Type and cv.EngagementType so detail responses no longer serialize them as
null. Use the existing GetCaseByID, CaseView, and SearchCases patterns as a
guide to keep the row mapping aligned.
🤖 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.

Inline comments:
In `@entity-service/internal/domain/entity.go`:
- Around line 568-571: CaseView still models DeploymentDetails as a non-pointer
value, so missing deployments can serialize as an empty EntityRef instead of
null. Change CaseView.DeploymentDetails to *EntityRef, then update every
CaseView builder/mapper that populates deployment data to set nil when no
deployment exists and only allocate an EntityRef when present. Also align the
generated API/OpenAPI schema and any related response model conversions that
reference CaseView, DeploymentDetails, and EntityRef so deployment is documented
and emitted as nullable.

In `@entity-service/internal/service/sn_case_service.go`:
- Around line 448-461: The optional ServiceNow reference mapping in the SN case
conversion logic should not assign empty-string IDs when the ref object exists
but its source ID is blank. Update the conversion branches in the method that
populates the domain entity refs for ProductDetails, Catalog, CatalogItem,
AssignedTeam, and Conversation to follow the same sysidToUUID(...) != "" guard
used for DeployedProductDetails, so only valid converted UUIDs are serialized
and empty responses stay omitted.
- Around line 339-340: The validation message in the case creation path is
stale: in the req.Type check inside the case creation logic, replace the
misleading typeKey wording with the actual request field name type so API
clients see an accurate error. Update the apierror.ValidationError message in
the case creation method to reference req.Type directly and keep the enum field
naming consistent with other request validations.
- Around line 136-155: Add the missing reverse mapping for the engagement case
type in snCaseTypeSysidMap so snCaseTypeToDomain can return "engagement" instead
of defaulting to "case". Update the mapping table alongside the existing
case_type sysid entries, and ensure the conversion logic in snCaseTypeToDomain
still falls back to "case" only for nil or unrecognized sysids.

---

Outside diff comments:
In `@entity-service/internal/repository/case_repo.go`:
- Around line 120-127: Populate the new CaseView detail fields in the Postgres
GetCaseByID query path. Update the SELECT built in case_repo.go and the matching
Scan/assignment logic in GetCaseByID to include c.type and c.engagement_type,
then assign the values to cv.Type and cv.EngagementType so detail responses no
longer serialize them as null. Use the existing GetCaseByID, CaseView, and
SearchCases patterns as a guide to keep the row mapping aligned.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1bd9dd87-3000-4938-8c82-fa2568c60986

📥 Commits

Reviewing files that changed from the base of the PR and between 17bdb6e and 28bdd73.

📒 Files selected for processing (7)
  • entity-service/CLAUDE.md
  • entity-service/internal/domain/entity.go
  • entity-service/internal/repository/case_repo.go
  • entity-service/internal/service/case_service.go
  • entity-service/internal/service/sn_case_service.go
  • entity-service/migrations/000008_create_cases.up.sql
  • entity-service/openapi.yaml

Comment thread entity-service/internal/domain/entity.go
Comment thread entity-service/internal/service/sn_case_service.go
Comment thread entity-service/internal/service/sn_case_service.go Outdated
Comment thread entity-service/internal/service/sn_case_service.go Outdated
cloby99 and others added 4 commits June 24, 2026 15:05
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…on error

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…onversion

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rashmika998 added a commit to Rashmika998/cs-tools that referenced this pull request Jun 24, 2026
… case type rename and nullable fields

- Rename type enum value support→case in CaseCreatePayload and CaseSearchFilters
- Add type and engagementType nullable fields to CaseView
- Add catalog, catalogItem, assignedTeam, conversation nullable EntityRef fields to CaseView
- Mark deployment, deployedProduct, product as nullable in CaseView
- Add type field and mark deployment, deployedProduct as nullable in CaseSearchView
- Update test payload and docs to use type: "case"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Rashmika998
Rashmika998 merged commit 480e076 into wso2-open-operations:v2 Jun 24, 2026
1 check passed
rksk added a commit to rksk/os-cs-tools that referenced this pull request Jun 24, 2026
…support->case; nullable CaseView refs)

- Rename case type value 'support' -> 'case' across BeCaseType,
  BeCaseCreatePayload (POST /cases), the case-type filter (caseType.ts:
  label 'Support' -> 'Case'), and CsmCaseCreatePage. Matches the entity
  PR wso2-open-operations#934 rename.
- BeCaseView: add nullable type/engagementType and catalog/catalogItem/
  assignedTeam/conversation EntityRefs; mark deployment/deployedProduct
  nullable.
- BeCaseSearchView: add 'type'; mark deployment/deployedProduct nullable.
  Map it onto the row (caseType: c.type).

Pure contract alignment. NOTE: depends on BE PR wso2-open-operations#938 — merge this after
it, or the cases list/create will send the new 'case' value to a BE that
still expects 'support'.
cloby99 pushed a commit that referenced this pull request Jun 24, 2026
…and nullable fields

- Rename type enum value support→case in CaseCreatePayload and CaseSearchFilters
- Add type and engagementType nullable fields to CaseView
- Add catalog, catalogItem, assignedTeam, conversation nullable EntityRef fields to CaseView
- Mark deployment, deployedProduct, product as nullable in CaseView
- Add type field and mark deployment, deployedProduct, product as nullable in CaseSearchView
- Update test payload and docs to use type: "case"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cloby99 added a commit that referenced this pull request Jun 24, 2026
…gnment

[CSM Portal][BE] align with entity service PR #934: case type rename and nullable fields
rksk added a commit to rksk/os-cs-tools that referenced this pull request Jun 24, 2026
…support->case; nullable CaseView refs)

- Rename case type value 'support' -> 'case' across BeCaseType,
  BeCaseCreatePayload (POST /cases), the case-type filter (caseType.ts:
  label 'Support' -> 'Case'), and CsmCaseCreatePage. Matches the entity
  PR wso2-open-operations#934 rename.
- BeCaseView: add nullable type/engagementType and catalog/catalogItem/
  assignedTeam/conversation EntityRefs; mark deployment/deployedProduct
  nullable.
- BeCaseSearchView: add 'type'; mark deployment/deployedProduct nullable.
  Map it onto the row (caseType: c.type).

Pure contract alignment. NOTE: depends on BE PR wso2-open-operations#938 — merge this after
it, or the cases list/create will send the new 'case' value to a BE that
still expects 'support'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants