Skip to content

Comments

Jmv 3997 validate schema from back#333

Open
dgiannico19 wants to merge 3 commits intomasterfrom
JMV-3997-validate-schema-from-back
Open

Jmv 3997 validate schema from back#333
dgiannico19 wants to merge 3 commits intomasterfrom
JMV-3997-validate-schema-from-back

Conversation

@dgiannico19
Copy link
Contributor

@dgiannico19 dgiannico19 commented Feb 20, 2026

Link al ticket

https://janiscommerce.atlassian.net/browse/JMV-3997

Descripción del requerimiento

Alinear el schema de validación de import/export con los cambios en Views, en las entidades de canExport debe ser posible definir la propiedad opcional filters con valor false (no enviar filtros al backend) u objeto con include y/o exclude (arrays de strings) para indicar qué filtros se envían o excluyen

Descripción de la solución

En lib/schemas/common/import-export.js se añadió el schema filtersEntitySchema (oneOf: false u objeto con include y/o exclude, arrays de strings) y se integró como propiedad opcional en el objeto de entidad de export. Las entidades pueden seguir siendo un string o un objeto con name, type, format, fields y, opcionalmente, filters. En tests se agregaron ejemplos en browse.json y browse-countDown.json (y sus expected) con entidades que usan filters: false, filters.include y filters.exclude para validar el schema

Cómo se puede probar?

Ejecutar los tests del validador y comprobar los casos de la tabla.

Caso Resultado esperado Resultado obtenido Observaciones
Schema con entidad canExport sin filters Valida correctamente Pendiente Entidad mínima (solo name u otras props existentes)
Schema con entidad canExport y filters: false Valida correctamente Pendiente No enviar filtros al backend
Schema con entidad canExport y filters.include (array de strings) Valida correctamente Pendiente Ejemplo en browse.json
Schema con entidad canExport y filters.exclude (array de strings) Valida correctamente Pendiente Ejemplo en browse-countDown.json
Schema con entidad canExport y filters con include y exclude Valida correctamente Pendiente Objeto con ambas claves
Schema con filters inválido (ej. string o array) Error de validación Pendiente Caso negativo
Suite de tests existente (browse, browse-countDown) Todos los tests pasan Pendiente Incluye mocks con filters

Changelog

Added - New filters type object

Summary by CodeRabbit

  • New Features
    • Added flexible entity filtering for import/export: entities can be simple names or detailed objects with optional include/exclude field lists, and an explicit "no filters" option.
  • Tests
    • Updated test fixtures to cover entities with no filters, include-only, exclude-only, and combined include/exclude scenarios.

Note

Low Risk
Schema-only change plus test fixture updates; low blast radius aside from potentially rejecting/accepting different canExport payload shapes.

Overview
Extends the lib/schemas/common/import-export.js validation for canExport.entities to allow an optional filters property per export entity, where filters can be false (send no filters) or an object with include and/or exclude string arrays.

Updates the browse and browse-countDown schema fixtures (and expected outputs) to cover the new filters variants (none, false, include-only, exclude-only, and include+exclude).

Written by Cursor Bugbot for commit 7696d54. This will update automatically on new commits. Configure here.

@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2026

📝 Walkthrough

Walkthrough

Adds a filtering-capable entity schema to import-export: introduces filtersEntitySchema, exportEntityObjectSchema, and an entitiesSchema union (string | object). Updates test mock and expected JSON fixtures to include entities demonstrating filters values (false, include, exclude, both).

Changes

Cohort / File(s) Summary
Schema Enhancement
lib/schemas/common/import-export.js
Adds filtersEntitySchema (false or object with include/exclude arrays), exportEntityObjectSchema (object with name, type, format, fields, filters), and entitiesSchema as oneOf string or export entity object.
Test Mocks
tests/mocks/schemas/browse.json, tests/mocks/schemas/browse-countDown.json
Adds sample entities showing filters: false, filters: { exclude: [...] }, and filters: { include: [...], exclude: [...] } to canExport/canCreate arrays.
Test Expectations
tests/mocks/schemas/expected/browse.json, tests/mocks/schemas/expected/browse-countDown.json
Updates expected fixtures to include the new entities and their filters configurations for validation of export/create behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I nibble schemas with joyful paws,
Filters tucked in tiny clause;
False or lists of include and out,
Entities prance and hop about.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and overly generic, using non-descriptive terms that don't clearly convey the changeset's purpose. Replace with a more descriptive title such as 'Add optional filters property to export entity schema' to clearly indicate the main change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description is comprehensive and follows the template structure with all required sections filled: ticket link, requirements, solution, test cases with a detailed validation table, and changelog.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch JMV-3997-validate-schema-from-back

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 and usage tips.

@coderabbitai coderabbitai bot added the enhancement New feature or request label Feb 20, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
lib/schemas/common/import-export.js (1)

12-24: filtersEntitySchema object branch accepts an empty {} — consider adding minProperties: 1.

The object branch has no required fields and no minProperties, so "filters": {} would pass validation despite having no semantic meaning. If the intent is that an object-form filter must specify at least include or exclude, add a constraint.

Additionally, include and exclude arrays lack minItems: 1, unlike entityProp (Line 8). An entity with "filters": { "include": [] } would validate but is likely not meaningful.

