Skip to content
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

Improve schema definition validation to prevent collisions #8655

Merged

Conversation

fredericbarthelet
Copy link
Contributor

Closes: #8481

@codecov
Copy link

codecov bot commented Dec 21, 2020

Codecov Report

Merging #8655 (a88767b) into master (95c0bc0) will decrease coverage by 0.00%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8655      +/-   ##
==========================================
- Coverage   87.15%   87.15%   -0.01%     
==========================================
  Files         252      252              
  Lines        9509     9544      +35     
==========================================
+ Hits         8288     8318      +30     
- Misses       1221     1226       +5     
Impacted Files Coverage Δ
lib/classes/ConfigSchemaHandler/index.js 91.35% <87.50%> (-1.56%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95c0bc0...a88767b. Read the comment docs.

pgrzesik
pgrzesik previously approved these changes Dec 22, 2020
Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fredericbarthelet 🙇 Looks good from my perspective, but as I'm not super familiar with schema engine yet, I'll ask for another review before merging this in

@@ -290,6 +309,21 @@ class ConfigSchemaHandler {
}

function addPropertiesToSchema(subSchema, extension = { properties: {}, required: [] }) {
let collidingExtensionPropertyKey;
const existingSubSchemaPropertiesKeys = Object.keys(subSchema.properties);
Object.keys(extension.properties).some(extensionPropertiesKey => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I was thinking why not to throw an error inside the callback, but I've noticed you used some to stop iteration on first colliding property, nice 👍

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fredericbarthelet looks great! I have just one DX suggestion towards error reporting, as as proposed may result with vague error reports.

lib/classes/ConfigSchemaHandler/index.js Outdated Show resolved Hide resolved
lib/classes/ConfigSchemaHandler/index.js Outdated Show resolved Hide resolved
lib/classes/ConfigSchemaHandler/index.js Outdated Show resolved Hide resolved
@fredericbarthelet
Copy link
Contributor Author

@medikoo I implemented your suggestions and added test cases for all different location where an error could be thrown :)

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @fredericbarthelet ! Looks great

@medikoo medikoo merged commit 7266599 into serverless:master Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve schema definition methods
3 participants