Allow formats for non-string types

Ouverte
#86 1 commentaire 0 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
38/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python
Domaine
backend

Piste de recherche

Start with the restriction in src/hypothesis_jsonschema/_from_schema.py around line 104, which the issue identifies as raising when a generated value is not a string. Read the format checker handling and its tests to see how format validation currently treats instance types. Done means non-string instances can use format checkers without raising, with tests covering the supported cases.

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

Description

As per Draft 4 and Draft 7 validation docs:

A format attribute can generally only validate a given set of instance types. If the type of the instance to validate is not in this set, validation for this format attribute and instance SHOULD succeed.

Newer drafts are more clear on this matter. For example, Draft 2020-12 additionally provides this:

All format attributes defined in this section apply to strings, but a format attribute can be specified to apply to any instance types defined in the data model defined in the core JSON Schema.

Even though, that the supported drafts (4, 6, 7) are a bit vague about instance types, I think that it could be treated as they allow non-string instances. The Open API spec explicitly uses it with int32, float, and other formats that are applicable for non-string types.

jsonschema also supports arbitrary types for its format checkers, at least based on its docstring:

        Check whether the instance conforms to the given format.
        Arguments:
            instance (*any primitive type*, i.e. str, number, bool):
                The instance to check

Currently, hypothesis-jsonschema raises an error if a strategy produces a non-string value.

What do you think about removing this restriction?

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

Préparer son environnement

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-jsonschema/hypothesis-jsonschema

Toutes les issues de python-jsonschema/hypothesis-jsonschema

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.