Detect duplicate JSON keys in flow files#78
Open
sfc-gh-pvillard wants to merge 1 commit into
Open
Conversation
Resolves #77. Before computing a diff, both flow files are now scanned with a streaming JSON parser that has STRICT_DUPLICATE_DETECTION enabled. If a duplicate key is found the action posts a CAUTION callout in the PR comment with the file path and exact line/column, then exits with code 1 so the PR check is blocked until the file is fixed. - Add validateNoDuplicateKeys() which uses a separate JsonFactory with STRICT_DUPLICATE_DETECTION; re-wraps JsonParseException with the file path for a self-contained error message. - Call it at the start of getDiff() for both pathA (skipped when absent) and pathB. - Catch JsonParseException in executeFlowDiffForOneFlow() and print the CAUTION block; set jsonParseError flag for run() to track. - Track jsonParseError per flow in run() and return RETURN_FAILURE if any parse error occurred. - Tighten the catch for snapshotA from Exception to IOException. - Add test fixture flow_v9_duplicate_key.json and four new tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #77.
Summary
STRICT_DUPLICATE_DETECTIONenabled before any POJO deserialization. A dedicatedvalidateNoDuplicateKeys()method handles this using a separateJsonFactoryso the existing parsing configuration is untouched.[!CAUTION]block is posted with the file path and exact line/column, matching the style of the existing checkstyle violation block.catch (Exception e)for the "no original flow" case is narrowed tocatch (IOException e), so duplicate-key errors in flowA are now reported rather than silently treated as a first-version flow.Example PR comment on detection
Test plan
mvn test)testDuplicateKeyInFlowBThrowsException- getDiff() throws JsonParseException when flowB has a duplicate keytestDuplicateKeyInFlowAThrowsException- getDiff() throws JsonParseException when flowA has a duplicate keytestDuplicateKeyReturnsFailureExitCode- run() returns exit code 1 when a duplicate key is presenttestDuplicateKeyOutputContainsCaution- PR comment output contains the CAUTION callout and the duplicate field name