Skip to content

Commit 958e052

Browse files
authored
Merge pull request #1 from kodemore/improve-json-schema-support
Immutable validators + automated schema testing
2 parents 05ade19 + 0fdf562 commit 958e052

25 files changed

+824
-809
lines changed

.github/workflows/main.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
python-version: ${{ matrix.python-version }}
2424
- name: Install dependencies
2525
run: |
26-
sudo apt-get install -y libev-dev
2726
python -m pip install --upgrade pip
2827
pip install poetry
2928
poetry install

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
__pycache__
44
dist
55
.pytest_cache
6+
tests/fixtures/generated_dtos.py

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "tests/test_cases"]
2+
path = tests/test_cases
3+
url = https://github.com/json-schema-org/JSON-Schema-Test-Suite.git

opyapi/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.0"
1+
__version__ = "1.1.0"

opyapi/_iso_datetime.py

Lines changed: 0 additions & 165 deletions
This file was deleted.

opyapi/errors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class ValidationError(ValueError):
5-
code: str
5+
code: str = "validation_error"
66
message: str
77

88
def __init__(self, *args, **kwargs: Any):
@@ -156,3 +156,8 @@ class MaximumPropertiesValidationError(ObjectSizeValidationError):
156156
class DependencyValidationError(ObjectValidationError):
157157
code = "dependency_error"
158158
message = "Property `{property}` requires {dependencies} to be provided."
159+
160+
161+
class ContainsValidationError(ValidationError):
162+
code = "contains_error"
163+
message = "Failed to assert that `{value}` contains expected schema. {error}"

opyapi/json_schema.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from os import path
66
from typing import Any, Dict, Optional, Union, List, Set, ItemsView, KeysView, ValuesView
77
from typing import Protocol
8-
from datetime import datetime
98

109
from ._yaml_support import load_yaml
1110

@@ -199,14 +198,18 @@ def __init__(self, document: Any, id_: JsonUri = None):
199198

200199
self._id = id_
201200
self._document = document
201+
if self._document is True or self._document is False:
202+
self._ready = True
203+
return
204+
202205
self._ready = False
203206
self._current_path: List[Union[str, int]] = []
204207
self.anchors: Dict[str, str] = {}
205208

206209
@classmethod
207210
def from_file(cls, file_name: str) -> "JsonSchema":
208211
if not path.isfile(file_name):
209-
raise ValueError(f"passed file name `{file_name}` is not a valid file.")
212+
raise ValueError(f"Passed file name `{file_name}` is not a valid file.")
210213

211214
return JsonSchemaStore.get(JsonUri(f"file://{file_name}"))
212215

@@ -332,6 +335,15 @@ def __iter__(self):
332335
def __repr__(self) -> str:
333336
return f"JsonSchema({str(self._id)})"
334337

338+
def keys(self):
339+
return self.document.keys()
340+
341+
def values(self):
342+
return self.document.values()
343+
344+
def items(self):
345+
return self.document.items()
346+
335347

336348
class JsonSchemaStore:
337349
loaders: Dict[str, URILoader] = {

0 commit comments

Comments
 (0)