3

Given a POST request with Content-Type: application/json and a body of ["foo", "bar"] how do I create a Colander schema in Pyramid using Cornice to deserialize this.

This is what I've come up with:

class SimpleList(colander.SequenceSchema):
    items = colander.SchemaNode(colander.String())

And it works great in the CLI with vanilla Colander. However, when I use it on a Cornice Service like so:

@simple_list_service.post(schema=SimpleList)
def simple_list_post(request):
    print(request.validated)

I get this:

{"errors": [{"name": "items", "description": "items is missing", "location": "body"}], "status": "error"}

Any suggestions?

Thanks!

Tim Tisdall
  • 9,914
  • 3
  • 52
  • 82
Dan P.
  • 1,433
  • 1
  • 16
  • 28

1 Answers1

0

The current version of cornice only allows colander.MappingSchema for schema validation. Anything else throws an exception (obviously you did this before that change was made as you got farther).

So, unless things change, you can't validate a list as input.

Tim Tisdall
  • 9,914
  • 3
  • 52
  • 82