{ "info": { "author": "Henri Hulski", "author_email": "henri.hulski@gazeta.pl", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "more.jsonschema: JSON Schema support for Morepath\n=================================================\n\nThis package provides Morepath integration for `JSON Schema`_,\nimplemented with jsonschema_:\n\n.. _JSON Schema: http://json-schema.org\n.. _jsonschema: https://python-jsonschema.readthedocs.io/en/latest\n\nJSON Schema can automate user input validation in a HTTP API.\n\n\nSchema\n------\n\nThe JSON schema need to be load into a Python dict\n(you can use ``json.load()``):\n\n.. code-block:: python\n\n user_schema = {\n 'type': 'object',\n 'properties': {\n 'name': {\n 'type': 'string',\n 'minLength': 3\n },\n 'age': {\n 'type': 'integer',\n 'minimum': 10\n }\n },\n 'required': ['name', 'age']\n }\n\nIf you want to define JSON schemas in Python, you can use jsl_ for instance.\n\n.. _jsl: http://jsl.readthedocs.io/en/latest\n\n\nValidate\n--------\n\nThe ``more.jsonschema`` integration helps\nwith validation of the request body as it is POSTed to a view.\nFirst we must create a loader for our schema:\n\n.. code-block:: python\n\n from more.jsonschema import loader\n\n user_schema_load = loader(user_schema)\n\nWe can use this loader to handle a POST request for instance:\n\n.. code-block:: python\n\n @App.json(model=User, request_method='POST', load=user_schema_load)\n def user_post(self, request, json):\n # json is now a validated and normalized dict of whatever got\n # POST onto this view that you can use to update\n # self\n\n\nCustomize the Validator\n-----------------------\n\nBy default ``more.jsonschema`` uses the ``Draft4Validator``.\nBut you can also use the ``Draft3Validator``, create your own Validator\nor extend an existent Validator. Just pass the Validator to the\n``loader``:\n\n.. code-block:: python\n\n from jsonschema import Draft3Validator\n from more.jsonschema import loader\n\n user_schema_load = loader(user_schema, validator=Draft3Validator)\n\nMore information about creating or extending Validator classes\nyou can find in the `jsonschema documentation`_.\n\n.. _jsonschema documentation:\n https://python-jsonschema.readthedocs.io/en/latest/creating\n\n\nError handling\n--------------\n\nIf validation fails due to a validation error (a required field is\nmissing, or a field is of the wrong datatype, for instance), you want\nto show some kind of error message. The ``load`` function created by\n``more.jsonschema`` raise the ``more.jsonschema.ValidationError`` exception\nin case of errors.\n\nThis exception object has an ``errors`` attribute with the validation errors.\nYou must define an exception view for it, otherwise validation errors are\nreturned as \"500 internal server error\" to API users.\n\nThis package provides a default exception view implementation. If you subclass\nyour application from ``more.jsonschema.JsonSchemaApp`` then you get a default\nerror view for ``ValidationError`` that has a 422 status code with an error\nmessage:\n\n.. code-block:: python\n\n from more.jsonschema import JsonSchemaApp\n\n class App(JsonSchemaApp):\n pass\n\nNow your app has reasonable error handling built-in.\n\n\nCHANGES\n*******\n\n0.1 (2017-03-17)\n================\n\n* initial public release.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/morepath/more.jsonschema", "keywords": "morepath validation", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "more.jsonschema", "package_url": "https://pypi.org/project/more.jsonschema/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/more.jsonschema/", "project_urls": { "Homepage": "https://github.com/morepath/more.jsonschema" }, "release_url": "https://pypi.org/project/more.jsonschema/0.1/", "requires_dist": [ "morepath (>=0.18)", "jsonschema", "pytest-cov; extra == 'coverage'", "flake8; extra == 'pep8'", "pep8-naming; extra == 'pep8'", "pytest (>=2.9.1); extra == 'test'", "pytest-remove-stale-bytecode; extra == 'test'", "webtest; extra == 'test'" ], "requires_python": "", "summary": "JSON Schema support for Morepath", "version": "0.1" }, "last_serial": 2713596, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "88fe477478b1403174ea988bd0469797", "sha256": "26065ba2af83e5d6daead7db27f1413ced3a13705b78e481811b683179dbbc83" }, "downloads": -1, "filename": "more.jsonschema-0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "88fe477478b1403174ea988bd0469797", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7799, "upload_time": "2017-03-17T18:35:49", "url": "https://files.pythonhosted.org/packages/d0/7a/4a2d6ac6451c3ab8fbc13e9346c5c32ed6c72a0dd198b8d737aafb26b5b9/more.jsonschema-0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "785274ef3a7c32f59e7cd59b6f7ddead", "sha256": "f8f202920f96825d350e9f07f90b8c7fa59de35208758e9bcc44132efa9d86e2" }, "downloads": -1, "filename": "more.jsonschema-0.1.tar.gz", "has_sig": false, "md5_digest": "785274ef3a7c32f59e7cd59b6f7ddead", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5525, "upload_time": "2017-03-17T18:35:57", "url": "https://files.pythonhosted.org/packages/af/f9/f25aa52f1205468322e764d62de55aaf12de61016b7ab0ae54c630a710f7/more.jsonschema-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "88fe477478b1403174ea988bd0469797", "sha256": "26065ba2af83e5d6daead7db27f1413ced3a13705b78e481811b683179dbbc83" }, "downloads": -1, "filename": "more.jsonschema-0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "88fe477478b1403174ea988bd0469797", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7799, "upload_time": "2017-03-17T18:35:49", "url": "https://files.pythonhosted.org/packages/d0/7a/4a2d6ac6451c3ab8fbc13e9346c5c32ed6c72a0dd198b8d737aafb26b5b9/more.jsonschema-0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "785274ef3a7c32f59e7cd59b6f7ddead", "sha256": "f8f202920f96825d350e9f07f90b8c7fa59de35208758e9bcc44132efa9d86e2" }, "downloads": -1, "filename": "more.jsonschema-0.1.tar.gz", "has_sig": false, "md5_digest": "785274ef3a7c32f59e7cd59b6f7ddead", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5525, "upload_time": "2017-03-17T18:35:57", "url": "https://files.pythonhosted.org/packages/af/f9/f25aa52f1205468322e764d62de55aaf12de61016b7ab0ae54c630a710f7/more.jsonschema-0.1.tar.gz" } ] }