Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to model schema for list of embedded dictionaires in python eve

Tags:

eve

I have a Document where a user has 2 addresses such as below. How would I create a schema for this in python-eve?

Also, How would I create an API request to allow a user to update only the zipcode. Do they have to repost the entire document?

{
   _id: "joe",
   name: "Joe Bookreader",
   addresses: [
                {
                  street: "123 Fake Street",
                  city: "Faketon",
                  state: "MA",
                  zip: "12345"
                },
                {
                  street: "1 Some Other Street",
                  city: "Boston",
                  state: "MA",
                  zip: "12345"
                }
              ]
 }
like image 501
CraigH Avatar asked Feb 06 '16 21:02

CraigH


1 Answers

As far as the schema goes, this should do the trick (docs):

'addresses': {
    'type': 'list',
    'schema' {
        'type': 'dict',
        'schema': {
            'street': {'type': 'string'},
            'city': {'type': 'string'},
            'state': {'type': 'string'},
            'zip': {'type': 'string'}
         }
     }
 }

Dot notation is supported for PATCH (update) requests, but not on lists of documents. They are trickier, and hard to do in a RESTful way. There's an open ticket for that right now, but not direct solution yet, I am afraid.

like image 94
Nicola Iarocci Avatar answered Sep 23 '22 22:09

Nicola Iarocci