pydantic icon indicating copy to clipboard operation
pydantic copied to clipboard

How about adding model tests for all of the json schema tests?

Open spacether opened this issue 2 years ago • 1 comments

Initial Checks

  • [X] I have searched Google & GitHub for similar requests and couldn't find anything
  • [X] I have read and followed the docs and still think this feature is missing

Description

How about adding model tests for all of the json schema tests?

They are at https://github.com/json-schema-org/JSON-Schema-Test-Suite/tree/main/tests

This will demonstrate the supported feature set

Affected Components

spacether avatar Aug 19 '22 15:08 spacether

Sounds for V2.

samuelcolvin avatar Aug 19 '22 20:08 samuelcolvin

What do you think @dmontagu ?

Kludex avatar Apr 29 '23 20:04 Kludex

If I'm understanding correctly, these tests seem to be checking whether instances match a specific JSON schema.

However, pydantic doesn't actually do any JSON schema validation, and (purposely) does not provide guarantees that its validation perfectly matches JSON schema, considering JSON schema is much less expressive. That's not a judgement against JSON schema — it's just a reflection of the fact that pydantic was designed to be more powerful — for example, being able to coerce types, transform inputs, apply general purpose logic during validation, etc. The JSON schema we generate is intended to be useful for things like generating API clients, etc., but is not tied to any aspect of runtime data validation in pydantic.

Because of this, I'm not sure this request makes sense — how would we make use of these tests in pydantic? That's not clear to me.

That said, I would like to add an array of tests that:

  1. the JSON schemas we produce are valid according to JSON schema
  2. data that validates into a BaseModel subclass passes validation against the JSON schema and vice versa
  3. instances of a BaseModel subclass serialize into data that passes validation against the JSON schema

However, I've already created a separate issue for this (don't remember the exact title, but it's along the lines of "use jsonschema for testing instances against their model schemas").

dmontagu avatar May 02 '23 00:05 dmontagu

Do you mean this issue? https://github.com/pydantic/pydantic/issues/5164

spacether avatar May 02 '23 03:05 spacether