Skip to content

Improve ValidationIssue enum #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 2, 2025
Merged

Improve ValidationIssue enum #74

merged 6 commits into from
Jun 2, 2025

Conversation

ajevans99
Copy link
Owner

Description

This pull request introduces two major updates: the addition of a CustomStringConvertible implementation for the JSONValue type and a significant refactor of the ValidationIssue error cases to include more detailed context in validation errors. These changes improve the clarity and debugging capabilities of the JSON schema validation library.

Enhancements to JSONValue:

  • Added a CustomStringConvertible implementation to the JSONValue type, allowing for a human-readable string representation of JSON values. This includes formatted output for strings, numbers, objects, arrays, booleans, and null values. (Sources/JSONSchema/JSONValue/JSONValue.swift)

Refactor of ValidationIssue:

  • Refactored the ValidationIssue enum to include detailed contextual information for all validation errors. For example:
    • typeMismatch now specifies the expected and actual types.
    • notEnumCase includes the value being validated and the allowed values.
    • Array-related errors like containsInsufficientMatches and containsExcessiveMatches now include counts and thresholds.
    • Object-related errors like exceedsMaxProperties and belowMinProperties now include property counts and limits.
    • Logical and conditional errors (e.g., oneOfFailed, conditionalFailed) now include associated validation errors for better debugging. (Sources/JSONSchema/Validation/Errors/ValidationIssue.swift)

Updates to Validation Logic:

  • Updated all validation methods in Keywords+Assertion.swift and Keywords+Applicator.swift to throw the newly refactored ValidationIssue cases with detailed context. This ensures that all validation errors provide specific information about what failed and why. [1] [2] [3] [4] [5] and others)

Closes #39

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Additional Notes

Add any other context or screenshots about the pull request here.

@ajevans99 ajevans99 requested a review from Copilot April 24, 2025 19:29
@ajevans99 ajevans99 added the auto-format CI will auto-commit swift format label Apr 24, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the JSON schema validation error reporting by introducing detailed context for each error case and adds a human‐readable string representation for JSON values. Key changes include:

  • Updating all ValidationIssue error cases to include detailed associated values.
  • Adjusting validation methods across assertion and applicator keywords to throw enriched errors.
  • Adding a CustomStringConvertible implementation for JSONValue.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Tests/JSONSchemaTests/KeywordTests.swift Updated tests to reflect new, more descriptive error cases.
Sources/JSONSchema/Validation/Errors/ValidationIssue.swift Refactored ValidationIssue enum to include associated values and improved descriptions.
Sources/JSONSchema/Keywords/Keywords+Assertion.swift Adjusted error throwing to use the new error cases with detailed context.
Sources/JSONSchema/Keywords/Keywords+Applicator.swift Updated error throwing in applicator methods with detailed error information.
Sources/JSONSchema/JSONValue/JSONValue.swift Added CustomStringConvertible conformance for more readable string representations.

@ajevans99 ajevans99 marked this pull request as ready for review June 2, 2025 04:15
@ajevans99 ajevans99 merged commit 3749d82 into main Jun 2, 2025
8 checks passed
@ajevans99 ajevans99 deleted the improve-validation-issues branch June 2, 2025 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-format CI will auto-commit swift format
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve ValidationIssue description
2 participants