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 parsing of the 'required' constraint #15

Merged
merged 2 commits into from
Oct 2, 2019

Conversation

serge-gaia
Copy link
Contributor

Fixed issue where the constraint required: false on a field's schema was interpreted as required: true.

Use the library datatable Field.required instead of our own parsing.

…was interpreted as `required: true`.

 Use the library datatable `Field.required`
@serge-gaia serge-gaia requested a review from tony-gaia October 2, 2019 03:41
@@ -142,7 +142,7 @@ export class SchemaService {

private static isRequiredField(field: Field): boolean {
if (typeof field === 'object') {
return 'constraints' in field && 'required' in field.constraints;
return field.required;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd put a !! in front of field.required to make sure it returns a boolean (in case required is undefined).

Suggested change
return field.required;
return !!field.required;

Copy link
Contributor Author

@serge-gaia serge-gaia Oct 2, 2019

Choose a reason for hiding this comment

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

required should not be undefined if field is really a frictionless tableschema field:
https://github.com/frictionlessdata/tableschema-js#field

But it doesn't hurt to add guards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@tony-gaia tony-gaia merged commit 93d5c08 into master Oct 2, 2019
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.

2 participants