I try add schema validation as it describe in official cornice doc and the do that through decorator like service_name.post(schema=SomeSchemaClass) but it's doesn't work
import colander
class TrackSchema(colander.MappingSchema):
genre = colander.SchemaNode(colander.String(), location="body", type='str')
@track.post(schema=TrackSchema)
def create_track(request):
...
And I get error
"status": "error", "errors": [{"location": "body", "name": null, "description": "Expecting value: line 1 column 2 (char 1)"}, {"location": "body", "name": "genre", "description": "genre is missing"}]}
I try different types of location arg like querystring and headers but I got the same error.
Encountered the same and after digging in, if you look at cornice.util.extract_request_data
function, you'll see that its trying to load the body as json json.loads(request.body)
so you need to post your data as json:
curl -H "Content-Type: application/json" -X POST http://localhost:6543/foo -d '{"foo": "bar"}'
HTH