Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Errors are less verbose than they need to be

Ouverte
#241 2 commentaires 5 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
35/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python
Domaine
api

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

area/unmarshalling kind/enhancement

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?

Langage dominant
Python
Étoiles
368
Forks
140
Métriques de merge des PR
Aucune PR mergée en 30 j

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de python-openapi/openapi-core

Toutes les issues de python-openapi/openapi-core

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.