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

1

5

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"
                }
              ]
 }
Cuspidor answered 6/2, 2016 at 21:1 Comment(0)
M
7

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.

Microphone answered 8/2, 2016 at 7:17 Comment(1)
can you add the full schema for the data in the question?Reamer

© 2022 - 2024 — McMap. All rights reserved.