From 40bcb8b34c5e8b1955dde30afa0fdb9b26b29be2 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 17 Apr 2024 22:37:32 +0530 Subject: [PATCH 01/30] Corrected replaced unevaluated with additoinalProperties --- tests/draft-next/additionalProperties.json | 2 +- tests/draft2019-09/additionalProperties.json | 2 +- tests/draft2020-12/additionalProperties.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/draft-next/additionalProperties.json b/tests/draft-next/additionalProperties.json index 606635e4..25cf95d2 100644 --- a/tests/draft-next/additionalProperties.json +++ b/tests/draft-next/additionalProperties.json @@ -171,7 +171,7 @@ "valid": true }, { - "description": "Valid against propertyNames, but not unevaluatedProperties", + "description": "Valid against propertyNames, but not additionalProperties", "data": { "fig": 2, "pear": "available" }, "valid": false } diff --git a/tests/draft2019-09/additionalProperties.json b/tests/draft2019-09/additionalProperties.json index dab3e89b..8dc35f3b 100644 --- a/tests/draft2019-09/additionalProperties.json +++ b/tests/draft2019-09/additionalProperties.json @@ -171,7 +171,7 @@ "valid": true }, { - "description": "Valid against propertyNames, but not unevaluatedProperties", + "description": "Valid against propertyNames, but not additionalProperties", "data": { "fig": 2, "pear": "available" }, "valid": false } diff --git a/tests/draft2020-12/additionalProperties.json b/tests/draft2020-12/additionalProperties.json index d48a498a..b0e9b242 100644 --- a/tests/draft2020-12/additionalProperties.json +++ b/tests/draft2020-12/additionalProperties.json @@ -177,7 +177,7 @@ "valid": true }, { - "description": "Valid against propertyNames, but not unevaluatedProperties", + "description": "Valid against propertyNames, but not additionalProperties", "data": { "fig": 2, "pear": "available" }, "valid": false } From 4eac02c71edfcb29d0803bf0955bdc4c2af5a8ae Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 23 Apr 2024 23:21:38 +0530 Subject: [PATCH 02/30] First workflow --- .github/workflows/annotate_specification.yml | 31 +++++++++++++ .github/workflows/json_tests_workflow.py | 49 ++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 .github/workflows/annotate_specification.yml create mode 100644 .github/workflows/json_tests_workflow.py diff --git a/.github/workflows/annotate_specification.yml b/.github/workflows/annotate_specification.yml new file mode 100644 index 00000000..d54b8c81 --- /dev/null +++ b/.github/workflows/annotate_specification.yml @@ -0,0 +1,31 @@ +name: JSON Tests Workflow + +on: + pull_request: + paths: + - 'tests/**' + +jobs: + run_tests: + name: Run JSON Schema Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install dependencies + run: pip install PyGithub + + - name: Run Python script + run: python json_tests_workflow.py + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REF: ${{ github.ref }} + GITHUB_REPOSITORY: ${{ github.repository }} + \ No newline at end of file diff --git a/.github/workflows/json_tests_workflow.py b/.github/workflows/json_tests_workflow.py new file mode 100644 index 00000000..687e0d41 --- /dev/null +++ b/.github/workflows/json_tests_workflow.py @@ -0,0 +1,49 @@ +from github import Github +import os +import sys + +def commit_and_push_changes(repo, branch, commit_message): + try: + repo.git.add(update=True) + repo.index.commit(commit_message) + origin = repo.remote(name='origin') + origin.push(refspec=branch) + print("Changes committed and pushed successfully.") + except Exception as e: + print(f"Error occurred while committing and pushing changes: {str(e)}") + +def main(): + # GitHub authentication using personal access token + # Replace 'YOUR_PERSONAL_ACCESS_TOKEN' with your actual token + g = Github(os.environ.get('GITHUB_REPOSITORY')) + + # Get repository and pull request number from environment variables + repo_name = os.environ.get('GITHUB_REPOSITORY') + pull_request_number = os.environ.get('GITHUB_REF').split('/')[-1] + + if not repo_name or not pull_request_number: + print("Repository name or pull request number not found in environment variables.") + sys.exit(1) + + # Get repository object + repo = g.get_repo(repo_name) + + # Get the pull request object + pr = repo.get_pull(int(pull_request_number)) + + # Get the list of changed files in the pull request + changed_files = [file.filename for file in pr.get_files()] + + print(changed_files) + # Filter the list to include only JSON files in the 'tests' directory + # changed_json_files = [file for file in changed_files if file.startswith('tests/') and file.endswith('.json')] + + # if changed_json_files: + # # Commit and push changes + # commit_message = "Update JSON files" + # commit_and_push_changes(repo, pr.base.ref, commit_message) + # else: + # print("No changes detected in JSON files.") + +if __name__ == "__main__": + main() From 810d148a772e3c5df44b60dcfa2e64c693a20e22 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 23 Apr 2024 23:24:15 +0530 Subject: [PATCH 03/30] First workflow2 --- .github/workflows/annotate_specification.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/annotate_specification.yml b/.github/workflows/annotate_specification.yml index d54b8c81..32d5fda7 100644 --- a/.github/workflows/annotate_specification.yml +++ b/.github/workflows/annotate_specification.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout Repository + - name: Checkout Repository uses: actions/checkout@v3 - name: Set up Python From 3558c2c62adbf0e3a77815e81ccacea5a536855a Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 23 Apr 2024 23:31:50 +0530 Subject: [PATCH 04/30] Fake add to tests --- tests/draft2020-12/allOf.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/draft2020-12/allOf.json b/tests/draft2020-12/allOf.json index 9e87903f..54bb5080 100644 --- a/tests/draft2020-12/allOf.json +++ b/tests/draft2020-12/allOf.json @@ -3,6 +3,7 @@ "description": "allOf", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", + "specification":[ { "core": "10.2", "quote": "Subschemas of applicator keywords evaluate the instance completely independently such that the results of one such subschema MUST NOT impact the results of sibling subschemas." } ], "allOf": [ { "properties": { From ce52852d02d2e104c97cd24c921222c706091dcc Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 23 Apr 2024 23:41:37 +0530 Subject: [PATCH 05/30] Python file location changed --- json_tests_workflow.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 json_tests_workflow.py diff --git a/json_tests_workflow.py b/json_tests_workflow.py new file mode 100644 index 00000000..687e0d41 --- /dev/null +++ b/json_tests_workflow.py @@ -0,0 +1,49 @@ +from github import Github +import os +import sys + +def commit_and_push_changes(repo, branch, commit_message): + try: + repo.git.add(update=True) + repo.index.commit(commit_message) + origin = repo.remote(name='origin') + origin.push(refspec=branch) + print("Changes committed and pushed successfully.") + except Exception as e: + print(f"Error occurred while committing and pushing changes: {str(e)}") + +def main(): + # GitHub authentication using personal access token + # Replace 'YOUR_PERSONAL_ACCESS_TOKEN' with your actual token + g = Github(os.environ.get('GITHUB_REPOSITORY')) + + # Get repository and pull request number from environment variables + repo_name = os.environ.get('GITHUB_REPOSITORY') + pull_request_number = os.environ.get('GITHUB_REF').split('/')[-1] + + if not repo_name or not pull_request_number: + print("Repository name or pull request number not found in environment variables.") + sys.exit(1) + + # Get repository object + repo = g.get_repo(repo_name) + + # Get the pull request object + pr = repo.get_pull(int(pull_request_number)) + + # Get the list of changed files in the pull request + changed_files = [file.filename for file in pr.get_files()] + + print(changed_files) + # Filter the list to include only JSON files in the 'tests' directory + # changed_json_files = [file for file in changed_files if file.startswith('tests/') and file.endswith('.json')] + + # if changed_json_files: + # # Commit and push changes + # commit_message = "Update JSON files" + # commit_and_push_changes(repo, pr.base.ref, commit_message) + # else: + # print("No changes detected in JSON files.") + +if __name__ == "__main__": + main() From 79dc92f10e934b02815531ba8eb0ce646ac5fd8a Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 23 Apr 2024 23:48:19 +0530 Subject: [PATCH 06/30] TOKEN --- json_tests_workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_tests_workflow.py b/json_tests_workflow.py index 687e0d41..b14d5453 100644 --- a/json_tests_workflow.py +++ b/json_tests_workflow.py @@ -15,7 +15,7 @@ def commit_and_push_changes(repo, branch, commit_message): def main(): # GitHub authentication using personal access token # Replace 'YOUR_PERSONAL_ACCESS_TOKEN' with your actual token - g = Github(os.environ.get('GITHUB_REPOSITORY')) + g = Github(os.environ.get('GITHUB_TOKEN')) # Get repository and pull request number from environment variables repo_name = os.environ.get('GITHUB_REPOSITORY') From cbdd1755eeaed7013c7f1f846c7c63a262232807 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 19:24:29 +0530 Subject: [PATCH 07/30] change day2 --- json_tests_workflow.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/json_tests_workflow.py b/json_tests_workflow.py index b14d5453..5fe9759e 100644 --- a/json_tests_workflow.py +++ b/json_tests_workflow.py @@ -19,7 +19,17 @@ def main(): # Get repository and pull request number from environment variables repo_name = os.environ.get('GITHUB_REPOSITORY') - pull_request_number = os.environ.get('GITHUB_REF').split('/')[-1] + + # Extract pull request number from GITHUB_REF if it's a pull request event + event_name = os.environ.get('GITHUB_EVENT_NAME') + if event_name == 'pull_request': + print(os.environ.get('GITHUB_REF')) + pull_request_number = os.environ.get('GITHUB_REF').split('/')[-2] + print(pull_request_number) + else: + print(os.environ.get('GITHUB_REF')) + print("Not a pull request event.") + sys.exit(1) if not repo_name or not pull_request_number: print("Repository name or pull request number not found in environment variables.") From c6b937cab801c07292c72afc56c5d49fa9d405de Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 20:07:58 +0530 Subject: [PATCH 08/30] Reading all jsons and spec urls added --- .github/workflows/annotate_specification.yml | 2 +- bin/json_tests_workflow.py | 68 ++++++++++++++++++++ bin/specification_urls.json | 33 ++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 bin/json_tests_workflow.py create mode 100644 bin/specification_urls.json diff --git a/.github/workflows/annotate_specification.yml b/.github/workflows/annotate_specification.yml index 32d5fda7..f8f60836 100644 --- a/.github/workflows/annotate_specification.yml +++ b/.github/workflows/annotate_specification.yml @@ -23,7 +23,7 @@ jobs: run: pip install PyGithub - name: Run Python script - run: python json_tests_workflow.py + run: python bin/json_tests_workflow.py env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REF: ${{ github.ref }} diff --git a/bin/json_tests_workflow.py b/bin/json_tests_workflow.py new file mode 100644 index 00000000..e4ff6da5 --- /dev/null +++ b/bin/json_tests_workflow.py @@ -0,0 +1,68 @@ +from github import Github +import os +import sys +import json + +def commit_and_push_changes(repo, branch, commit_message): + try: + repo.git.add(update=True) + repo.index.commit(commit_message) + origin = repo.remote(name='origin') + origin.push(refspec=branch) + print("Changes committed and pushed successfully.") + except Exception as e: + print(f"Error occurred while committing and pushing changes: {str(e)}") + +def main(): + + # Get GITHUB_TOKEN from environment variables automatically + g = Github(os.environ.get('GITHUB_TOKEN')) + + # Get repository and pull request number from environment variables + repo_name = os.environ.get('GITHUB_REPOSITORY') + + # Extract pull request number from GITHUB_REF if it's a pull request event + event_name = os.environ.get('GITHUB_EVENT_NAME') + if event_name == 'pull_request': + pull_request_number = os.environ.get('GITHUB_REF').split('/')[-2] + else: + print("Not a pull request event.") + sys.exit(1) + + if not repo_name or not pull_request_number: + print("Repository name or pull request number not found in environment variables.") + sys.exit(1) + + # Get repository object + repo = g.get_repo(repo_name) + + # Get the pull request object + pr = repo.get_pull(int(pull_request_number)) + + # Get the list of changed files in the pull request + changed_files = [file.filename for file in pr.get_files()] + + print(changed_files) + # Traverse each file in the 'tests' folder and print JSON content + for file in changed_files: + if file.startswith('tests/'): + # Read the file content + draft = file.split('/')[1] + + urls = json.loads(repo.get_contents("specification_urls.json").decoded_content.decode('utf-8')) + + changed_file_content = repo.get_contents(file).decoded_content.decode('utf-8') + # Parse JSON content + try: + json_content = json.loads(changed_file_content) + for test in json_content: + if "specification" in test: + for spec, section in test["specification"]: + if spec in ["core", "validation", "hyper-schema"]: + print(urls[draft][spec] + section) + else: print(urls[spec] + section) + except json.JSONDecodeError as e: + print(f"Error parsing JSON in file '{file}': {e}") + +if __name__ == "__main__": + main() diff --git a/bin/specification_urls.json b/bin/specification_urls.json new file mode 100644 index 00000000..f3a16359 --- /dev/null +++ b/bin/specification_urls.json @@ -0,0 +1,33 @@ +{ + "draft3": { + "core": "https://json-schema.org/draft-03/draft-zyp-json-schema-03.pdf" + }, + "draft4": { + "core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04", + "validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00" + }, + "draft6": { + "core": "https://json-schema.org/draft-06/draft-wright-json-schema-01", + "validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01", + "hyper-schema": "https://json-schema.org/draft-06/draft-wright-json-schema-hyperschema-01" + }, + "draft7": { + "core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01", + "validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01", + "hyper-schema": "https://json-schema.org/draft-07/draft-handrews-json-schema-hyperschema-01" + }, + "draft2019-09": { + "core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02", + "validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02", + "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02" + }, + "draft2020-12": { + "core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01", + "validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01", + "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02" + }, + "rfc": "", + "ecma262": "", + "iso": "", + "perl5": "" +} \ No newline at end of file From df3bdeccc13a165a4cc01fbd3b5443c3dff04cca Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 20:12:39 +0530 Subject: [PATCH 09/30] path corrected --- bin/json_tests_workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/json_tests_workflow.py b/bin/json_tests_workflow.py index e4ff6da5..e4e54c3c 100644 --- a/bin/json_tests_workflow.py +++ b/bin/json_tests_workflow.py @@ -49,7 +49,7 @@ def main(): # Read the file content draft = file.split('/')[1] - urls = json.loads(repo.get_contents("specification_urls.json").decoded_content.decode('utf-8')) + urls = json.loads(repo.get_contents("bin/specification_urls.json").decoded_content.decode('utf-8')) changed_file_content = repo.get_contents(file).decoded_content.decode('utf-8') # Parse JSON content From 582e12be10870f9c54a55fdc562684d6a6ef0f69 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 20:18:26 +0530 Subject: [PATCH 10/30] logging logs check --- bin/json_tests_workflow.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/json_tests_workflow.py b/bin/json_tests_workflow.py index e4e54c3c..b9cf3a82 100644 --- a/bin/json_tests_workflow.py +++ b/bin/json_tests_workflow.py @@ -42,13 +42,14 @@ def main(): # Get the list of changed files in the pull request changed_files = [file.filename for file in pr.get_files()] - print(changed_files) # Traverse each file in the 'tests' folder and print JSON content for file in changed_files: + print(file) if file.startswith('tests/'): # Read the file content draft = file.split('/')[1] + print(draft) urls = json.loads(repo.get_contents("bin/specification_urls.json").decoded_content.decode('utf-8')) changed_file_content = repo.get_contents(file).decoded_content.decode('utf-8') @@ -56,6 +57,7 @@ def main(): try: json_content = json.loads(changed_file_content) for test in json_content: + print("hiiii----------------") if "specification" in test: for spec, section in test["specification"]: if spec in ["core", "validation", "hyper-schema"]: From f29d090ac2b8564fc6216408b2fb13426d2fba9f Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 20:28:53 +0530 Subject: [PATCH 11/30] Wrong location sepcification --- bin/json_tests_workflow.py | 6 ++---- tests/draft2020-12/allOf.json | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bin/json_tests_workflow.py b/bin/json_tests_workflow.py index b9cf3a82..e4ff6da5 100644 --- a/bin/json_tests_workflow.py +++ b/bin/json_tests_workflow.py @@ -42,22 +42,20 @@ def main(): # Get the list of changed files in the pull request changed_files = [file.filename for file in pr.get_files()] + print(changed_files) # Traverse each file in the 'tests' folder and print JSON content for file in changed_files: - print(file) if file.startswith('tests/'): # Read the file content draft = file.split('/')[1] - print(draft) - urls = json.loads(repo.get_contents("bin/specification_urls.json").decoded_content.decode('utf-8')) + urls = json.loads(repo.get_contents("specification_urls.json").decoded_content.decode('utf-8')) changed_file_content = repo.get_contents(file).decoded_content.decode('utf-8') # Parse JSON content try: json_content = json.loads(changed_file_content) for test in json_content: - print("hiiii----------------") if "specification" in test: for spec, section in test["specification"]: if spec in ["core", "validation", "hyper-schema"]: diff --git a/tests/draft2020-12/allOf.json b/tests/draft2020-12/allOf.json index 54bb5080..9e87903f 100644 --- a/tests/draft2020-12/allOf.json +++ b/tests/draft2020-12/allOf.json @@ -3,7 +3,6 @@ "description": "allOf", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", - "specification":[ { "core": "10.2", "quote": "Subschemas of applicator keywords evaluate the instance completely independently such that the results of one such subschema MUST NOT impact the results of sibling subschemas." } ], "allOf": [ { "properties": { From 540a269b4e8728b6716db787dd269304ff746b4a Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 20:33:04 +0530 Subject: [PATCH 12/30] Log2 --- bin/json_tests_workflow.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/json_tests_workflow.py b/bin/json_tests_workflow.py index e4ff6da5..576b8fd5 100644 --- a/bin/json_tests_workflow.py +++ b/bin/json_tests_workflow.py @@ -53,11 +53,14 @@ def main(): changed_file_content = repo.get_contents(file).decoded_content.decode('utf-8') # Parse JSON content + print("--------") try: json_content = json.loads(changed_file_content) for test in json_content: + print(test) if "specification" in test: for spec, section in test["specification"]: + print(spec, section) if spec in ["core", "validation", "hyper-schema"]: print(urls[draft][spec] + section) else: print(urls[spec] + section) From eb8fd76081cea78418e31fe8db5fea23515214e7 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 20:45:54 +0530 Subject: [PATCH 13/30] Branch name specified --- bin/json_tests_workflow.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/json_tests_workflow.py b/bin/json_tests_workflow.py index 576b8fd5..18542d0c 100644 --- a/bin/json_tests_workflow.py +++ b/bin/json_tests_workflow.py @@ -51,7 +51,9 @@ def main(): urls = json.loads(repo.get_contents("specification_urls.json").decoded_content.decode('utf-8')) - changed_file_content = repo.get_contents(file).decoded_content.decode('utf-8') + branch_name = pr.head.ref + print(branch_name) + changed_file_content = repo.get_contents(file, ref=branch_name).decoded_content.decode('utf-8') # Parse JSON content print("--------") try: From 77527b6342ba0ae03a8af01daa5c1fe52dd734e3 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 20:53:41 +0530 Subject: [PATCH 14/30] Stupidity corrected --- bin/json_tests_workflow.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/json_tests_workflow.py b/bin/json_tests_workflow.py index 18542d0c..43317677 100644 --- a/bin/json_tests_workflow.py +++ b/bin/json_tests_workflow.py @@ -61,11 +61,12 @@ def main(): for test in json_content: print(test) if "specification" in test: - for spec, section in test["specification"]: - print(spec, section) - if spec in ["core", "validation", "hyper-schema"]: - print(urls[draft][spec] + section) - else: print(urls[spec] + section) + for specification_object in test["specification"]: + for key, value in specification_object.items(): + if key in ["core", "validation", "hyper-schema"]: + print(urls[draft][key] + value) + elif key in ["quote"]: continue + else: print(urls[key] + value) except json.JSONDecodeError as e: print(f"Error parsing JSON in file '{file}': {e}") From 5f050a0715f0cb647bc75bbdb5b98c34b98e799c Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 22:06:14 +0530 Subject: [PATCH 15/30] Final correction1 --- bin/json_tests_workflow.py | 28 +++++++++++----------------- bin/specification_urls.json | 37 +++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/bin/json_tests_workflow.py b/bin/json_tests_workflow.py index 43317677..731020dc 100644 --- a/bin/json_tests_workflow.py +++ b/bin/json_tests_workflow.py @@ -2,16 +2,11 @@ import os import sys import json +import re -def commit_and_push_changes(repo, branch, commit_message): - try: - repo.git.add(update=True) - repo.index.commit(commit_message) - origin = repo.remote(name='origin') - origin.push(refspec=branch) - print("Changes committed and pushed successfully.") - except Exception as e: - print(f"Error occurred while committing and pushing changes: {str(e)}") + +def print_github_action_notice(file_name, message): + print(f"::notice file={file_name}::{message}") def main(): @@ -52,21 +47,20 @@ def main(): urls = json.loads(repo.get_contents("specification_urls.json").decoded_content.decode('utf-8')) branch_name = pr.head.ref - print(branch_name) changed_file_content = repo.get_contents(file, ref=branch_name).decoded_content.decode('utf-8') + # Parse JSON content - print("--------") try: json_content = json.loads(changed_file_content) for test in json_content: - print(test) if "specification" in test: for specification_object in test["specification"]: - for key, value in specification_object.items(): - if key in ["core", "validation", "hyper-schema"]: - print(urls[draft][key] + value) - elif key in ["quote"]: continue - else: print(urls[key] + value) + for spec, section in specification_object.items(): + if spec in ["core", "validation", "hyper-schema"]: print_github_action_notice(file, urls[draft][spec] + section) + elif spec in ["quote"]: continue + elif spec in ["ecma262", "perl5"]: print_github_action_notice(file, urls[spec] + section) + elif re.match("^rfc\\d+$"): print_github_action_notice(file, urls["rfc"] + spec + ".txt#" + section) + else: print_github_action_notice(file, urls["iso"]) except json.JSONDecodeError as e: print(f"Error parsing JSON in file '{file}': {e}") diff --git a/bin/specification_urls.json b/bin/specification_urls.json index f3a16359..4041534a 100644 --- a/bin/specification_urls.json +++ b/bin/specification_urls.json @@ -3,31 +3,32 @@ "core": "https://json-schema.org/draft-03/draft-zyp-json-schema-03.pdf" }, "draft4": { - "core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04", - "validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00" + "core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04#rfc.section.", + "validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.", + "hyper-schema": "https://json-schema.org/draft-04/draft-luff-json-hyper-schema-00#rfc.section." }, "draft6": { - "core": "https://json-schema.org/draft-06/draft-wright-json-schema-01", - "validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01", - "hyper-schema": "https://json-schema.org/draft-06/draft-wright-json-schema-hyperschema-01" + "core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.", + "validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.", + "hyper-schema": "https://json-schema.org/draft-06/draft-wright-json-schema-hyperschema-01#rfc.section." }, "draft7": { - "core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01", - "validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01", - "hyper-schema": "https://json-schema.org/draft-07/draft-handrews-json-schema-hyperschema-01" + "core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.", + "validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.", + "hyper-schema": "https://json-schema.org/draft-07/draft-handrews-json-schema-hyperschema-01#rfc.section." }, "draft2019-09": { - "core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02", - "validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02", - "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02" + "core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.", + "validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.", + "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section." }, "draft2020-12": { - "core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01", - "validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01", - "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02" + "core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-", + "validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-", + "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section." }, - "rfc": "", - "ecma262": "", - "iso": "", - "perl5": "" + "ecma262": "https://262.ecma-international.org/", + "perl5": "https://perldoc.perl.org/perlre#", + "rfc": "https://www.rfc-editor.org/rfc/", + "iso": "https://www.iso.org/obp/ui" } \ No newline at end of file From 96f7683aebc650f5fdf3db875aa4b77cbe6e6a74 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 22:18:06 +0530 Subject: [PATCH 16/30] Final correction2 - file names beautufied --- ...cification.yml => annotation_workflow.yml} | 6 +- .github/workflows/json_tests_workflow.py | 49 --------------- ...sts_workflow.py => annotation_workflow.py} | 0 json_tests_workflow.py | 59 ------------------- 4 files changed, 3 insertions(+), 111 deletions(-) rename .github/workflows/{annotate_specification.yml => annotation_workflow.yml} (82%) delete mode 100644 .github/workflows/json_tests_workflow.py rename bin/{json_tests_workflow.py => annotation_workflow.py} (100%) delete mode 100644 json_tests_workflow.py diff --git a/.github/workflows/annotate_specification.yml b/.github/workflows/annotation_workflow.yml similarity index 82% rename from .github/workflows/annotate_specification.yml rename to .github/workflows/annotation_workflow.yml index f8f60836..d104fa51 100644 --- a/.github/workflows/annotate_specification.yml +++ b/.github/workflows/annotation_workflow.yml @@ -1,4 +1,4 @@ -name: JSON Tests Workflow +name: Specifications Annotation Workflow on: pull_request: @@ -7,7 +7,7 @@ on: jobs: run_tests: - name: Run JSON Schema Tests + name: logging annotations runs-on: ubuntu-latest steps: @@ -23,7 +23,7 @@ jobs: run: pip install PyGithub - name: Run Python script - run: python bin/json_tests_workflow.py + run: python bin/annotation_workflow.py env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REF: ${{ github.ref }} diff --git a/.github/workflows/json_tests_workflow.py b/.github/workflows/json_tests_workflow.py deleted file mode 100644 index 687e0d41..00000000 --- a/.github/workflows/json_tests_workflow.py +++ /dev/null @@ -1,49 +0,0 @@ -from github import Github -import os -import sys - -def commit_and_push_changes(repo, branch, commit_message): - try: - repo.git.add(update=True) - repo.index.commit(commit_message) - origin = repo.remote(name='origin') - origin.push(refspec=branch) - print("Changes committed and pushed successfully.") - except Exception as e: - print(f"Error occurred while committing and pushing changes: {str(e)}") - -def main(): - # GitHub authentication using personal access token - # Replace 'YOUR_PERSONAL_ACCESS_TOKEN' with your actual token - g = Github(os.environ.get('GITHUB_REPOSITORY')) - - # Get repository and pull request number from environment variables - repo_name = os.environ.get('GITHUB_REPOSITORY') - pull_request_number = os.environ.get('GITHUB_REF').split('/')[-1] - - if not repo_name or not pull_request_number: - print("Repository name or pull request number not found in environment variables.") - sys.exit(1) - - # Get repository object - repo = g.get_repo(repo_name) - - # Get the pull request object - pr = repo.get_pull(int(pull_request_number)) - - # Get the list of changed files in the pull request - changed_files = [file.filename for file in pr.get_files()] - - print(changed_files) - # Filter the list to include only JSON files in the 'tests' directory - # changed_json_files = [file for file in changed_files if file.startswith('tests/') and file.endswith('.json')] - - # if changed_json_files: - # # Commit and push changes - # commit_message = "Update JSON files" - # commit_and_push_changes(repo, pr.base.ref, commit_message) - # else: - # print("No changes detected in JSON files.") - -if __name__ == "__main__": - main() diff --git a/bin/json_tests_workflow.py b/bin/annotation_workflow.py similarity index 100% rename from bin/json_tests_workflow.py rename to bin/annotation_workflow.py diff --git a/json_tests_workflow.py b/json_tests_workflow.py deleted file mode 100644 index 5fe9759e..00000000 --- a/json_tests_workflow.py +++ /dev/null @@ -1,59 +0,0 @@ -from github import Github -import os -import sys - -def commit_and_push_changes(repo, branch, commit_message): - try: - repo.git.add(update=True) - repo.index.commit(commit_message) - origin = repo.remote(name='origin') - origin.push(refspec=branch) - print("Changes committed and pushed successfully.") - except Exception as e: - print(f"Error occurred while committing and pushing changes: {str(e)}") - -def main(): - # GitHub authentication using personal access token - # Replace 'YOUR_PERSONAL_ACCESS_TOKEN' with your actual token - g = Github(os.environ.get('GITHUB_TOKEN')) - - # Get repository and pull request number from environment variables - repo_name = os.environ.get('GITHUB_REPOSITORY') - - # Extract pull request number from GITHUB_REF if it's a pull request event - event_name = os.environ.get('GITHUB_EVENT_NAME') - if event_name == 'pull_request': - print(os.environ.get('GITHUB_REF')) - pull_request_number = os.environ.get('GITHUB_REF').split('/')[-2] - print(pull_request_number) - else: - print(os.environ.get('GITHUB_REF')) - print("Not a pull request event.") - sys.exit(1) - - if not repo_name or not pull_request_number: - print("Repository name or pull request number not found in environment variables.") - sys.exit(1) - - # Get repository object - repo = g.get_repo(repo_name) - - # Get the pull request object - pr = repo.get_pull(int(pull_request_number)) - - # Get the list of changed files in the pull request - changed_files = [file.filename for file in pr.get_files()] - - print(changed_files) - # Filter the list to include only JSON files in the 'tests' directory - # changed_json_files = [file for file in changed_files if file.startswith('tests/') and file.endswith('.json')] - - # if changed_json_files: - # # Commit and push changes - # commit_message = "Update JSON files" - # commit_and_push_changes(repo, pr.base.ref, commit_message) - # else: - # print("No changes detected in JSON files.") - -if __name__ == "__main__": - main() From 1c175195f88418915278d7bccbaa7c9e40fae54b Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 24 Apr 2024 22:24:52 +0530 Subject: [PATCH 17/30] regex correction --- bin/annotation_workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/annotation_workflow.py b/bin/annotation_workflow.py index 731020dc..06594c84 100644 --- a/bin/annotation_workflow.py +++ b/bin/annotation_workflow.py @@ -59,7 +59,7 @@ def main(): if spec in ["core", "validation", "hyper-schema"]: print_github_action_notice(file, urls[draft][spec] + section) elif spec in ["quote"]: continue elif spec in ["ecma262", "perl5"]: print_github_action_notice(file, urls[spec] + section) - elif re.match("^rfc\\d+$"): print_github_action_notice(file, urls["rfc"] + spec + ".txt#" + section) + elif re.match("^rfc\\d+$", spec): print_github_action_notice(file, urls["rfc"] + spec + ".txt#" + section) else: print_github_action_notice(file, urls["iso"]) except json.JSONDecodeError as e: print(f"Error parsing JSON in file '{file}': {e}") From 891d0265ab0b3b174a59459b864dc97fe00eac53 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 23 Apr 2024 23:24:15 +0530 Subject: [PATCH 18/30] First workflow2 --- ...cification.yml => annotation_workflow.yml} | 8 +-- .github/workflows/json_tests_workflow.py | 49 ------------- bin/annotation_workflow.py | 68 ++++++++++++++++++ bin/specification_urls.json | 34 +++++++++ tests/draft-next/additionalProperties.json | 68 ++++++++++++++++++ tests/draft-next/dynamicRef.json | 55 +++++++++++++++ tests/draft-next/oneOf.json | 2 +- tests/draft-next/optional/dynamicRef.json | 56 +++++++++++++++ tests/draft-next/unevaluatedProperties.json | 69 +++++++++++++++++++ tests/draft2019-09/additionalProperties.json | 35 +++++++++- tests/draft2019-09/oneOf.json | 2 +- tests/draft2019-09/unevaluatedProperties.json | 33 +++++++++ tests/draft2020-12/additionalProperties.json | 33 +++++++++ tests/draft2020-12/dynamicRef.json | 55 +++++++++++++++ tests/draft2020-12/oneOf.json | 2 +- tests/draft2020-12/optional/dynamicRef.json | 56 +++++++++++++++ tests/draft2020-12/unevaluatedItems.json | 1 - tests/draft2020-12/unevaluatedProperties.json | 33 +++++++++ tests/draft4/oneOf.json | 2 +- tests/draft6/oneOf.json | 2 +- tests/draft7/oneOf.json | 2 +- 21 files changed, 604 insertions(+), 61 deletions(-) rename .github/workflows/{annotate_specification.yml => annotation_workflow.yml} (77%) delete mode 100644 .github/workflows/json_tests_workflow.py create mode 100644 bin/annotation_workflow.py create mode 100644 bin/specification_urls.json create mode 100644 tests/draft-next/optional/dynamicRef.json create mode 100644 tests/draft2020-12/optional/dynamicRef.json diff --git a/.github/workflows/annotate_specification.yml b/.github/workflows/annotation_workflow.yml similarity index 77% rename from .github/workflows/annotate_specification.yml rename to .github/workflows/annotation_workflow.yml index d54b8c81..d104fa51 100644 --- a/.github/workflows/annotate_specification.yml +++ b/.github/workflows/annotation_workflow.yml @@ -1,4 +1,4 @@ -name: JSON Tests Workflow +name: Specifications Annotation Workflow on: pull_request: @@ -7,11 +7,11 @@ on: jobs: run_tests: - name: Run JSON Schema Tests + name: logging annotations runs-on: ubuntu-latest steps: - - name: Checkout Repository + - name: Checkout Repository uses: actions/checkout@v3 - name: Set up Python @@ -23,7 +23,7 @@ jobs: run: pip install PyGithub - name: Run Python script - run: python json_tests_workflow.py + run: python bin/annotation_workflow.py env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REF: ${{ github.ref }} diff --git a/.github/workflows/json_tests_workflow.py b/.github/workflows/json_tests_workflow.py deleted file mode 100644 index 687e0d41..00000000 --- a/.github/workflows/json_tests_workflow.py +++ /dev/null @@ -1,49 +0,0 @@ -from github import Github -import os -import sys - -def commit_and_push_changes(repo, branch, commit_message): - try: - repo.git.add(update=True) - repo.index.commit(commit_message) - origin = repo.remote(name='origin') - origin.push(refspec=branch) - print("Changes committed and pushed successfully.") - except Exception as e: - print(f"Error occurred while committing and pushing changes: {str(e)}") - -def main(): - # GitHub authentication using personal access token - # Replace 'YOUR_PERSONAL_ACCESS_TOKEN' with your actual token - g = Github(os.environ.get('GITHUB_REPOSITORY')) - - # Get repository and pull request number from environment variables - repo_name = os.environ.get('GITHUB_REPOSITORY') - pull_request_number = os.environ.get('GITHUB_REF').split('/')[-1] - - if not repo_name or not pull_request_number: - print("Repository name or pull request number not found in environment variables.") - sys.exit(1) - - # Get repository object - repo = g.get_repo(repo_name) - - # Get the pull request object - pr = repo.get_pull(int(pull_request_number)) - - # Get the list of changed files in the pull request - changed_files = [file.filename for file in pr.get_files()] - - print(changed_files) - # Filter the list to include only JSON files in the 'tests' directory - # changed_json_files = [file for file in changed_files if file.startswith('tests/') and file.endswith('.json')] - - # if changed_json_files: - # # Commit and push changes - # commit_message = "Update JSON files" - # commit_and_push_changes(repo, pr.base.ref, commit_message) - # else: - # print("No changes detected in JSON files.") - -if __name__ == "__main__": - main() diff --git a/bin/annotation_workflow.py b/bin/annotation_workflow.py new file mode 100644 index 00000000..06594c84 --- /dev/null +++ b/bin/annotation_workflow.py @@ -0,0 +1,68 @@ +from github import Github +import os +import sys +import json +import re + + +def print_github_action_notice(file_name, message): + print(f"::notice file={file_name}::{message}") + +def main(): + + # Get GITHUB_TOKEN from environment variables automatically + g = Github(os.environ.get('GITHUB_TOKEN')) + + # Get repository and pull request number from environment variables + repo_name = os.environ.get('GITHUB_REPOSITORY') + + # Extract pull request number from GITHUB_REF if it's a pull request event + event_name = os.environ.get('GITHUB_EVENT_NAME') + if event_name == 'pull_request': + pull_request_number = os.environ.get('GITHUB_REF').split('/')[-2] + else: + print("Not a pull request event.") + sys.exit(1) + + if not repo_name or not pull_request_number: + print("Repository name or pull request number not found in environment variables.") + sys.exit(1) + + # Get repository object + repo = g.get_repo(repo_name) + + # Get the pull request object + pr = repo.get_pull(int(pull_request_number)) + + # Get the list of changed files in the pull request + changed_files = [file.filename for file in pr.get_files()] + + print(changed_files) + # Traverse each file in the 'tests' folder and print JSON content + for file in changed_files: + if file.startswith('tests/'): + # Read the file content + draft = file.split('/')[1] + + urls = json.loads(repo.get_contents("specification_urls.json").decoded_content.decode('utf-8')) + + branch_name = pr.head.ref + changed_file_content = repo.get_contents(file, ref=branch_name).decoded_content.decode('utf-8') + + # Parse JSON content + try: + json_content = json.loads(changed_file_content) + for test in json_content: + if "specification" in test: + for specification_object in test["specification"]: + for spec, section in specification_object.items(): + if spec in ["core", "validation", "hyper-schema"]: print_github_action_notice(file, urls[draft][spec] + section) + elif spec in ["quote"]: continue + elif spec in ["ecma262", "perl5"]: print_github_action_notice(file, urls[spec] + section) + elif re.match("^rfc\\d+$", spec): print_github_action_notice(file, urls["rfc"] + spec + ".txt#" + section) + else: print_github_action_notice(file, urls["iso"]) + except json.JSONDecodeError as e: + print(f"Error parsing JSON in file '{file}': {e}") + +if __name__ == "__main__": + main() diff --git a/bin/specification_urls.json b/bin/specification_urls.json new file mode 100644 index 00000000..4041534a --- /dev/null +++ b/bin/specification_urls.json @@ -0,0 +1,34 @@ +{ + "draft3": { + "core": "https://json-schema.org/draft-03/draft-zyp-json-schema-03.pdf" + }, + "draft4": { + "core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04#rfc.section.", + "validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.", + "hyper-schema": "https://json-schema.org/draft-04/draft-luff-json-hyper-schema-00#rfc.section." + }, + "draft6": { + "core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.", + "validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.", + "hyper-schema": "https://json-schema.org/draft-06/draft-wright-json-schema-hyperschema-01#rfc.section." + }, + "draft7": { + "core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.", + "validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.", + "hyper-schema": "https://json-schema.org/draft-07/draft-handrews-json-schema-hyperschema-01#rfc.section." + }, + "draft2019-09": { + "core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.", + "validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.", + "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section." + }, + "draft2020-12": { + "core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-", + "validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-", + "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section." + }, + "ecma262": "https://262.ecma-international.org/", + "perl5": "https://perldoc.perl.org/perlre#", + "rfc": "https://www.rfc-editor.org/rfc/", + "iso": "https://www.iso.org/obp/ui" +} \ No newline at end of file diff --git a/tests/draft-next/additionalProperties.json b/tests/draft-next/additionalProperties.json index 25cf95d2..51b0edad 100644 --- a/tests/draft-next/additionalProperties.json +++ b/tests/draft-next/additionalProperties.json @@ -176,5 +176,73 @@ "valid": false } ] + }, + { + "description": "propertyDependencies with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties" : {"foo2" : {}}, + "propertyDependencies": { + "foo" : {}, + "foo2": { + "bar": { + "properties": { + "buz": {} + } + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "additionalProperties doesn't consider propertyDependencies properties" , + "data": {"foo": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see buz even when foo2 is present", + "data": {"foo2": "bar", "buz": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see buz", + "data": {"buz": ""}, + "valid": false + } + ] + }, + { + "description": "dependentSchemas with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo": {}, + "foo2": { + "properties": { + "bar": {} + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "additionalProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar even when foo2 is present", + "data": {"foo2": "", "bar": ""}, + "valid": false + } + ] } ] diff --git a/tests/draft-next/dynamicRef.json b/tests/draft-next/dynamicRef.json index 94124fff..30821c5b 100644 --- a/tests/draft-next/dynamicRef.json +++ b/tests/draft-next/dynamicRef.json @@ -642,5 +642,60 @@ "valid": false } ] + }, + { + "description": "$dynamicRef skips over intermediate resources - direct reference", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "tests": [ + { + "description": "integer property passes", + "data": { "bar-item": { "content": 42 } }, + "valid": true + }, + { + "description": "string property fails", + "data": { "bar-item": { "content": "value" } }, + "valid": false + } + ] } ] diff --git a/tests/draft-next/oneOf.json b/tests/draft-next/oneOf.json index e8c07713..840d1579 100644 --- a/tests/draft-next/oneOf.json +++ b/tests/draft-next/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/next/schema", diff --git a/tests/draft-next/optional/dynamicRef.json b/tests/draft-next/optional/dynamicRef.json new file mode 100644 index 00000000..dcace154 --- /dev/null +++ b/tests/draft-next/optional/dynamicRef.json @@ -0,0 +1,56 @@ +[ + { + "description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "bar#/$defs/item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "tests": [ + { + "description": "integer property passes", + "data": { "bar-item": { "content": 42 } }, + "valid": true + }, + { + "description": "string property fails", + "data": { "bar-item": { "content": "value" } }, + "valid": false + } + ] + }] \ No newline at end of file diff --git a/tests/draft-next/unevaluatedProperties.json b/tests/draft-next/unevaluatedProperties.json index d0d53507..13fe6e03 100644 --- a/tests/draft-next/unevaluatedProperties.json +++ b/tests/draft-next/unevaluatedProperties.json @@ -1603,5 +1603,74 @@ "valid": false } ] + }, + { + "description": "propertyDependencies with unevaluatedProperties" , + "schema" : { + "$schema": "https://json-schema.org/draft/next/schema", + "properties" : {"foo2" : {}}, + "propertyDependencies": { + "foo" : {}, + "foo2": { + "bar": { + "properties": { + "buz": {} + } + } + } + }, + "unevaluatedProperties": false + }, + + "tests": [ + { + "description": "unevaluatedProperties doesn't consider propertyDependencies" , + "data": {"foo": "bar"}, + "valid": false + }, + { + "description": "unevaluatedProperties sees buz when foo2 is present", + "data": {"foo2": "bar", "buz": ""}, + "valid": true + }, + { + "description": "unevaluatedProperties doesn't see buz when foo2 is absent", + "data": {"buz": ""}, + "valid": false + } + ] + }, + { + "description": "dependentSchemas with unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/next/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "unevaluatedProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties doesn't see bar when foo2 is absent", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties sees bar when foo2 is present", + "data": {"foo2": "", "bar": ""}, + "valid": true + } + ] } ] diff --git a/tests/draft2019-09/additionalProperties.json b/tests/draft2019-09/additionalProperties.json index 8dc35f3b..73f9b909 100644 --- a/tests/draft2019-09/additionalProperties.json +++ b/tests/draft2019-09/additionalProperties.json @@ -156,7 +156,7 @@ { "description": "additionalProperties with propertyNames", "schema": { - "$schema": "https://json-schema.org/draft/next/schema", + "$schema": "https://json-schema.org/draft/2019-09/schema", "propertyNames": { "maxLength": 5 }, @@ -176,5 +176,38 @@ "valid": false } ] + }, + { + "description": "dependentSchemas with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "additionalProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar even when foo2 is present", + "data": { "foo2": "", "bar": ""}, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/oneOf.json b/tests/draft2019-09/oneOf.json index 9b7a2204..c27d4865 100644 --- a/tests/draft2019-09/oneOf.json +++ b/tests/draft2019-09/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/2019-09/schema", diff --git a/tests/draft2019-09/unevaluatedProperties.json b/tests/draft2019-09/unevaluatedProperties.json index 71c36dfa..e8765112 100644 --- a/tests/draft2019-09/unevaluatedProperties.json +++ b/tests/draft2019-09/unevaluatedProperties.json @@ -1567,5 +1567,38 @@ "valid": false } ] + }, + { + "description": "dependentSchemas with unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "unevaluatedProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties doesn't see bar when foo2 is absent", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties sees bar when foo2 is present", + "data": { "foo2": "", "bar": ""}, + "valid": true + } + ] } ] diff --git a/tests/draft2020-12/additionalProperties.json b/tests/draft2020-12/additionalProperties.json index b0e9b242..9618575e 100644 --- a/tests/draft2020-12/additionalProperties.json +++ b/tests/draft2020-12/additionalProperties.json @@ -182,5 +182,38 @@ "valid": false } ] + }, + { + "description": "dependentSchemas with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar": {} + } + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "additionalProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "additionalProperties can't see bar even when foo2 is present", + "data": {"foo2": "", "bar": ""}, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/dynamicRef.json b/tests/draft2020-12/dynamicRef.json index bff26ad6..ffa211ba 100644 --- a/tests/draft2020-12/dynamicRef.json +++ b/tests/draft2020-12/dynamicRef.json @@ -756,5 +756,60 @@ "valid": false } ] + }, + { + "description": "$dynamicRef skips over intermediate resources - direct reference", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "tests": [ + { + "description": "integer property passes", + "data": { "bar-item": { "content": 42 } }, + "valid": true + }, + { + "description": "string property fails", + "data": { "bar-item": { "content": "value" } }, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/oneOf.json b/tests/draft2020-12/oneOf.json index 416c8e57..7a7c7ffe 100644 --- a/tests/draft2020-12/oneOf.json +++ b/tests/draft2020-12/oneOf.json @@ -220,7 +220,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", diff --git a/tests/draft2020-12/optional/dynamicRef.json b/tests/draft2020-12/optional/dynamicRef.json new file mode 100644 index 00000000..7e63f209 --- /dev/null +++ b/tests/draft2020-12/optional/dynamicRef.json @@ -0,0 +1,56 @@ +[ + { + "description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "bar#/$defs/item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "tests": [ + { + "description": "integer property passes", + "data": { "bar-item": { "content": 42 } }, + "valid": true + }, + { + "description": "string property fails", + "data": { "bar-item": { "content": "value" } }, + "valid": false + } + ] + }] \ No newline at end of file diff --git a/tests/draft2020-12/unevaluatedItems.json b/tests/draft2020-12/unevaluatedItems.json index ee0cb658..f861cefa 100644 --- a/tests/draft2020-12/unevaluatedItems.json +++ b/tests/draft2020-12/unevaluatedItems.json @@ -793,7 +793,6 @@ "data": [ "b" ], "valid": false } - ] } ] diff --git a/tests/draft2020-12/unevaluatedProperties.json b/tests/draft2020-12/unevaluatedProperties.json index b8a2306c..ae29c9eb 100644 --- a/tests/draft2020-12/unevaluatedProperties.json +++ b/tests/draft2020-12/unevaluatedProperties.json @@ -1564,5 +1564,38 @@ "valid": false } ] + }, + { + "description": "dependentSchemas with unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": {"foo2": {}}, + "dependentSchemas": { + "foo" : {}, + "foo2": { + "properties": { + "bar":{} + } + } + }, + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "unevaluatedProperties doesn't consider dependentSchemas", + "data": {"foo": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties doesn't see bar when foo2 is absent", + "data": {"bar": ""}, + "valid": false + }, + { + "description": "unevaluatedProperties sees bar when foo2 is present", + "data": { "foo2": "", "bar": ""}, + "valid": true + } + ] } ] diff --git a/tests/draft4/oneOf.json b/tests/draft4/oneOf.json index fb63b089..2487f0e3 100644 --- a/tests/draft4/oneOf.json +++ b/tests/draft4/oneOf.json @@ -159,7 +159,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/tests/draft6/oneOf.json b/tests/draft6/oneOf.json index eeb7ae86..c30a65c0 100644 --- a/tests/draft6/oneOf.json +++ b/tests/draft6/oneOf.json @@ -203,7 +203,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ diff --git a/tests/draft7/oneOf.json b/tests/draft7/oneOf.json index eeb7ae86..c30a65c0 100644 --- a/tests/draft7/oneOf.json +++ b/tests/draft7/oneOf.json @@ -203,7 +203,7 @@ } ] }, - { + { "description": "oneOf with missing optional property", "schema": { "oneOf": [ From 564e69572b59299effbc9e8271aa4ec6e77e0971 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 30 Apr 2024 11:10:22 +0530 Subject: [PATCH 19/30] Walking through all leaf files --- .github/workflows/annotation_workflow.yml | 8 --- bin/annotation_workflow.py | 81 ++++++++--------------- 2 files changed, 27 insertions(+), 62 deletions(-) diff --git a/.github/workflows/annotation_workflow.yml b/.github/workflows/annotation_workflow.yml index d104fa51..7aa6b6b9 100644 --- a/.github/workflows/annotation_workflow.yml +++ b/.github/workflows/annotation_workflow.yml @@ -19,13 +19,5 @@ jobs: with: python-version: '3.x' - - name: Install dependencies - run: pip install PyGithub - - name: Run Python script run: python bin/annotation_workflow.py - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_REF: ${{ github.ref }} - GITHUB_REPOSITORY: ${{ github.repository }} - \ No newline at end of file diff --git a/bin/annotation_workflow.py b/bin/annotation_workflow.py index 06594c84..16944083 100644 --- a/bin/annotation_workflow.py +++ b/bin/annotation_workflow.py @@ -1,53 +1,23 @@ -from github import Github -import os -import sys import json +from pathlib import Path import re +# Function to print GitHub action notice +def print_github_action_notice(file, url): + print(f"::warning file={file},line=1::Annotation: {url}") -def print_github_action_notice(file_name, message): - print(f"::notice file={file_name}::{message}") +# Read specification URLs from JSON file +with open("specification_urls.json", "r") as f: + urls = json.load(f) -def main(): - - # Get GITHUB_TOKEN from environment variables automatically - g = Github(os.environ.get('GITHUB_TOKEN')) - - # Get repository and pull request number from environment variables - repo_name = os.environ.get('GITHUB_REPOSITORY') - - # Extract pull request number from GITHUB_REF if it's a pull request event - event_name = os.environ.get('GITHUB_EVENT_NAME') - if event_name == 'pull_request': - pull_request_number = os.environ.get('GITHUB_REF').split('/')[-2] - else: - print("Not a pull request event.") - sys.exit(1) - - if not repo_name or not pull_request_number: - print("Repository name or pull request number not found in environment variables.") - sys.exit(1) - - # Get repository object - repo = g.get_repo(repo_name) - - # Get the pull request object - pr = repo.get_pull(int(pull_request_number)) - - # Get the list of changed files in the pull request - changed_files = [file.filename for file in pr.get_files()] - - print(changed_files) - # Traverse each file in the 'tests' folder and print JSON content - for file in changed_files: - if file.startswith('tests/'): +# Iterate through files in tests folder +for root, dirs, files in Path("tests").walk(): + for file in files: + if file.endswith('.json'): # Check if file is JSON + file_path = root / file # Read the file content - draft = file.split('/')[1] - - urls = json.loads(repo.get_contents("specification_urls.json").decoded_content.decode('utf-8')) - - branch_name = pr.head.ref - changed_file_content = repo.get_contents(file, ref=branch_name).decoded_content.decode('utf-8') + with open(file_path, "r") as f: + changed_file_content = f.read() # Parse JSON content try: @@ -56,13 +26,16 @@ def main(): if "specification" in test: for specification_object in test["specification"]: for spec, section in specification_object.items(): - if spec in ["core", "validation", "hyper-schema"]: print_github_action_notice(file, urls[draft][spec] + section) - elif spec in ["quote"]: continue - elif spec in ["ecma262", "perl5"]: print_github_action_notice(file, urls[spec] + section) - elif re.match("^rfc\\d+$", spec): print_github_action_notice(file, urls["rfc"] + spec + ".txt#" + section) - else: print_github_action_notice(file, urls["iso"]) - except json.JSONDecodeError as e: - print(f"Error parsing JSON in file '{file}': {e}") - -if __name__ == "__main__": - main() + draft = root.split('/')[-1] + if spec in ["core", "validation", "hyper-schema"]: + print_github_action_notice(file_path, urls[draft][spec] + section) + elif spec in ["quote"]: + continue + elif spec in ["ecma262", "perl5"]: + print_github_action_notice(file_path, urls[spec] + section) + elif re.match("^rfc\\d+$", spec): + print_github_action_notice(file_path, urls["rfc"] + spec + ".txt#" + section) + else: + print_github_action_notice(file_path, urls["iso"]) + except json.JSONDecodeError: + print(f"Failed to parse JSON content for file: {file_path}") From 7b40efe4b6e28084cc7735bea613457abd2b2d07 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 30 Apr 2024 11:14:35 +0530 Subject: [PATCH 20/30] Base path for neighbouring file? --- bin/annotation_workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/annotation_workflow.py b/bin/annotation_workflow.py index 16944083..8144aced 100644 --- a/bin/annotation_workflow.py +++ b/bin/annotation_workflow.py @@ -7,7 +7,7 @@ def print_github_action_notice(file, url): print(f"::warning file={file},line=1::Annotation: {url}") # Read specification URLs from JSON file -with open("specification_urls.json", "r") as f: +with open("bin/specification_urls.json", "r") as f: urls = json.load(f) # Iterate through files in tests folder From e88a2da62412dd93525f276fadbcc0bbb7ca07c0 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Tue, 30 Apr 2024 11:30:11 +0530 Subject: [PATCH 21/30] Works for all OS --- bin/annotation_workflow.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bin/annotation_workflow.py b/bin/annotation_workflow.py index 8144aced..fa9f84dc 100644 --- a/bin/annotation_workflow.py +++ b/bin/annotation_workflow.py @@ -1,6 +1,7 @@ import json -from pathlib import Path +import os import re +from pathlib import Path # Function to print GitHub action notice def print_github_action_notice(file, url): @@ -10,13 +11,13 @@ def print_github_action_notice(file, url): with open("bin/specification_urls.json", "r") as f: urls = json.load(f) -# Iterate through files in tests folder -for root, dirs, files in Path("tests").walk(): - for file in files: - if file.endswith('.json'): # Check if file is JSON - file_path = root / file +# Iterate through JSON files in tests folder and subdirectories +for root, dirs, files in os.walk("tests"): + for file_name in files: + if file_name.endswith(".json"): + file_path = os.path.join(root, file_name) # Read the file content - with open(file_path, "r") as f: + with open(file_path, 'r', encoding='utf-8') as f: changed_file_content = f.read() # Parse JSON content @@ -26,7 +27,7 @@ def print_github_action_notice(file, url): if "specification" in test: for specification_object in test["specification"]: for spec, section in specification_object.items(): - draft = root.split('/')[-1] + draft = Path(file_path).parent.name if spec in ["core", "validation", "hyper-schema"]: print_github_action_notice(file_path, urls[draft][spec] + section) elif spec in ["quote"]: From 2b1ffb7423dacfd08d6de9250ee76f3b3bfb960a Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 1 May 2024 01:26:38 +0530 Subject: [PATCH 22/30] Best practices followed with optimized code --- ...yml => show_specification_annotations.yml} | 12 +-- bin/annotation_workflow.py | 93 ++++++++++++------- bin/specification_urls.json | 38 ++++---- 3 files changed, 82 insertions(+), 61 deletions(-) rename .github/workflows/{annotation_workflow.yml => show_specification_annotations.yml} (50%) diff --git a/.github/workflows/annotation_workflow.yml b/.github/workflows/show_specification_annotations.yml similarity index 50% rename from .github/workflows/annotation_workflow.yml rename to .github/workflows/show_specification_annotations.yml index 7aa6b6b9..634fa42b 100644 --- a/.github/workflows/annotation_workflow.yml +++ b/.github/workflows/show_specification_annotations.yml @@ -1,4 +1,4 @@ -name: Specifications Annotation Workflow +name: Show Specification Annotations on: pull_request: @@ -6,16 +6,14 @@ on: - 'tests/**' jobs: - run_tests: - name: logging annotations + annotate: runs-on: ubuntu-latest steps: - - name: Checkout Repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v4 + - name: Generate Annotations + uses: actions/setup-python@v5 with: python-version: '3.x' diff --git a/bin/annotation_workflow.py b/bin/annotation_workflow.py index fa9f84dc..438ff525 100644 --- a/bin/annotation_workflow.py +++ b/bin/annotation_workflow.py @@ -1,42 +1,65 @@ import json -import os -import re from pathlib import Path -# Function to print GitHub action notice -def print_github_action_notice(file, url): - print(f"::warning file={file},line=1::Annotation: {url}") +def github_action_notice(file, url, line): + """ + Print GitHub action notice with file path, URL, and line number. -# Read specification URLs from JSON file -with open("bin/specification_urls.json", "r") as f: + Parameters: + file (str): File path. + url (str): URL. + line (int): Line number. + """ + return f"::warning file={file},line={line}::Annotation: {url}" + +def find_test_line_number(test_content, test_name): + """ + Find the line number of a test in the JSON content. + + Parameters: + test_content (str): JSON content. + test_name (str): Test name. + + Returns: + int: Line number of the test. + """ + lines = test_content.split("\n") # Split content into lines + for i, line in enumerate(lines, start=1): # Iterate over lines + if test_name in line: # Check if test name is found in the line + return i # Return the line number if found + return 1 # Return None if test name is not found + +# Specify the path to the JSON file using pathlib.Path +json_file_path = Path("bin/specification_urls.json") + +# Read specification URLs from JSON file using pathlib.Path +with json_file_path.open("r", encoding="utf-8") as f: urls = json.load(f) # Iterate through JSON files in tests folder and subdirectories -for root, dirs, files in os.walk("tests"): - for file_name in files: - if file_name.endswith(".json"): - file_path = os.path.join(root, file_name) - # Read the file content - with open(file_path, 'r', encoding='utf-8') as f: - changed_file_content = f.read() - - # Parse JSON content - try: - json_content = json.loads(changed_file_content) - for test in json_content: - if "specification" in test: - for specification_object in test["specification"]: - for spec, section in specification_object.items(): - draft = Path(file_path).parent.name - if spec in ["core", "validation", "hyper-schema"]: - print_github_action_notice(file_path, urls[draft][spec] + section) - elif spec in ["quote"]: - continue - elif spec in ["ecma262", "perl5"]: - print_github_action_notice(file_path, urls[spec] + section) - elif re.match("^rfc\\d+$", spec): - print_github_action_notice(file_path, urls["rfc"] + spec + ".txt#" + section) - else: - print_github_action_notice(file_path, urls["iso"]) - except json.JSONDecodeError: - print(f"Failed to parse JSON content for file: {file_path}") +for file_path in Path("tests").rglob("*.json"): + # Read the file content using pathlib.Path + with file_path.open('r', encoding='utf-8') as f: + changed_file_content = f.read() + + # Parse JSON content + try: + json_content = json.loads(changed_file_content) + for test in json_content: + if "specification" in test: + line_number = find_test_line_number(changed_file_content, test.get("description") ) + + for specification_object in test["specification"]: + for spec, section in specification_object.items(): + draft = file_path.parent.name + if spec in ["quote"]: + continue + elif spec in ["core", "validation", "hyper-schema"]: + url = urls[draft][spec].format(spec=spec, section=section) + else: + url = urls[spec].format(spec=spec, section=section) + annotation = github_action_notice(file_path, url, line_number) + print(annotation) + + except json.JSONDecodeError: + print(f"::error file={file_path}::Failed to parse JSON content") diff --git a/bin/specification_urls.json b/bin/specification_urls.json index 4041534a..faa60ea9 100644 --- a/bin/specification_urls.json +++ b/bin/specification_urls.json @@ -3,32 +3,32 @@ "core": "https://json-schema.org/draft-03/draft-zyp-json-schema-03.pdf" }, "draft4": { - "core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04#rfc.section.", - "validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.", - "hyper-schema": "https://json-schema.org/draft-04/draft-luff-json-hyper-schema-00#rfc.section." + "core": "https://json-schema.org/draft-04/draft-zyp-json-schema-04#rfc.section.{section}", + "validation": "https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.{section}", + "hyper-schema": "https://json-schema.org/draft-04/draft-luff-json-hyper-schema-00#rfc.section.{section}" }, "draft6": { - "core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.", - "validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.", - "hyper-schema": "https://json-schema.org/draft-06/draft-wright-json-schema-hyperschema-01#rfc.section." + "core": "https://json-schema.org/draft-06/draft-wright-json-schema-01#rfc.section.{section}", + "validation": "https://json-schema.org/draft-06/draft-wright-json-schema-validation-01#rfc.section.{section}", + "hyper-schema": "https://json-schema.org/draft-06/draft-wright-json-schema-hyperschema-01#rfc.section.{section}" }, "draft7": { - "core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.", - "validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.", - "hyper-schema": "https://json-schema.org/draft-07/draft-handrews-json-schema-hyperschema-01#rfc.section." + "core": "https://json-schema.org/draft-07/draft-handrews-json-schema-01#rfc.section.{section}", + "validation": "https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.{section}", + "hyper-schema": "https://json-schema.org/draft-07/draft-handrews-json-schema-hyperschema-01#rfc.section.{section}" }, "draft2019-09": { - "core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.", - "validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.", - "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section." + "core": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#rfc.section.{section}", + "validation": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-validation-02#rfc.section.{section}", + "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section.{section}" }, "draft2020-12": { - "core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-", - "validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-", - "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section." + "core": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-{section}", + "validation": "https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-{section}", + "hyper-schema": "https://json-schema.org/draft/2019-09/draft-handrews-json-schema-hyperschema-02#rfc.section.{section}" }, - "ecma262": "https://262.ecma-international.org/", - "perl5": "https://perldoc.perl.org/perlre#", - "rfc": "https://www.rfc-editor.org/rfc/", + "ecma262": "https://262.ecma-international.org/{section}", + "perl5": "https://perldoc.perl.org/perlre#{section}", + "rfc": "https://www.rfc-editor.org/rfc/{spec}.txt#{section}", "iso": "https://www.iso.org/obp/ui" -} \ No newline at end of file +} From 0b780b2c0d68f7656f012969920daf4d7a4b310d Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 1 May 2024 02:00:15 +0530 Subject: [PATCH 23/30] Corected yaml format --- .github/workflows/show_specification_annotations.yml | 2 +- tests/draft2020-12/additionalProperties.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/show_specification_annotations.yml b/.github/workflows/show_specification_annotations.yml index 634fa42b..a4fd65fd 100644 --- a/.github/workflows/show_specification_annotations.yml +++ b/.github/workflows/show_specification_annotations.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - name: Generate Annotations uses: actions/setup-python@v5 diff --git a/tests/draft2020-12/additionalProperties.json b/tests/draft2020-12/additionalProperties.json index 9618575e..dadea948 100644 --- a/tests/draft2020-12/additionalProperties.json +++ b/tests/draft2020-12/additionalProperties.json @@ -1,7 +1,6 @@ [ { - "description": - "additionalProperties being false does not allow other properties", + "description": "additionalProperties being false does not allow other properties", "specification": [ { "core":"10.3.2.3", "quote": "The value of \"additionalProperties\" MUST be a valid JSON Schema. Boolean \"false\" forbids everything." } ], "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", From 23674123c2c5f3d6dd61f7d91b05ca0adfdd171e Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 1 May 2024 02:19:17 +0530 Subject: [PATCH 24/30] Cases for rfc and iso written separately --- bin/annotation_workflow.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/annotation_workflow.py b/bin/annotation_workflow.py index 438ff525..9e1a3ddf 100644 --- a/bin/annotation_workflow.py +++ b/bin/annotation_workflow.py @@ -1,4 +1,4 @@ -import json +import json, re from pathlib import Path def github_action_notice(file, url, line): @@ -39,7 +39,7 @@ def find_test_line_number(test_content, test_name): # Iterate through JSON files in tests folder and subdirectories for file_path in Path("tests").rglob("*.json"): # Read the file content using pathlib.Path - with file_path.open('r', encoding='utf-8') as f: + with file_path.open("r", encoding="utf-8") as f: changed_file_content = f.read() # Parse JSON content @@ -56,10 +56,13 @@ def find_test_line_number(test_content, test_name): continue elif spec in ["core", "validation", "hyper-schema"]: url = urls[draft][spec].format(spec=spec, section=section) + elif re.match("^rfc\\d+$", spec): + url = urls["rfc"].format(spec=spec, section=section) + elif re.match("^iso\\d+$", spec): + url = urls["iso"].format(spec=spec, section=section) else: - url = urls[spec].format(spec=spec, section=section) - annotation = github_action_notice(file_path, url, line_number) - print(annotation) + url = urls[spec].format(spec=spec, section=section) + print(github_action_notice(file_path, url, line_number)) except json.JSONDecodeError: print(f"::error file={file_path}::Failed to parse JSON content") From 3a50900741bbb02c19ba4f66a9f744ba8ea42e13 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 1 May 2024 02:40:45 +0530 Subject: [PATCH 25/30] Clear existin annotations on same PR --- bin/annotation_workflow.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/annotation_workflow.py b/bin/annotation_workflow.py index 9e1a3ddf..e8aac81a 100644 --- a/bin/annotation_workflow.py +++ b/bin/annotation_workflow.py @@ -29,6 +29,12 @@ def find_test_line_number(test_content, test_name): return i # Return the line number if found return 1 # Return None if test name is not found +def clear_previous_annotations(): + """ + Clear previous GitHub action annotations. + """ + print("::remove-matcher owner=me::") + # Specify the path to the JSON file using pathlib.Path json_file_path = Path("bin/specification_urls.json") @@ -62,6 +68,8 @@ def find_test_line_number(test_content, test_name): url = urls["iso"].format(spec=spec, section=section) else: url = urls[spec].format(spec=spec, section=section) + + clear_previous_annotations() print(github_action_notice(file_path, url, line_number)) except json.JSONDecodeError: From f2766616f86ff39d386517f0a490ed32422f3d10 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 8 May 2024 20:22:32 +0530 Subject: [PATCH 26/30] template library, url loads changes --- bin/annotation_workflow.py | 73 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/bin/annotation_workflow.py b/bin/annotation_workflow.py index e8aac81a..df789d73 100644 --- a/bin/annotation_workflow.py +++ b/bin/annotation_workflow.py @@ -1,16 +1,17 @@ import json, re from pathlib import Path +import uritemplate -def github_action_notice(file, url, line): +def github_action_notice(path, url, line): """ - Print GitHub action notice with file path, URL, and line number. + Return a GitHub action notice with file path, URL, and line number. Parameters: - file (str): File path. + path (str): File path. url (str): URL. line (int): Line number. """ - return f"::warning file={file},line={line}::Annotation: {url}" + return f"::warning file={path},line={line}::Annotation: {url}" def find_test_line_number(test_content, test_name): """ @@ -23,11 +24,11 @@ def find_test_line_number(test_content, test_name): Returns: int: Line number of the test. """ - lines = test_content.split("\n") # Split content into lines - for i, line in enumerate(lines, start=1): # Iterate over lines - if test_name in line: # Check if test name is found in the line - return i # Return the line number if found - return 1 # Return None if test name is not found + lines = test_content.split("\n") + for i, line in enumerate(lines, start=1): + if test_name in line: + return i + return 1 def clear_previous_annotations(): """ @@ -35,42 +36,40 @@ def clear_previous_annotations(): """ print("::remove-matcher owner=me::") -# Specify the path to the JSON file using pathlib.Path json_file_path = Path("bin/specification_urls.json") -# Read specification URLs from JSON file using pathlib.Path -with json_file_path.open("r", encoding="utf-8") as f: - urls = json.load(f) +BIN_DIR = Path(__file__).parent +urls = json.loads(BIN_DIR.joinpath("specification_urls.json").read_text()) + +clear_previous_annotations() -# Iterate through JSON files in tests folder and subdirectories for file_path in Path("tests").rglob("*.json"): - # Read the file content using pathlib.Path + with file_path.open("r", encoding="utf-8") as f: changed_file_content = f.read() - - # Parse JSON content + try: json_content = json.loads(changed_file_content) - for test in json_content: - if "specification" in test: - line_number = find_test_line_number(changed_file_content, test.get("description") ) + except json.JSONDecodeError: + print(f"::error file={file_path}::Failed to parse JSON content") - for specification_object in test["specification"]: - for spec, section in specification_object.items(): - draft = file_path.parent.name - if spec in ["quote"]: - continue - elif spec in ["core", "validation", "hyper-schema"]: - url = urls[draft][spec].format(spec=spec, section=section) - elif re.match("^rfc\\d+$", spec): - url = urls["rfc"].format(spec=spec, section=section) - elif re.match("^iso\\d+$", spec): - url = urls["iso"].format(spec=spec, section=section) - else: - url = urls[spec].format(spec=spec, section=section) + for test in json_content: + if "specification" in test: + line_number = find_test_line_number(changed_file_content, test.get("description") ) - clear_previous_annotations() - print(github_action_notice(file_path, url, line_number)) + for specification_object in test["specification"]: + for spec, section in specification_object.items(): + draft = file_path.parent.name + if spec in ["quote"]: + continue + elif spec in ["core", "validation", "hyper-schema"]: + template = uritemplate.URITemplate(urls[draft][spec]) + elif re.match("^rfc\\d+$", spec): + template = uritemplate.URITemplate(urls["rfc"]) + elif re.match("^iso\\d+$", spec): + template = uritemplate.URITemplate(urls["iso"]) + else: + template = uritemplate.URITemplate(urls[spec]) + url = template.expand(spec=spec, section=section) - except json.JSONDecodeError: - print(f"::error file={file_path}::Failed to parse JSON content") + print(github_action_notice(file_path, url, line_number)) From 11f8e5115d5c2352d0d631aea680e3080239a13f Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 8 May 2024 20:31:56 +0530 Subject: [PATCH 27/30] Added installing command in workflow --- .github/workflows/show_specification_annotations.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/show_specification_annotations.yml b/.github/workflows/show_specification_annotations.yml index a4fd65fd..b041265c 100644 --- a/.github/workflows/show_specification_annotations.yml +++ b/.github/workflows/show_specification_annotations.yml @@ -12,6 +12,9 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install dependencies + run: pip install uritemplate + - name: Generate Annotations uses: actions/setup-python@v5 with: From 57c7c8697cac0f3d4e57e1544643f03349c56d18 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 8 May 2024 22:09:12 +0530 Subject: [PATCH 28/30] changed install location --- .github/workflows/show_specification_annotations.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/show_specification_annotations.yml b/.github/workflows/show_specification_annotations.yml index b041265c..a0c99e99 100644 --- a/.github/workflows/show_specification_annotations.yml +++ b/.github/workflows/show_specification_annotations.yml @@ -11,8 +11,6 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: Install dependencies run: pip install uritemplate - name: Generate Annotations From d8ade402567b1a8b0acd70d60fd6a2365d631cc7 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 8 May 2024 22:16:46 +0530 Subject: [PATCH 29/30] inside run --- .github/workflows/show_specification_annotations.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/show_specification_annotations.yml b/.github/workflows/show_specification_annotations.yml index a0c99e99..fdca83e2 100644 --- a/.github/workflows/show_specification_annotations.yml +++ b/.github/workflows/show_specification_annotations.yml @@ -11,7 +11,10 @@ jobs: steps: - uses: actions/checkout@v4 - run: pip install uritemplate + + - name: Install dependencies + run: | + pip install uritemplate - name: Generate Annotations uses: actions/setup-python@v5 From e4bd7554315cf0a39bc9df6619b026d1f575c2d9 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Wed, 8 May 2024 22:23:37 +0530 Subject: [PATCH 30/30] dumbness2 corrected --- .github/workflows/show_specification_annotations.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/show_specification_annotations.yml b/.github/workflows/show_specification_annotations.yml index fdca83e2..824dd63e 100644 --- a/.github/workflows/show_specification_annotations.yml +++ b/.github/workflows/show_specification_annotations.yml @@ -12,14 +12,12 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install dependencies - run: | - pip install uritemplate - - name: Generate Annotations uses: actions/setup-python@v5 with: python-version: '3.x' - name: Run Python script - run: python bin/annotation_workflow.py + run: | + pip install uritemplate + python bin/annotation_workflow.py