marshmallow-code/marshmallow

Create raw list Schema

Opened this issue · 1 comments

How can one create Schema derived class from a list only data?

For input with a field value, i.e. dictionary, e.g.:

{
  "string_list": [
    "one",
    "two",
    "three"
  ]
}

one can use;

class StringListSchema(Schema):
    string_list = fields.List(fields.Str())

But how can one so it when input is just a list:

[
  "one",
  "two",
  "three"
]

?

NB: both are valid JSONs

I don't think you can do that with marshmallow. I'm pretty sure there was once a discussion about it, maybe involving sort of merging Schema and Field. I can't find it.

You could probably use a pre_load to wrap the payload into a dict with a single key and using that key as name for the List field in the schema, but this sucks, of course.