-
Notifications
You must be signed in to change notification settings - Fork 69
SB3 Schema/Validation #21
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
Conversation
…ratch 3.0 projects. Added sb3 schema, renamed sb2 schema, and updated validate to check given input against both sb2 and sb3 schemas. Validate appends a projectVersion to the given project with 2 or 3 if the given project is valid against the corresponding schema. Validate now returns an object containing an error message and both the sb2 and sb3 validation errors upon failure to validate against both schemas. BREAKING CHANGE: Changes to validate API and what it returns (namely, error returned by validate is no longer a string, but is now an object which contains an error message string as well as the sb2 errors and the sb3 errors). Users of this library function should expect to parse the given error to figure out why validation failed.
…ise-based interface. Refactor m Refactor unpack and main exported function to return optional zip, if originally provided, in addition to the validated project. BREAKING CHANGE: Change to main api to return originally provided zip (or null if string was provided) along with validated project, in a 2-element array.
Fixed up existing test coverage to accommodate the recent breaking changes.
Field and input values can be strings or numbers. TopLevel property is not required of blocks. VM version property should be more permissive and follow semantic release convention.
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.
This looks great. I think my only suggestion would be to add a unit test for the new zip.js
module that wraps JSZip, but the rest of the test coverage looks good. Hopefully we can simplify this a bit further when we move the analysis stuff into it's own module.
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.
This all looks good, though I agree with the suggestion for a unit test for lib/zip.js
. The comments I made are more about potential future work than this PR in particular.
lib/sb3_schema.json
Outdated
}, | ||
"md5": { | ||
"type": "string", | ||
"pattern": "^[a-fA-F0-9]{32}.[a-zA-Z]+$" |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
validationError: 'Could not parse as a valid SB2 or SB3 project.', | ||
sb2Errors: validateSb2.errors, | ||
sb3Errors: validateSb3.errors | ||
}; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
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.
I don't think any of my comments should block merging, and are just feedback for things that we might want to adjust in the future.
index.js
Outdated
}; | ||
|
||
// First unpack the input (need this outside of the async waterfall so that | ||
// unoackedProject can be refered to again) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
lib/sb3_schema.json
Outdated
"rotationCenterY": { | ||
"type": "number" | ||
}, | ||
"skinId": { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
lib/sb3_schema.json
Outdated
"sampleCount": { | ||
"type": "integer" | ||
}, | ||
"soundID": { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
} | ||
} | ||
}, | ||
"block": { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
] | ||
}, | ||
|
||
"targets": { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
…dd descriptive error message to Added unit tests for unzip and added a user-friendly error message for unzip being unable to perform its duties of extracting a project.json from the given input (zip).
… from sb3 schema that aren't ne
…in sb3 schema to reflect the ac
@rschamp, @cwillisf, @thisandagain, I believe I have now made changes (or comments) that address your PR comments. I think this PR (or just those changes) needs a second glance before this PR is ready to go. |
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.
👍
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.
😎
This PR is an improved (less complexity, less major code changes) version of #20 which is closed in favor of this PR.
Proposed Changes
input is valid against either of them. Note breaking change: since the validator is now checking against two different schemas, the 'error' returned by the validate function is now an object which includes both sb2 and sb3 errors if the input failed to validate against both specifications.
Test Coverage
The existing tests have been modified to accommodate these changes as necessary. Additional tests to be added for sb3 validation and for testing the new promise functionality. Both of these have been manually tested through scratch-vm and scratch-gui.
Additional Notes
This PR is related to the following PRs, and should be merged before either of them. The changes in these other PRs depend on the changes proposed by this PR.
scratchfoundation/scratch-vm#979
scratchfoundation/scratch-gui#1621