-
Notifications
You must be signed in to change notification settings - Fork 39
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
fix(bundle/definition): add custom validator for contentEncoding #118
Conversation
1a7a762
to
f51437c
Compare
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.
LGTM
val := struct { | ||
File string `json:"file"` | ||
}{ | ||
File: "SGVsbG8gV29ybGQhCg==", |
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.
If I change this to an invalid base64 value such as "SGVsbG8gV29ybGQhCg===", the test still passes. Shouldn't it fail?
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.
Good call; indeed, as mentioned in the code comments, the current validator is a no-op (simply allows for a contentEncoding
property), but we can and perhaps should actually perform some basic validations specific to this property. Preference on doing so in this PR or as a follow-up?
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.
Actually, I'd prefer it in this PR to check feasibility before merging this PR. Hope it's not too much work - maybe a separate commit?
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 think the values we need to support are defined by https://json-schema.org/latest/json-schema-validation.html#rfc.section.8.3.
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.
Ok, validation added for base64
. Wanted to keep scope limited so didn't venture off into adding other content encoding validations quite yet. What do you think?
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.
Fair enough. Why not raise issue(s) for the other encodings?
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.
Deal! #132
) | ||
|
||
// ContentEncoding represents a "custom" Schema property | ||
type ContentEncoding string |
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.
As NewContentEncoding
is returning a jsonschema.Validator
, do we really need to expose that type?
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.
Fair question; I followed the library's examples to set this up and I'd lean towards keeping it for code clarity/comprehension, but can change if majority deems it unnecessary.
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 have strong opinion on it, I just have the habit of reducing the exposed parts to their minimum 👍
3768a4e
to
b962d3d
Compare
b962d3d
to
47a8d43
Compare
This represents a fix to ensure definitions with a non-empty
contentEncoding
property pass validation by adding a custom validator for continued use of the jsonschema library cnab-go currently uses. It's specific tocontentEncoding
but illustrates a potential path forward for further "custom" validators (either for properties in the default JSON Schema but not stock in the jsonschema library or for truly custom properties/validators down the line.)See #117 for background on general issue and getporter/porter#579 for feature that uses the changes here to pass validation.