♻️ Proposed fix
 const filtersEntitySchema = {
 	oneOf: [
 		{ const: false },
 		{
 			type: 'object',
 			properties: {
-				include: { type: 'array', items: stringType },
-				exclude: { type: 'array', items: stringType }
+				include: { type: 'array', items: stringType, minItems: 1 },
+				exclude: { type: 'array', items: stringType, minItems: 1 }
 			},
-			additionalProperties: false
+			additionalProperties: false,
+			minProperties: 1
 		}
 	]
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/schemas/common/import-export.js` around lines 12 - 24,
filtersEntitySchema's object branch currently allows an empty object and empty
include/exclude arrays; update the object branch in filtersEntitySchema to add
"minProperties: 1" so an object must contain at least one property, and add
"minItems: 1" to both the include and exclude array schemas (matching the
entityProp pattern) so empty arrays are rejected; change these constraints on
the filtersEntitySchema definition (referencing filtersEntitySchema, include,
and exclude) to enforce meaningful filter content.
tests/mocks/schemas/browse.json (1)

14-24: Consider adding a mock entity with both include and exclude in filters.

The PR description mentions validating entities with filters containing both keys, but neither this file nor browse-countDown.json includes an entity with both include and exclude simultaneously. Adding such a case would improve test coverage for the combined scenario.

Example entity to add
       {
         "name": "entityNameWithIncludeExclude",
         "filters": {
           "include": ["status", "name"]
         }
+      },
+      {
+        "name": "entityNameWithBothFilters",
+        "filters": {
+          "include": ["status", "name"],
+          "exclude": ["search"]
+        }
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/mocks/schemas/browse.json` around lines 14 - 24, Test coverage is
missing a mock entity that has both include and exclude in its filters; add a
new JSON entity object (e.g., name "entityNameWithBothIncludeExclude") alongside
"entityNameWithIncludeExclude" and "entityNameWithFilters" with a "filters"
object containing both "include": ["status","name"] and "exclude":
["internalFlag"] so the combined scenario is exercised, and mirror this new
entity in the corresponding browse-countDown mock as well.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/schemas/common/import-export.js`:
- Around line 12-24: filtersEntitySchema's object branch currently allows an
empty object and empty include/exclude arrays; update the object branch in
filtersEntitySchema to add "minProperties: 1" so an object must contain at least
one property, and add "minItems: 1" to both the include and exclude array
schemas (matching the entityProp pattern) so empty arrays are rejected; change
these constraints on the filtersEntitySchema definition (referencing
filtersEntitySchema, include, and exclude) to enforce meaningful filter content.

In `@tests/mocks/schemas/browse.json`:
- Around line 14-24: Test coverage is missing a mock entity that has both
include and exclude in its filters; add a new JSON entity object (e.g., name
"entityNameWithBothIncludeExclude") alongside "entityNameWithIncludeExclude" and
"entityNameWithFilters" with a "filters" object containing both "include":
["status","name"] and "exclude": ["internalFlag"] so the combined scenario is
exercised, and mirror this new entity in the corresponding browse-countDown mock
as well.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on March 12

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
tests/mocks/schemas/browse-countDown.json (1)

23-40: Consider adding a filters.include-only entity to this fixture for symmetric coverage.

The three new entries cover filters: false, exclude-only, and include + exclude. An include-only case (e.g., { "name": "entityIncludeFilters", "filters": { "include": ["status"] } }) is documented as a test case in the PR objectives but is absent from this fixture. Per the AI summary it is present in browse.json — adding it here too would make browse-countDown.json self-contained for the full filters surface.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/mocks/schemas/browse-countDown.json` around lines 23 - 40, Add an
include-only fixture entry to mirror the other filter cases: insert an object
with "name": "entityIncludeFilters" and a "filters" object containing only
"include": ["status"] so the file has symmetric coverage alongside
"entityNoFilters", "entityExcludeFilters", and "entityWithBothIncludeExclude";
ensure the new entry follows the same array/object style as the existing items
and is valid JSON (commas between objects).
lib/schemas/common/import-export.js (1)

40-45: The string branch of entitiesSchema is untested for isExport=true.

entitiesSchema is a union of stringType | exportEntityObjectSchema. The string branch (a bare entity name string as an export entity) is newly introduced by this PR, but all canExport.entities entries in the provided fixtures are objects. The existing canImport string fixtures go through stringType directly (not entitiesSchema), so they don't cover this path. Consider adding at least one plain string entry to a canExport.entities array in a test fixture.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/schemas/common/import-export.js` around lines 40 - 45, entitiesSchema
currently unions stringType and exportEntityObjectSchema but the string branch
isn't tested for export mode; add at least one plain string entry to a
canExport.entities array in the test fixtures so the stringType path is
exercised when isExport=true. Update or add a fixture used by the export tests
(the file that feeds canExport.entities) to include a bare entity name string,
then run the export-related tests to ensure validation passes through
entitiesSchema's string branch; reference entitiesSchema, stringType,
exportEntityObjectSchema, canExport.entities and isExport when locating code and
tests to update.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/schemas/common/import-export.js`:
- Around line 40-45: entitiesSchema currently unions stringType and
exportEntityObjectSchema but the string branch isn't tested for export mode; add
at least one plain string entry to a canExport.entities array in the test
fixtures so the stringType path is exercised when isExport=true. Update or add a
fixture used by the export tests (the file that feeds canExport.entities) to
include a bare entity name string, then run the export-related tests to ensure
validation passes through entitiesSchema's string branch; reference
entitiesSchema, stringType, exportEntityObjectSchema, canExport.entities and
isExport when locating code and tests to update.

In `@tests/mocks/schemas/browse-countDown.json`:
- Around line 23-40: Add an include-only fixture entry to mirror the other
filter cases: insert an object with "name": "entityIncludeFilters" and a
"filters" object containing only "include": ["status"] so the file has symmetric
coverage alongside "entityNoFilters", "entityExcludeFilters", and
"entityWithBothIncludeExclude"; ensure the new entry follows the same
array/object style as the existing items and is valid JSON (commas between
objects).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant