-
Notifications
You must be signed in to change notification settings - Fork 2
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
refactor: ♻️ switch between schemas for codemeta.json version #126
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1ca6f1d
🐛 fix: update sorting on updated time (#121)
megasanjay 31935f6
⚰️ chore: update stdout
megasanjay 93a22cd
✨ feat: add a dashboard page (#122)
megasanjay c31467f
refactor: :recycle: update version number before merge
slugb0t 3b5244b
fix: :bug: prettier config updated for bot + cwl patch (#124)
slugb0t f248b24
feat: :sparkles: seperate codemeta 2.0 and 3.0 schemas
slugb0t 6f2cadc
refactor: :recycle: update codemeta 3.0 schema
slugb0t 7cd5636
Merge branch 'main' into staging
slugb0t b60363a
Merge remote-tracking branch 'origin/main' into staging
slugb0t 92c01c4
refactor: :recycle: hide okay button until it is clickable
slugb0t f2e6db7
refacor: :recycle: switch between the two validation schemas dependin…
slugb0t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -218,23 +218,46 @@ def post(self): | |||||||||||||
"message": "Validation Error", | ||||||||||||||
"error": "Unsupported codemeta version", | ||||||||||||||
}, 400 | ||||||||||||||
try: | ||||||||||||||
with open("./codemeta-schema.json", "r", encoding="utf-8") as f: | ||||||||||||||
schema = json.load(f) | ||||||||||||||
jsonschema.validate(file_content, schema) | ||||||||||||||
|
||||||||||||||
return { | ||||||||||||||
"message": "valid", | ||||||||||||||
"version": codemeta_version, | ||||||||||||||
}, 200 | ||||||||||||||
except jsonschema.exceptions.ValidationError as e: | ||||||||||||||
return { | ||||||||||||||
"message": "invalid", | ||||||||||||||
"error": str(e.message + " at " + str(e.validator_value)), | ||||||||||||||
"version": codemeta_version, | ||||||||||||||
}, 200 | ||||||||||||||
except Exception as e: | ||||||||||||||
return { | ||||||||||||||
"message": "Validation Error", | ||||||||||||||
"error": f"Unexpected error: {str(e)}", | ||||||||||||||
}, 400 | ||||||||||||||
if codemeta_version == "2.0": | ||||||||||||||
try: | ||||||||||||||
with open("./codemeta-schema2.0.json", "r", encoding="utf-8") as f: | ||||||||||||||
schema = json.load(f) | ||||||||||||||
jsonschema.validate(file_content, schema) | ||||||||||||||
|
||||||||||||||
return { | ||||||||||||||
"message": "valid", | ||||||||||||||
"version": codemeta_version, | ||||||||||||||
}, 200 | ||||||||||||||
except jsonschema.exceptions.ValidationError as e: | ||||||||||||||
return { | ||||||||||||||
"message": "invalid", | ||||||||||||||
"error": str(e.message + " at " + str(e.validator_value)), | ||||||||||||||
"version": codemeta_version, | ||||||||||||||
}, 200 | ||||||||||||||
except Exception as e: | ||||||||||||||
return { | ||||||||||||||
"message": "Validation Error", | ||||||||||||||
"error": f"Unexpected error: {str(e)}", | ||||||||||||||
}, 400 | ||||||||||||||
Comment on lines
+240
to
+242
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Consider using a 500 status code for unexpected errors instead of 400 400 Bad Request implies client error, but unexpected exceptions might be server-side issues. Using 500 Internal Server Error would be more appropriate for unexpected exceptions.
Suggested change
|
||||||||||||||
elif codemeta_version == "3.0": | ||||||||||||||
try: | ||||||||||||||
with open("./codemeta-schema.json", "r", encoding="utf-8") as f: | ||||||||||||||
schema = json.load(f) | ||||||||||||||
jsonschema.validate(file_content, schema) | ||||||||||||||
|
||||||||||||||
return { | ||||||||||||||
"message": "valid", | ||||||||||||||
"version": codemeta_version, | ||||||||||||||
}, 200 | ||||||||||||||
except jsonschema.exceptions.ValidationError as e: | ||||||||||||||
return { | ||||||||||||||
"message": "invalid", | ||||||||||||||
"error": str(e.message + " at " + str(e.validator_value)), | ||||||||||||||
"version": codemeta_version, | ||||||||||||||
}, 200 | ||||||||||||||
except Exception as e: | ||||||||||||||
return { | ||||||||||||||
"message": "Validation Error", | ||||||||||||||
"error": f"Unexpected error: {str(e)}", | ||||||||||||||
}, 400 |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider extracting the validation logic into a separate function to avoid code duplication
The validation logic for both version 2.0 and 3.0 is identical except for the schema file name. Consider creating a helper function that takes the schema file name as a parameter to reduce duplication and improve maintainability.
Suggested implementation:
The developer will need to: