Skip to content

feat(data-access): add type-specific data schemas for suggestions [SITES-39183]#1289

Merged
Kanishkavijay39 merged 6 commits intomainfrom
feat/suggestion-data-schemas
Feb 2, 2026
Merged

feat(data-access): add type-specific data schemas for suggestions [SITES-39183]#1289
Kanishkavijay39 merged 6 commits intomainfrom
feat/suggestion-data-schemas

Conversation

@Kanishkavijay39
Copy link
Contributor

@Kanishkavijay39 Kanishkavijay39 commented Jan 27, 2026

Summary

Add type-specific data schemas for suggestion opportunity types to enable validation, flexible projections, and maintainability.

Motivation

Previously, suggestion data structures had no validation or type-specific configurations, making it difficult to:

  • Ensure data consistency across audit workers
  • Return minimal/optimized field sets for API responses
  • Understand what fields each opportunity type supports

Changes

New Features

Data Schemas (suggestion.data-schemas.js)

  • Joi validation schemas for 8 opportunity types: structured-data, color-contrast, a11y-assistive, cwv, alt-text, security-permissions, security-vulnerabilities, form-accessibility
  • Type-specific projection configurations for minimal views
  • Field transformers for optimized API responses

Projection Utilities (suggestion.projection-utils.js)

  • Reusable field transformation functions (filterIssuesOccurrences, filterCwvMetrics, etc.)
  • Conservative fallback projection with 14 URL-only fields for unknown types

Model Enhancements (suggestion.model.js)

  • getProjection(opportunityType, viewName) - Returns projection config
  • validateData(data, opportunityType) - Validates against Joi schema

Testing

adobe/spacecat-api-service#1693

To test with feature branch tarball:
{
"dependencies": {
"@adobe/spacecat-shared-data-access": "https://gist.github.com/Kanishkavijay39/3e10f6de31238e7ed188269f3a1cbd15/raw/adobe-spacecat-shared-data-access-2.96.0.tgz"
}
}

Thanks for contributing!

@Kanishkavijay39 Kanishkavijay39 force-pushed the feat/suggestion-data-schemas branch from 25bbd29 to 94e646f Compare January 27, 2026 11:23
@github-actions
Copy link

This PR will trigger a minor release when merged.

…URL extraction

- Remove extractUrl() method and urlExtraction config (unused in production)
- Reduce FALLBACK_PROJECTION from 25 fields to 14 URL-only fields
- Remove urlExtraction property from all opportunity type schemas
- Update tests to reflect simplified implementation

This change reduces complexity by removing speculative features that were only used in tests, following YAGNI principle and Single Responsibility Principle.
- Resolved conflict in suggestion.model.js
- Kept REJECTED status from main
- Kept all new schema methods and properties from feature branch
- All tests passing
Kanishka and others added 2 commits February 2, 2026 10:51
- Made minimal projection fields required across all opportunity types
- Validated schemas against actual suggestion data for 20+ opportunity types
- Added missing fields discovered through data validation (aiRationale, urlsSuggested, priority, etc.)
- Fixed projection mismatches (removed fields not in requirements, added missing required fields)
- Added comprehensive schemas for: CANONICAL, HEADINGS, HREFLANG, INVALID_OR_MISSING_METADATA,
  SITEMAP, SITEMAP_PRODUCT_COVERAGE, BROKEN_BACKLINKS, BROKEN_INTERNAL_LINKS, REDIRECT_CHAINS,
  PRERENDER, HIGH_ORGANIC_LOW_CTR, LLM_BLOCKED
- Updated JSDoc example to clarify required vs optional field pattern
- Organized schemas into clear sections: validated, needs validation, and to be added
- Fixed linter errors (line length violations)

Follows design principle: fields in minimal projection must be required, others optional.
@Kanishkavijay39 Kanishkavijay39 merged commit 9824b22 into main Feb 2, 2026
7 checks passed
@Kanishkavijay39 Kanishkavijay39 deleted the feat/suggestion-data-schemas branch February 2, 2026 06:48
solaris007 pushed a commit that referenced this pull request Feb 2, 2026
# [@adobe/spacecat-shared-data-access-v2.100.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.99.0...@adobe/spacecat-shared-data-access-v2.100.0) (2026-02-02)

### Features

* **data-access:** add type-specific data schemas for suggestions [SITES-39183] ([#1289](#1289)) ([9824b22](9824b22))
@solaris007
Copy link
Member

🎉 This PR is included in version @adobe/spacecat-shared-data-access-v2.100.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Kanishkavijay39 added a commit to adobe/spacecat-api-service that referenced this pull request Feb 5, 2026
## Summary

Adds field projection via a `view` query parameter and optional status
filtering to the Suggestions API endpoints. This allows clients to
request lighter payloads optimized for specific UI needs (e.g.,
selection lists, table displays).

Implements API projection for suggestions with a schema-driven
architecture.
This PR integrates with spacecat-shared PR-1289 which provides
type-specific data schemas, validation, and projection logic.
adobe/spacecat-shared#1289

## Changes

### `view` parameter
Pre-defined projections for all GET suggestion endpoints:

| View | Returns | Use Case |
|------|---------|----------|
| `minimal` | `id`, `status`, URL-related `data` fields | Lightest
payload for selection lists |
| `summary` | Minimal + `opportunityId`, `type`, `rank`, `url`,
timestamps | Table displays without heavy data |
| `full` | All fields including `data` and `kpiDeltas` | Default,
backward compatible |

### `status` parameter
Filter suggestions by status (non-paginated endpoint only):

- Single status: `?status=NEW`
- Multiple statuses: `?status=NEW,APPROVED,IN_PROGRESS`
- Valid values: `NEW`, `APPROVED`, `SKIPPED`, `FIXED`, `ERROR`,
`IN_PROGRESS`, `OUTDATED`, `PENDING_VALIDATION`
- Returns `400 Bad Request` for invalid status values

> **Note:** Status filtering excluded from paginated endpoints to avoid
pagination inconsistencies. Use `/by-status/{status}/paged` for
paginated status-filtered results.

## Example Usage

### Minimal view for selection list
GET /sites/{siteId}/opportunities/{opptyId}/suggestions?view=minimal

### Summary view with status filter  
GET
/sites/{siteId}/opportunities/{opptyId}/suggestions?view=summary&status=NEW,FIXED

### Full view (default)
GET /sites/{siteId}/opportunities/{opptyId}/suggestions

---------

Co-authored-by: Kanishka <kanishka@adobe.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants