cnabio / cnab-go

A Go implementation of CNAB Core 1.0
MIT License
69 stars 37 forks source link

Parameter with valid JSON Schema definition may fail validation #117

Open vdice opened 5 years ago

vdice commented 5 years ago

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:

urfinjuezz commented 5 days ago

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 (https://github.com/cnabio/cnab-go/pull/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