You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i've been using a simple decorator to get nicer ergonomics on view/route function signatures and type validation. I'd like to go ahead and add something like this to chalice, with the notion that it could also be used for swagger generation. Atm chalice swagger gen is effectively wild card method parameters with the empty object definition. Ideally with this decorator it would allow offloading request validation to api gateway, though i'm a bit unclear if thats supported by the underlying SAM transform although it looks like we could just inject a separate non sam request validator resource.
defschema(schema, required=None):
"""Decorator for chalice view functions to enable jsonschema At the moment it allows validation and keyword parameter passing based on extracted values. """# sugar syntax for skipping the declaration enclosure if'properties'notinschema:
schema= {'properties': schema,
'type': 'object',
'additionalProperties': False}
if'$schema'notinschema:
schema['$schema'] ='http://json-schema.org/schema#'ifrequiredand'required'notinschema:
schema['required'] =list(required)
defwrapper(func):
func.schema=schema@functools.wraps(func)defvalidate_invoke(*args, **kw):
r=app.current_requestifr.method=='POST':
rj=app.current_request.json_bodyelifr.method=='GET':
rj=app.current_request.query_paramsjsonschema.validate(rj, schema)
kw= {}
forkinschema['properties'].keys():
ifkinrj:
kw[k] =rj[k]
returnfunc(*args, **kw)
returnvalidate_invokereturnwrapper
i've been using a simple decorator to get nicer ergonomics on view/route function signatures and type validation. I'd like to go ahead and add something like this to chalice, with the notion that it could also be used for swagger generation. Atm chalice swagger gen is effectively wild card method parameters with the empty object definition. Ideally with this decorator it would allow offloading request validation to api gateway, though i'm a bit unclear if thats supported by the underlying SAM transform although it looks like we could just inject a separate non sam request validator resource.
in terms of using it
Potentially this would allow for future extension to using python typing information.
tbd on referencing common model definitions across view functions.
The text was updated successfully, but these errors were encountered: