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: validate property values are not empty #247

Merged
merged 1 commit into from
Nov 26, 2021
Merged

Conversation

dpilch
Copy link
Contributor

@dpilch dpilch commented Nov 23, 2021

Validates that a property value is not an empty object.

// invalid
properties: {
  pathData: {}
}

// valid
properties: {
  pathData: {
    value: ''
  }
}

Copy link
Contributor

@alharris-at alharris-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM - one n.p.

]),
),
)
.required();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a taste thing, I'd prefer to leave required in the parent object, rather than here. It's functionally identical, but I think maps slightly better to where optionality is defined in the parent, rather than in the object itself, similar to the smithy and typescript definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can move required up.

Are you suggesting like this?

const propertiesSchema = yup.lazy((value) => {
  return yup
    .object()
    .shape(...)
}).required();

Gives error:
Property 'required' does not exist on type 'Lazy<O...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, just remove from this definition entirely, then in the Component validator, it'd be like properties: propertiesSchema.required(),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah makes sense, good idea.

@dpilch dpilch merged commit f712117 into develop Nov 26, 2021
@dpilch dpilch deleted the validate-properties branch November 26, 2021 19:58
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

3 participants