Allow formats for non-string types

オープン
#86 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
38/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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?

主要言語
Python
スター
281
フォーク
35
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-jsonschema/hypothesis-jsonschema のほかの issue

python-jsonschema/hypothesis-jsonschema の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。