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

Parameter with valid JSON Schema definition may fail validation #117

Open
vdice opened this issue Sep 3, 2019 · 1 comment
Open

Parameter with valid JSON Schema definition may fail validation #117

vdice opened this issue Sep 3, 2019 · 1 comment

Comments

@vdice
Copy link
Member

vdice commented Sep 3, 2019

This project currently uses the qri-io/jsonschema library for parameter validation, as in https://github.com/deislabs/cnab-go/blob/master/bundle/definition/validation.go.

However, this underlying library currently only defines a subset of valid schema properties (see https://github.com/qri-io/jsonschema/blob/master/validate.go#L58-L107) and will fail validation (actually in unmarshal-ing prior to) for properties not in the list and not supplied via a custom validator.

One such property that would trigger this failure is contentEncoding. As an example, the validation then fails with:

Error: could not list bundle instances: error unmarshaling contentEncoding from json: json: cannot unmarshal string into Go value of type jsonschema._schema

Ways to avoid these validation failures would be:

  • Add a custom validator to the jsonschema library before unmarshal-ing/validation. We'd have to do this for any/all missing/desired properties. See fix(bundle/definition): add custom validator for contentEncoding #118 as a first example.
  • Add/PR applicable validators upstream (depending on project status, etc.)
  • Explore use of a different JSON Schema validation library with full/desired support
  • Other?
@urfinjuezz
Copy link

There is a library that supports all scheme parameters, including the more recent draft-2020-12 (https://github.com/santhosh-tekuri/jsonschema). This library is easily integrated into cnab-go, I have an almost ready-made solution. But there is a nuance, the library does not return an error if incorrect content Encoding is passed, this will change the behavior, and actually I created a pullRequest (#305) in which I changed the library and corrected the tests for new error texts. I deleted one test, this is due to the behavior that I described above

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

No branches or pull requests

2 participants