Skip to content

Fix #226 allow arrays of literals as property values#231

Merged
Pfeil merged 5 commits intomainfrom
fix-#226-allow-arrays-of-literals-as-property-values
Mar 14, 2025
Merged

Fix #226 allow arrays of literals as property values#231
Pfeil merged 5 commits intomainfrom
fix-#226-allow-arrays-of-literals-as-property-values

Conversation

@Pfeil
Copy link
Member

@Pfeil Pfeil commented Mar 14, 2025

Fixes #226

Summary by CodeRabbit

  • New Features

    • Updated data validation to support a broader range of data types and enforce essential identifier properties, offering enhanced flexibility and improved data consistency.
  • Tests

    • Expanded test coverage by introducing validations for mixed and nested array structures, ensuring more robust handling of complex data scenarios and bolstering overall system reliability.
  • Documentation

    • Improved clarity and detail in method documentation for property addition, enhancing user understanding without altering functionality.

These improvements contribute to a more resilient and flexible experience while maintaining stringent data validation standards.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2025

Walkthrough

The JSON schema has been updated to accept additional data types for array items and enforce the presence of the @id property. Specifically, new types (number, boolean, null) are added alongside string types, and type declarations for certain properties have been changed to array forms. In parallel, the test suite for DataEntity has been enhanced. This includes improved exception handling and safer type assertions using Path objects, as well as the addition of new tests to validate both mixed array properties and the rejection of nested arrays, with a dedicated provider for invalid test cases.

Changes

File(s) Change Summary
src/main/.../entity_field_structure_schema.json Expanded schema definition: added number, boolean, and null to items.anyOf; updated $defs.idProperty type to array; modified @id type to array and marked it as required.
src/test/.../DataEntityTest.java Updated test methods for clarity and type-safety; added new tests for mixed array properties and nested array validations; introduced a provider method supplying invalid array structures for parameterized tests.
src/main/.../AbstractEntity.java Enhanced documentation for overloaded addProperty methods, clarifying functionality and parameter descriptions without altering functionality.

Poem

I'm a little rabbit, hopping through the code,
Updating schemas and tests on a busy, bouncy road.
Arrays can now mingle numbers, booleans, and null with cheer,
And '@id' stands required, shining bright and clear.
With each test that passes, my whiskers twitch with delight,
Coding adventures make my heart hop day and night!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4ea18c and c506c5f.

📒 Files selected for processing (1)
  • src/test/java/edu/kit/datamanager/ro_crate/entities/data/DataEntityTest.java (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (java)
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: build (windows-latest, 17)
🔇 Additional comments (10)
src/test/java/edu/kit/datamanager/ro_crate/entities/data/DataEntityTest.java (10)

3-5: Well-structured imports for JSON handling

These new imports for JsonNode and ArrayNode from the Jackson library are properly added to support the new array functionality tests. The imports are organized logically with the rest of the Jackson-related imports.


17-22: Appropriate imports for new functionality

The addition of Path import is consistent with the improved type safety in the testPathCheck method. The Stream import is needed for the new parameterized test provider method. All imports are well-organized and grouped logically.


24-25: Proper setup for parameterized testing

Adding imports for ParameterizedTest and MethodSource is appropriate for the new test case testing invalid property values with multiple scenarios.


102-109: Improved code formatting for exception test

The reformatted exception test is now more readable with proper indentation. The functionality remains unchanged, but the improved formatting makes the code easier to maintain.


125-140: Enhanced type safety with Path objects

Using Path objects instead of string literals for file paths improves type safety and makes the code more robust. The assertions have been updated to directly compare expected values with actual values, improving readability and error reporting.


169-178: More precise assertions

Replacing assertTrue with assertEquals provides more specific error messages on test failures, making debugging easier. This is a good practice for test maintenance.


193-198: Clearer property count verification

The updated assertions provide a clearer expectation of the property count after operations, making the test's intent more explicit.


200-218: Comprehensive test for mixed array properties

This new test effectively validates the core functionality being added in this PR - supporting arrays with mixed types of literals. The test creates an array with various data types (integers, strings, floats, booleans, nulls) and verifies they're correctly preserved in the DataEntity.

The test is well-structured and includes a variety of data types that could appear in RO-Crate metadata.


220-228: Robust validation of nested array rejection

Using parameterized testing is an excellent approach for testing multiple invalid cases. This test verifies that nested arrays (arrays containing other arrays or objects) are properly rejected, which is important for maintaining RO-Crate compatibility.


230-238: Well-implemented test data provider

The provider method creates two types of invalid array structures for testing: arrays containing sub-arrays and arrays containing objects. This approach ensures robust testing of the validation logic.

The Stream.of() approach is an elegant way to provide multiple test cases to the parameterized test.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/test/java/edu/kit/datamanager/ro_crate/entities/data/DataEntityTest.java (2)

200-219: Remove debug logging statement

There's an unnecessary System.out.println statement that should be removed.

-        System.out.println(entity.getProperty(propertyName));
         assertEquals(propertyValue, entity.getProperty(propertyName));

221-230: Remove debug logging statement

There's an unnecessary System.out.println statement that should be removed.

-        System.out.println(entity.getProperty(propertyName));
         assertNull(entity.getProperty(propertyName));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16bfa42 and 50ff4c3.

📒 Files selected for processing (2)
  • src/main/resources/json_schemas/entity_field_structure_schema.json (2 hunks)
  • src/test/java/edu/kit/datamanager/ro_crate/entities/data/DataEntityTest.java (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build (macos-latest, 17)
  • GitHub Check: build (ubuntu-latest, 21)
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: Analyze (java)
🔇 Additional comments (8)
src/main/resources/json_schemas/entity_field_structure_schema.json (2)

10-13: Enhanced schema flexibility with additional array item types

The schema now allows numbers, booleans, and null values in arrays, not just strings. This properly addresses the issue described in the PR to allow arrays of literals as property values.


36-42: Improved type declarations and added required property constraint

Good changes:

  1. Using array notation for type declarations ("type": ["object"] and "type": ["string"]) follows best practices in JSON Schema and allows for future extension
  2. Adding "required": ["@id"] enforces that all objects must have an @id property, which is essential for RO-Crate entities

These changes improve schema validation while maintaining backward compatibility.

src/test/java/edu/kit/datamanager/ro_crate/entities/data/DataEntityTest.java (6)

3-6: Added appropriate imports for new functionality

The imports for JsonNode, ArrayNode, Path, and JUnit parameterized test support are necessary for the new test methods.

Also applies to: 17-18, 21-25


102-109: Improved exception handling format

The reformatted exception handling is more readable and consistent with modern Java style.


128-140: Enhanced type safety using Path objects

Using Path objects instead of string literals for file paths improves type safety and makes the test more robust.


200-219: Comprehensive test for mixed array properties

This test validates that arrays can contain different primitive types (integer, string, decimal, boolean, null) as specified in the updated schema. It properly checks that the DataEntity class correctly maintains the mixed array structure.


221-230: Well-structured parameterized test for invalid array properties

Good approach using a parameterized test to validate that nested arrays are rejected. This ensures the implementation properly handles invalid structures according to the schema.


232-240: Comprehensive test cases for invalid property values

The test data provider creates two types of invalid array structures (arrays containing sub-arrays and arrays containing sub-objects) to validate schema enforcement. This is a thorough approach to ensure the implementation correctly rejects invalid structures.

Comment on lines +211 to +214
* This is the most generic way to add a property. The value is a
* JsonNode that could contain anything possible. It is limited to
* objects allowed to flattened documents, which means any literal,
* an array of literals, or an object with an @id property.
Copy link
Contributor

Choose a reason for hiding this comment

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

As I mentioned in #230 and I guess it would require significant changes but would it make sense to:

Anyway, thank you for the work, it looks good to me!

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your review :)

As the bug hinders certain use cases, I wanted to do a quick release with a fix for #226 before looking into larger refactorings. I agree this should be looked into at some point. But for the quick releases, I'd like to fix it with the current approaches.

If I remember correctly, we have a JSON schema that validates the crate at some point in the end, and I agree to use something like this, and probably it is already in place (not sure if optional).

@Pfeil Pfeil merged commit ea55aca into main Mar 14, 2025
9 checks passed
@coveralls
Copy link

coveralls commented Mar 14, 2025

Pull Request Test Coverage Report for Build #302

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 90.688%

Totals Coverage Status
Change from base Build #273: 0.0%
Covered Lines: 1607
Relevant Lines: 1772

💛 - Coveralls

@Pfeil Pfeil deleted the fix-#226-allow-arrays-of-literals-as-property-values branch May 27, 2025 11:24
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.

Array of literals are valid/flat json-ld

3 participants