This module uses python types to validate request and response data in Flask Python APIs and generate API documentation. It uses python 3 type hints to validate request parameters. It also supports generic schema validation for plain dictionaries.
Next release (in development)¶
- Fixed Python 3.7+ compatibility issue.
- Fixed random inserted character.
- Fixed incorrect type hint.
- Fixed a few incorrect type hints.
- Fixed missing import.
- Fixed return types for quick type functions. mypy does not support more strict typing when using the builtin type function to dynamically generate a class. The only way for it to not complain about these functions it to omit the the return type or specify typing.Any.
- Implemented PEP-561 using inline type hints.
- Added case_insensitive option to Enum type.
- Added lowercase_value option to Enum type.
- added uppercase_value option to Enum type.
- Fixed a bug that caused object reference links to be duplicated when documenting a request param or response property that was a list of dicts.
- Fixed a bug when using new_type that did not copy all attributes of the class being passed to it. See issue #123 for more details.
- Removed syntax for variable annotations and switched back to mypy comment hints in order to support python versions >= 3.5 and < 3.6
- Added ability to add custom validation to types.
- Fixed bug where you could not specify a custom description when using the new_type type function when the type provided had it’s own description attribute.
- Document default values for optional request params by inspecting the logic function signature.
- Fixed UnionType types from not getting passed to logic functions.
- Fixed UnionType types from not getting documented in api docs.
- Fixed bug with native_type for UnionType which could cause an error parsing the value, even if it conformed to one of the n types defined.
- Fixed bug introducded in v3.10.1 when doctor attempted to generate api documentation when an endpoint had a request parameter that was an array of objects.
- Fixed bug when using UnionType as it was missing a native_type attribute.
- Fixed bug when using Array where items is a list of types for each index. Documentation was generating exceptions when processing an annotation using this type.
- Added ability to document what type(s) an array’s items are in the api documentation.
- Added optional parser attribute to doctor types that allows the ability to specify a callable to parse the request parameter before it gets validated. See the documentation for more information.
- Added new UnionType to types that allows a value to be one of n types.
- Don’t filter out request parameters not defined in the type object for routes that specify a req_obj_type.
- Added JSON body to error message when parsing JSON fails.
- Fixed bug that caused AttributError when creating routes in flask >= 1.0.0
- Fixed an AttributeError when a logic function contained a parameter in it’s signature that was not annotated by a doctor type and a request parameter in a form or query request also contained a variable that matched it’s name.
- Added ability to specify a callable that can be run before and/or after a logic function is called when defining a route. See documentation for an example.
- Added ability to specify for a particular route a request Object type that a json body should be validated against and passed to the logic function. This allows the base json body to be passed as a parameter without having to have the logic function variable match a request parameter. The full json body will simply be passed as the first parameter to the logic function.
- Fixed bug when documenting resource objects where we should have been calling Object.get_example() instead of constructing it ourselves from the object’s properties. That is what get_example does behind the scenes, but it will also use a user defined example if one is available. This is especially useful for Object’s without any properties that you still want to document an example for.
- Added the ability to document object resources in the api documentation. Any api endpoints that have an object or an array of objects in it’s request parameters will include a link to the documentation about the object.
- Added ability to specify which request parameter a type should map to it’s annotated logic function variable. See param_name in the types documentation for more information.
- Added long description to setup.py for pypi rendering.
- Updated API documentation to also include a link to the logic function associated with the endpoint being documented.
- Added ability to validate/document content of Response instances.
- Renamed base error class to DoctorError and made TypeSystemError also inherit from DoctorError. DoctorError is still aliased as SchematicError for backwards compatibility.
- Added errors property to base DoctorError, so all Doctor errors can include additional details in a standard way.
- Fixed the enum type to include possible choices in error message.
- First public release of v3.0.0
- Updates parsing of query/form params to parse null values properly.
- Makes a copy of the logic function to preserve doctor attributes if the logic function is shared between routes.
- Updated handle_http to parse query and form parameters from strings to their expected type before we do validation on them.
- Fixed issue where if multiple decorators were used on a logic function and each one added param annotations the outer most decorator would erase any param annotations added from the previous decorator.
- Added a nullable attribute to all types to signify that None is a valid value for the type, in addition to it’s native type.
- Fixed doctor attempting to document non doctor type params (#70)
- String with format of date now returns datetime.date (#69)
- Fixed swallowing of TypeError from SuperType class in Object init (#68)
- Changed the flask code to only raise response validation errors if an environment variable is set. Before it also raised them when DEBUG was True in the config. In practice this was incredibly annoying and slowed down development. Especially in the case where a datetime string was returned that didn’t include timezone information. Updated the docs to reflect this too.
- Fixed issue that could create duplicate handler names which would cause an exception in flask restful (#67 )
- Made the JsonSchema doctor type work in validating/coercing params in the api and for generating api documentation.
- Made validation errors better when raising http 400 exceptions. They now will display all missing required fields and all validation errors along with have the param in the error message.
- Fixed issue with doctor types being passed to logic functions. Instead the native types are now passed to prevent downstream issues from other code encountering unexpected/unknown types.
- Added default example values for all doctor types.
- Documentation updates
- Updated doctor code to work agnostic of the framework so eventually other backends than flask could be used.
- First beta release of 3.0. This is a backwards incompatible change. It drops support for python 2 and defining request parameters through the usage of json schemas. It’s still possible to use the json schemas from previous versions of doctor to generate new doctor types using doctor.types.json_schema_type. See the documentation for more information.
- Added status_code to Response class.
- Fixed a few deprecation warnings about inspect.getargspec when running doctor using python 3. It will now use inspect.getfullargspec. This also fixes the issue of not being able to use type hints on logic functions in python 3.
- Removed set operation on decorators when applying them to the logic function. Since set types don’t have an explicit order it caused unpredicatable behavior as the decorators weren’t always applied to the logic function in the same order with every call.
- Add request option to router HTTP method dictionary, which allows you to override the schema used to validate the request body.
- Fixed response validation when the response was an instance of doctor.response.Response
- Fixed bug when auto generating documentation for GET endpoints that contained a parameter that was an array or object. It wasn’t getting json dumped, so when the request was made to generate the example response it would get a 400 error.
- Fixed a few typos and bugs in the README quick start example.
- Added a Response class that can be returned from logic functions in order to add/modify response headers.
- More fixes for Python 3.
- Fixed sphinx build error encountered on Sphinx v1.6.1+ when checking if the http domain has already been added.
- Added support for Python 3.
- Updates doctor to not parse json bodies on GET/DELETE requests, and instead try to parse them from the query string or form parameters.
- Fixes a bug introducded in v1.1.3. This bug would only occur if a logic function was decorated and that decorator passed a positional argument to the logic function. Doctor would think the positional argument passed by the decorator was a required request parameter even if it was specified to be omitted in the router using omit_args.
- Added new InternalError class to represent non-doctor internal errors.
- Updated sphinx pin version to be minimum 1.5.4 and added new env kwarg to make_field amd make_xref.
- Fixed bug where extra parameters passed on json requests would cause a TypeError if the logic function used a decorator.
- Made sure to make decorators a set when applying them to a logic function when creating routes. This is to prevent a decorator from wrapping a function twice if it’s defined at the logic level and handler level when creating routes.
- Fixes a bug where the logic function wouldn’t be undecorated properly.
- Made logic function exceptions always raise when applicaiton is in debug mode.
- Updated error message to be clearer when a logic function raises an exception.
- Added ability to override the schema used for an individual endpoint.
- Making required changes to setup.py for pypi.
- Initial release.