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

feat(schema.go): add support for params of object type in ConvertValue #251

Merged
merged 1 commit into from
May 26, 2021

Conversation

vdice
Copy link
Member

@vdice vdice commented May 13, 2021

  • Adds support for params of type object in ConvertValue

(Original issue from Porter: getporter/porter#1459)

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.

Do we have existing tests around the validate call for object properties with json schema definitions? Like the replica count property in the original example, if the input was a string instead of an integer, or it violated the maximum, would bundle.validate fail with a good error?

Also have we confirmed what this parameter ends up looking like when it's finally injected into the bundle at runtime? There is a related porter issue about consuming object parameters. I think it would help if we checked how well object parameters are supported from definition through consumption in the bundle to sus out any further changes needed.

@vdice
Copy link
Member Author

vdice commented May 18, 2021

Do we have existing tests around the validate call for object properties with json schema definitions? Like the replica count property in the original example, if the input was a string instead of an integer, or it violated the maximum, would bundle.validate fail with a good error?

This library indeed has existing unit tests in this area: https://github.com/cnabio/cnab-go/blob/main/bundle/definition/validation_test.go These are a bit more abstract in that they build inline JSON Schemas and test them against provided values (using the func (s *Schema) Validate(data interface{})... function. So, the validation has been in place. This PR adds the link of allowing parameter values of type object to flow through and then be validated by the provided parameter definition schema.

Also have we confirmed what this parameter ends up looking like when it's finally injected into the bundle at runtime? There is a related porter issue about consuming object parameters. I think it would help if we checked how well object parameters are supported from definition through consumption in the bundle to sus out any further changes needed.

I haven't dug in deeply, but I have tested these changes with a sample Porter bundle like https://github.com/vdice/porter-bundles/blob/master/params/porter.yaml, which will catch instances when a parameter value is invalid per the inline definition schema, etc. The ConvertValue func updated in this PR does a lot of the runtime magic: converting the param vals that have arrived in string form into their intended/native golang types (integer, boolean, object, etc.)

Not sure I've adequately answered any/all of the above. Let me know!

@carolynvs
Copy link
Contributor

That is exactly the info I was looking for, thanks! I really just wanted to make sure that we had tests in place ✅ and have seen this work in Porter ✅ .

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

@vdice vdice merged commit 6e7e1f5 into cnabio:main May 26, 2021
@vdice vdice deleted the feat/support-object-type-param branch May 26, 2021 16:49
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.

3 participants