Errors are less verbose than they need to be
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Start in openapi_core/unmarshalling/schemas/unmarshallers.py, especially PrimitiveTypeUnmarshaller.validate, and inspect how the validator and collected errors are currently used. Determine how an opt-in detailed error path could coexist with aggregated validation, then verify that invalid schema values expose the underlying validation detail without breaking the existing behavior.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Thanks for the excellent library. I have a request. I'm currently getting error messages like the following for an invalid schema:
Traceback (most recent call last):
...
File ".../openapi_core/unmarshalling/schemas/unmarshallers.py", line 61, in validate
value, self.schema.type, schema_errors=errors)
openapi_core.unmarshalling.schemas.exceptions.InvalidSchemaValue: Value [{'id': 1, ...}] not valid for schema of type SchemaType.ARRAY: (<ValidationError: 'None for not nullable'>,)
This isn't very helpful, and it took me a while to figure out what was happening (I was running into https://github.com/OAI/OpenAPI-Specification/issues/1368). I managed it by hacking on openapi-core in my venv and adding the following:
diff --git openapi_core/unmarshalling/schemas/unmarshallers.py openapi_core/unmarshalling/schemas/unmarshallers.py
index b60f9c3..9b4ddea 100644
--- openapi_core/unmarshalling/schemas/unmarshallers.py
+++ openapi_core/unmarshalling/schemas/unmarshallers.py
@@ -54,6 +54,7 @@ class PrimitiveTypeUnmarshaller(object):
raise InvalidSchemaValue(value, self.schema.type)
def validate(self, value):
+ self.validator.validate(value)
errors_iter = self.validator.iter_errors(value)
errors = tuple(errors_iter)
if errors:
which gave me a far more helpful:
Traceback (most recent call last):
...
File ".../openapi_core/unmarshalling/schemas/unmarshallers.py", line 57, in validate
self.validator.validate(value)
File ".../jsonschema/validators.py", line 353, in validate
raise error
jsonschema.exceptions.ValidationError: None for not nullable
Failed validating 'nullable' in schema['items']['properties']['delegate']['allOf'][0]:
{'nullable': False,
'properties': {'email': {'format': 'email',
'minLength': 1,
'readOnly': True,
'title': 'Email address',
'type': 'string'},
'first_name': {'maxLength': 30,
'readOnly': True,
'title': 'First name',
'type': 'string'},
'id': {'readOnly': True,
'title': 'ID',
'type': 'integer'},
'last_name': {'maxLength': 150,
'readOnly': True,
'title': 'Last name',
'type': 'string'},
'url': {'format': 'uri',
'readOnly': True,
'title': 'URL',
'type': 'string'},
'username': {'maxLength': 150,
'minLength': 1,
'readOnly': True,
'title': 'Username',
'type': 'string'}},
'type': 'object'}
On instance[0]['delegate']:
None
I understand that you probably don't want to raise an exception immediately since you'd only see the first error, but would it be possible to opt-in to this behavior, or at least surface up the more verbose error message, assuming jsonschema provides a way to access this?
- Vorherrschende Sprache
- Python
- Sterne
- 368
- Forks
- 140
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python-openapi/openapi-core
-
kind/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
python-openapi/openapi-core#1188 · 2 Kommentare ·
-
kind/bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
python-openapi/openapi-core#1225 · 2 Kommentare ·
-
kind/bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 76/100
python-openapi/openapi-core#1212 ·
-
[Bug]: Query parameter validation fails to match empty string when listed as a valid enum value Offenkind/bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
python-openapi/openapi-core#1210 ·
-
kind/bug kind/bug/confirmed
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 58/100
python-openapi/openapi-core#1180 · 3 Kommentare ·
Alle Issues in python-openapi/openapi-core
Ähnliche Issues
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
canonical/paas-charm#368 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
tech debt
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
StevenBlack/hosts#3256 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
qualcomm/qai-appbuilder#275 ·