Skip to content
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

Code Editor (Specmatic Error - Line Highlighting) #1474

Merged
merged 10 commits into from
Dec 15, 2024
Merged

Conversation

samyakOO7
Copy link
Collaborator

@samyakOO7 samyakOO7 commented Dec 14, 2024

Code Editor Specmatic Error Line Highlighting

The functionality implemented highlights error lines in a code editor using metadata and JSON paths derived from a Specmatic response.

Functionality:

  1. Parse a JSON document and its associated metadata using jsonSourceMap to map JSON paths to their respective locations (lines and columns).
  2. Iterate through the metadata, match each jsonPath to the corresponding location in the parsed pointers, and highlight the error line in the editor.
  3. Handle cases where the jsonPath does not directly match any key by removing the trailing parts of the path incrementally until a match is found.
    4.Provide a fallback to use value line information if key is not available.

Key Features:

1.Error Highlighting:
The error lines are marked in the editor using editor.markText, with a CSS class (CodeMirror-lint-mark-error) for styling.
A tooltip is added to the highlighted line to display the error description.

2.Fallback for Missing Keys:
If the key location is not found in the pointers, the function falls back to using the value location for highlighting.

3.Dynamic Path Matching:
If the jsonPath does not match any pointer, the function trims the path from the leaf node backward (e.g., /store/location/city → /store/location) until a match is found.

4.Gutter Marker:
Adds a marker in the editor's gutter to visually indicate errors alongside the line numbers.

Optimization and Improvements

  1. Reusable Path Matching:
    A utility function (findObjectByPath) matches paths dynamically, ensuring robustness even with incomplete paths.
  2. Dynamic Path Trimming:
    Implements a strategy to handle missing paths by iteratively trimming the path and retrying.
  3. Support for Key and Value Locations:
    Ensures that both key and value locations are checked for highlighting, covering all possible cases.

@samyakOO7 samyakOO7 requested review from joelrosario, harikrishnan83 and StarKhan6368 and removed request for joelrosario and harikrishnan83 December 14, 2024 06:43
Samy and others added 6 commits December 14, 2024 12:44
* main: (24 commits)
  Refactored StringPattern.matches
  - minor grammatical and spelling changes in tests - adding tests for contradicting length constraints and regex
  Merged latest
  Merged latest
  Specmatic String Pattern Tests Rectified
  Specmatic String Pattern Tests Rectified
  Specmatic String Pattern Tests
  String Pattern Validation Updated
  Removed unwanted arguments
  Changes for String Pattern Csv Source Tests
  Changes for String Pattern throwOnFailure()
  Fixed test cases
  File formatted
  File formatted
  File formatted
  #1417 making test and stub consistent when pattern is defined for String - Removing comments and instead renaming variables for readability - Removing redundant rows in parameterised test for min and max length based String generation - Adding test for regex based generation - Extracting regex generation code to separate method
  Updated Default Example Match Condition To the Top
  Pattern Validation Logic for Minimum Size Regex
  Pattern Validation Logic for Minimum Size Regex
  Cleaned code- Removed Cognitive Complexity
  ...
…e edit

- made all return types non-null to keep it consistent
…essage class

- extracting constants for some of the magic strings
Copy link
Member

@harikrishnan83 harikrishnan83 left a comment

Choose a reason for hiding this comment

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

Please add unit tests for ExampleValidationErrorMessage jsonpath extraction logic

@joelrosario joelrosario merged commit 1794009 into main Dec 15, 2024
2 checks passed
@joelrosario joelrosario deleted the html-GUI-upgrade branch December 15, 2024 06:20
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