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

Add support for embedded objects #372

Open
BryanHunt opened this issue Feb 6, 2018 · 7 comments
Open

Add support for embedded objects #372

BryanHunt opened this issue Feb 6, 2018 · 7 comments

Comments

@BryanHunt
Copy link

We have a use-case where we need to use embedded objects. According to the JSON-API spec:

Complex data structures involving JSON objects and arrays are allowed as attribute values

When we try to create a schema containing an embedded object, we get:

Error: Unable to parse Joi type
@championswimmer
Copy link
Contributor

Can you provide an example of your resource config and what object you want to store ?
I am working on a fork of this https://github.com/coding-blocks/jsonapi-server/
I would be interested in supporting object attributes

@pmcnr-hx
Copy link
Contributor

pmcnr-hx commented Feb 7, 2018

Can you please provide a example of your schema @BryanHunt? We're still using an older version of Joi to support Node.js v6, but I've been working on moving to v8 + transpilling to support v6, which would allow use to use the latest version of Joi which will probably support your use case. Anyway, if you can provide an example I can have a more detailed look at this.

@BryanHunt
Copy link
Author

Here's a specific use-case I'm about to have:

{
  "id" : "94419dc7-a945-4dd3-8f01-c778ef49a5ac",
  "type" : "notifications",
  "attributes" : {
    "sentOn" : 1518932462583.0,
    "tags" : [
      { "key1" : "value1" },
      { "key2" : "value2" }
    ]
  }
}

In this specific use-case, a notification contains an array of tags that are key:value pairs where the keys and values are arbitrary (user defined). The keys are restricted to strings, but the values could be strings, numbers, etc.

Here is another example use-case:

{
  "id" : "94419dc7-a945-4dd3-8f01-c778ef49a5ac",
  "type" : "widgets",
  "attributes" : {
    "name" : "My Widget",
    "backgroundColor" : {
      "r" : 109,
      "g" : 25,
      "b" : 193
    }
  }
}

@paparomeo
Copy link
Contributor

Thanks for providing the example. I'm planning on spending some time next week on the project so I should be able to look into updating Joi and see if we can support your use case.

@gboston
Copy link

gboston commented May 4, 2018

We would also like to validate nested objects but this isn't possible at the moment?

@championswimmer
Copy link
Contributor

You can validate via Joi

@gboston
Copy link

gboston commented May 4, 2018

Mistakenly used .valid() instead of .items() for validating objects within an array. It's working now 👍

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

No branches or pull requests

5 participants