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

fix(bundle/definition): add custom validator for contentEncoding #118

Merged
merged 2 commits into from
Sep 24, 2019

Conversation

vdice
Copy link
Member

@vdice vdice commented Sep 4, 2019

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 to contentEncoding 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.

Copy link
Contributor

@carolynvs carolynvs left a 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==",
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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 👍

@vdice vdice merged commit 5facf46 into cnabio:master Sep 24, 2019
@vdice vdice deleted the fix/custom-validators branch September 24, 2019 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants