-
Notifications
You must be signed in to change notification settings - Fork 152
Closed
Labels
Description
In Cornice < 2, when a schema item had location=path, it was extracted/validated from request.matchdict. This allowed for code like
class MySchema(colander.Schema):
item_id = colander.SchemaNode(
colander.Integer(),
location='path')
@resource(
path='/items/{item_id}.json',
schema=MySchema)
class ItemResource(object):
def __init__(self, request):
self.request = request
def get(self):
item_id = request.validated['item_id']
return {'id': item_id}In Cornice >= 2, I would naively translate the above to
class PathSchema(colander.Schema):
item_id = colander.SchemaNode(colander.Integer())
class MySchema(colander.Schema):
path = PathSchema()
@resource(
path='/items/{item_id}.json',
schema=MySchema,
validators=(colander_validator,))
class ItemResource(object):
def __init__(self, request):
self.request = request
def get(self):
item_id = request.validated['path']['item_id']
return {'id': item_id}This does not, however, seem to work. Currently, extract_cstruct puts request.path (a string) into cstruct['path'] (and does not appear to make request.matchdict available at all.)
I would suggest that extract_cstruct should be modified to make request.matchdict available in the cstruct; either as cstruct['path'] (replacing request.path) or as cstruct['matchdict'].
Am I missing something?
Reactions are currently unavailable