Repository: cwacek/python-jsonschema-objects

Issue:
Detail JSON Schema draft version support
It doesn't look like you detail the draft version of JSON Schema you support.
Could you add this detial to the read-me please?

draft-7 is latest, but draft-8 is coming pretty soon.

Discussion:

Patch:
diff --git a/python_jsonschema_objects/__init__.py b/python_jsonschema_objects/__init__.py
index af24cad..c48747f 100644
--- a/python_jsonschema_objects/__init__.py
+++ b/python_jsonschema_objects/__init__.py
@@ -1,8 +1,10 @@
 import jsonschema
 from jsonschema import Draft4Validator
 from jsonschema.compat import iteritems
+import re
 import json
 import codecs
+import warnings
 import copy
 import os.path
 import inflection
@@ -22,6 +24,11 @@ __all__ = ["ObjectBuilder", "markdown_support", "ValidationError"]
 
 FILE = __file__
 
+SUPPORTED_VERSIONS = (
+    "http://json-schema.org/draft-03/schema",
+    "http://json-schema.org/draft-04/schema",
+)
+
 
 class ObjectBuilder(object):
     def __init__(self, schema_uri, resolved={}, resolver=None, validatorClass=None):
@@ -37,6 +44,17 @@ class ObjectBuilder(object):
             uri = os.path.normpath(FILE)
             self.basedir = os.path.dirname(uri)
 
+        if (
+            "$schema" in self.schema
+            and self.schema["$schema"] not in SUPPORTED_VERSIONS
+        ):
+            warnings.warn(
+                "Schema version {} not recognized. Some "
+                "keywords and features may not be supported.".format(
+                    self.schema["$schema"]
+                )
+            )
+
         self.resolver = resolver or jsonschema.RefResolver.from_schema(self.schema)
         self.resolver.handlers.update(
             {"file": self.relative_file_resolver, "memory": self.memory_resolver}
diff --git a/python_jsonschema_objects/examples/README.md b/python_jsonschema_objects/examples/README.md
index 5b0597a..8a359cf 100644
--- a/python_jsonschema_objects/examples/README.md
+++ b/python_jsonschema_objects/examples/README.md
@@ -1,10 +1,10 @@
 [![Build Status](https://travis-ci.org/cwacek/python-jsonschema-objects.svg?branch=master)](https://travis-ci.org/cwacek/python-jsonschema-objects)
-[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
 
 ## What
 
 python-jsonschema-objects provides an *automatic* class-based
-binding to JSON Schemas (draft-4 only) for use in python.
+binding to JSON Schemas for use in python. See [Draft Schema
+Support](#draft-schema-support) to see supported keywords
 
 For example, given the following schema:
 
@@ -400,8 +400,30 @@ schemas are unique.
 Tests are managed using the excellent Tox. Simply `pip install
 tox`, then `tox`.
 
+## Draft Keyword Support
+
+Most of draft-4 is supported, so only exceptions are noted
+in the table. Where a keyword functionality changed between
+drafts, the version that is supported is noted.
+
+The library will warn (but not throw an exception) if you give
+it an unsupported `$schema`
+
+| Keyword | supported | version |
+| --------| -----------| --------- |
+| $id     | true   | draft-6      |
+| propertyNames | false   | |
+| contains    | false   | |
+| const | false   |      |
+| required | true   | draft-4 |
+| examples | false |       |
+| format | false |       |
+
+
 ## Changelog
 
+*Please refer to Github releases for up to date changelogs.*
+
 **0.0.18**
 
 + Fix assignment to schemas defined using 'oneOf'


Test patch:
diff --git a/test/test_pytest.py b/test/test_pytest.py
index d36cdf6..415101d 100644
--- a/test/test_pytest.py
+++ b/test/test_pytest.py
@@ -1,5 +1,6 @@
 import pytest
 
+import warnings
 import json
 import six
 import jsonschema
@@ -10,6 +11,29 @@ import logging
 logging.basicConfig(level=logging.DEBUG)
 
 
+@pytest.mark.parametrize(
+    "version, warn",
+    [
+        ("http://json-schema.org/schema#", True),
+        ("http://json-schema.org/draft-03/schema", False),
+        ("http://json-schema.org/draft-04/schema", False),
+        ("http://json-schema.org/draft-06/schema", True),
+        ("http://json-schema.org/draft-07/schema", True),
+    ],
+)
+def test_warnings_on_schema_version(version, warn):
+    schema = {"$schema": version, "$id": "test", "type": "object", "properties": {}}
+
+    with warnings.catch_warnings(record=True) as w:
+        pjs.ObjectBuilder(schema)
+
+        if warn:
+            assert len(w) == 1
+            assert "Schema version %s not recognized" % version in str(w[-1].message)
+        else:
+            assert len(w) == 0, w[-1].message
+
+
 def test_schema_validation():
     """ Test that the ObjectBuilder validates the schema itself.
     """
@@ -18,7 +42,7 @@ def test_schema_validation():
         "$id": "test",
         "type": "object",
         "properties": {
-            "name": "string",
+            "name": "string",  #  <-- this is invalid
             "email": {"oneOf": [{"type": "string"}, {"type": "integer"}]},
         },
         "required": ["email"],