Skip to content

Commit 1592c18

Browse files
Store additional information in the schema (name and deref) and also store schema in errors. This gives us the ability to provide additional context when an error occurs, for example if the schema is named then the name of the schema, or if the yaml is parsed with ruamel.yaml we can show the line and column number that generated the error.
1 parent 395f68b commit 1592c18

File tree

6 files changed

+88
-46
lines changed

6 files changed

+88
-46
lines changed

Diff for: openapi_core/schema/schemas/exceptions.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import attr
44

55

6+
@attr.s
67
class OpenAPISchemaError(OpenAPIMappingError):
7-
pass
8+
schema = attr.ib()
89

910

1011
@attr.s
@@ -77,3 +78,19 @@ class MultipleOneOfSchema(OpenAPISchemaError):
7778

7879
def __str__(self):
7980
return "Exactly one schema type {0} should be valid, more than one found".format(self.type)
81+
82+
83+
@attr.s
84+
class InvalidSchema(OpenAPISchemaError):
85+
msg = attr.ib()
86+
87+
def __str__(self):
88+
return self.msg
89+
90+
91+
@attr.s
92+
class InvalidFormat(OpenAPISchemaError):
93+
msg = attr.ib()
94+
95+
def __str__(self):
96+
return self.msg

Diff for: openapi_core/schema/schemas/factories.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SchemaFactory(object):
1313
def __init__(self, dereferencer):
1414
self.dereferencer = dereferencer
1515

16-
def create(self, schema_spec):
16+
def create(self, schema_spec, schema_name=''):
1717
schema_deref = self.dereferencer.dereference(schema_spec)
1818

1919
schema_type = schema_deref.get('type', None)
@@ -75,6 +75,7 @@ def create(self, schema_spec):
7575
exclusive_maximum=exclusive_maximum,
7676
exclusive_minimum=exclusive_minimum,
7777
min_properties=min_properties, max_properties=max_properties,
78+
schema_name=schema_name, schema_deref=schema_deref,
7879
)
7980

8081
@property

Diff for: openapi_core/schema/schemas/generators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ def generate(self, schemas_spec):
1616
schemas_deref = self.dereferencer.dereference(schemas_spec)
1717

1818
for schema_name, schema_spec in iteritems(schemas_deref):
19-
schema, _ = self.schemas_registry.get_or_create(schema_spec)
19+
schema, _ = self.schemas_registry.get_or_create(schema_spec, schema_name)
2020
yield schema_name, schema

0 commit comments

Comments
 (0)