-
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
Conversation
* 🐛 fix: update sorting on updated time * ⚰️ chore: remove yarn.lock * 💄 style: uipdate profile ui
* ✨ feat: add a dashboard page * 🐛 fix: remove old code * 🐛 fix: add response checks * refactor: ♻️ dashboard link in nav directs to /dashboard * refactor: ♻️ update variables for GET /dashboard api --------- Co-authored-by: slugb0t <wheresdorian@gmail.com>
Thank you for submitting this pull request! We appreciate your contribution to the project. Before we can merge it, we need to review the changes you've made to ensure they align with our code standards and meet the requirements of the project. We'll get back to you as soon as we can with feedback. Thanks again! |
Reviewer's Guide by SourceryThis pull request refactors the validator API to support multiple schemas for different CodeMeta versions. It implements version switching logic and error handling for schema validation. Additionally, the UI is updated to only show the "Okay" button after publishing to Zenodo, simplifying the user interaction. Sequence diagram for CodeMeta validation with version supportsequenceDiagram
participant Client
participant API
participant SchemaValidator
Client->>API: POST /validate with codemeta.json
API->>API: Extract codemeta_version
alt version not supported
API-->>Client: Return 400 error
else version == 2.0
API->>SchemaValidator: Load codemeta-schema2.0.json
SchemaValidator->>SchemaValidator: Validate content
else version == 3.0
API->>SchemaValidator: Load codemeta-schema.json
SchemaValidator->>SchemaValidator: Validate content
end
alt validation successful
API-->>Client: Return valid status (200)
else validation error
API-->>Client: Return invalid status with error (200)
else unexpected error
API-->>Client: Return error status (400)
end
State diagram for Zenodo publish button visibilitystateDiagram-v2
[*] --> Hidden: Initial State
Hidden --> Visible: When status is 'published' or 'error'
Visible --> [*]: After clicking Okay
note right of Hidden: Button not shown during processing
note right of Visible: Button enables navigation to dashboard
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Thanks for making updates to your pull request. Our team will take a look and provide feedback as soon as possible. Please wait for any GitHub Actions to complete before editing your pull request. If you have any additional questions or concerns, feel free to let us know. Thank you for your contributions! |
PR Summary
|
Thanks for closing this pull request! If you have any further questions, please feel free to open a new issue. We are always happy to help! |
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.
Hey @slugb0t - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider reducing code duplication by extracting the schema validation logic into a separate function that takes the schema filename as a parameter. This would make the code more maintainable and easier to extend for future codemeta versions.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -218,23 +218,46 @@ def post(self): | |||
"message": "Validation Error", | |||
"error": "Unsupported codemeta version", | |||
}, 400 |
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:
def validate_schema(schema_filename: str, version: str) -> tuple[dict, int]:
"""Validate file content against the specified schema file.
Args:
schema_filename: Path to the schema file
version: Version string to include in the response
Returns:
Tuple of (response dict, status code)
"""
try:
with open(schema_filename, "r", encoding="utf-8") as f:
schema = json.load(f)
jsonschema.validate(file_content, schema)
return {
"message": "valid",
"version": version,
}, 200
except jsonschema.exceptions.ValidationError as e:
raise e
if codemeta_version == "2.0":
return validate_schema("./codemeta-schema2.0.json", codemeta_version)
The developer will need to:
- Update the code handling version 3.0 to use the new validate_schema() function in the same way
- Ensure the error handling for ValidationError is properly implemented in the calling code since we're re-raising the exception
"message": "Validation Error", | ||
"error": f"Unexpected error: {str(e)}", | ||
}, 400 |
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 (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.
"message": "Validation Error", | |
"error": f"Unexpected error: {str(e)}", | |
}, 400 | |
"message": "Internal Server Error", | |
"error": f"Unexpected error: {str(e)}", | |
}, 500 |
Summary by Sourcery
Support validating different versions of the codemeta schema.
New Features:
Tests: