marshmallow-jsonapi
marshmallow-jsonapi copied to clipboard
Collection of entities
On the landing page of jsonapi.org they specify what to return for a collection of entities (a data
array with all entities inside). Is this something that's already implemented that I just completely missed the docs on?
If this isn't currently being worked on, how can I help to get this accomplished?
@Rdbaker yes i don't see any examples in the docs, the http://marshmallow.readthedocs.org/en/latest/examples.html?highlight=dump#quotes-api-flask-sqlalchemy docs are a bit better for this
here's an example. it'd be tremendous if you add something to the docs and make a PR :)
from pprint import pprint
from marshmallow_jsonapi import Schema, fields
users = [{id: 1, name:'user1', nickname:'user1', email:'[email protected]'},
{id: 1, name:'user1', nickname:'user1', email:'[email protected]'}]
class UserSchema(Schema):
""" User Schema. """
id = fields.Int(dump_only=True)
name = fields.Str(required=True)
password = fields.Str(load_only=True, required=True)
nickname = fields.Str(required=True)
email = fields.Email(required=True)
class Meta:
type_ = 'user'
strict = True
users_schema = UserSchema()
pprint(users_schema.dump(users, many=True).data)
{'data': [{'attributes': {'email': '[email protected]',
'name': 'user1',
'nickname': 'user1'},
'type': 'user'},
{'attributes': {'email': '[email protected]',
'name': 'user1',
'nickname': 'user1'},
'type': 'user'}]}
ok, reading a bit deeper through the repo it looks like it's a transparent pass to the marshmallow library call.. meaning that this questions is actually answered here.
Maybe the docs should have an FAQ section or something like that so people don't have to dig through the source. I'm happy to add that to the docs, any idea on where it would go?
how about under quick start - serialization alongside the example of serializing a single object?
https://raw.githubusercontent.com/marshmallow-code/marshmallow-jsonapi/dev/docs/quickstart.rst