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

validator has not been provided for attribute ... of type 'object' #857

Closed
bradjones1 opened this issue Jul 7, 2021 · 4 comments · Fixed by #858
Closed

validator has not been provided for attribute ... of type 'object' #857

bradjones1 opened this issue Jul 7, 2021 · 4 comments · Fixed by #858

Comments

@bradjones1
Copy link
Contributor

I am working with v0.17.0-beta.20 utilizing a json:api source pulled through an in-memory source. While syncing the record cache, the record is validated. I have a model for a file record type, with an attribute of object type specified thusly:

{
  "models": {
    "file": {
      "attributes": {
...
        "uri": {
          "type": "object"
        },
...
        }
      }
    }
  }
}

In SyncRecordCache::update, the validation fails with the following issue:

Screenshot from 2021-07-06 23-23-57

It appears this is related to #842 but as there is no documentation yet on 0.17 beyond the tests, I'm a bit stumped as to whether this is a:

  • bad model definition (there are no examples of object attributes in the current docs or tests)
  • regression/bug with the new validator model
  • something else?
@bradjones1
Copy link
Contributor Author

Looks like we're missing an object validator:

export enum StandardValidators {
Array = 'array',
Boolean = 'boolean',
Date = 'date',
Number = 'number',
String = 'string'
}
export type StandardValidator =
| ArrayValidator
| BooleanValidator
| DateValidator
| NumberValidator
| StringValidator;
export const standardValidators: Dict<StandardValidator> = {
array: validateArray,
boolean: validateBoolean,
date: validateDate,
number: validateNumber,
string: validateString
};

@dgeb
Copy link
Member

dgeb commented Jul 7, 2021

Good catch, @bradjones1.

In reviewing the validator logic, I found a few holes that I'm going to try to fill today:

  • the missing object validator (which will probably just do a typeof check)
  • datetime fields should be validated with the same date validator
  • the concept of an unknown validator to allow for a catch-all for validating types that don't have a registered validator (similar to the unknown serializer concept)

I'll get a new beta out after this work is done.

In the mean time, if you want a workaround to avoid the above error you can provide a custom validatorFor function to your sources that includes a no-op validator (() => {}) for object.

@dgeb
Copy link
Member

dgeb commented Jul 7, 2021

@bradjones1
Copy link
Contributor Author

Wow! 🚀 Thanks!

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 a pull request may close this issue.

2 participants