pytest_jsonschema_snapshot.tools.genson_addon.to_schema_converter

Json → Schema with optional format handling.

format_mode options

  • "on" – detect formats and let validators assert them (default).

  • "off" – ignore formats entirely.

  • "safe" – keep the annotations but embed a $vocabulary block that

    disables the draft‑2020‑12 format‑assertion vocabulary. This makes every format purely informational, regardless of validator settings.

Classes

JsonToSchemaConverter

A thin wrapper around genson.SchemaBuilder.

Module Contents

class JsonToSchemaConverter(
schema_uri: str = 'https://json-schema.org/draft/2020-12/schema',
*,
format_mode: _FormatMode = 'on',
)[source]

A thin wrapper around genson.SchemaBuilder.

add_object(obj: Any, path: str = 'root') None[source]

Modify the schema to accommodate an object.

Parameters:

obj – any object or scalar that can be serialized in JSON

to_schema() Dict[str, Any][source]

Generate a schema based on previous inputs.

Return type:

dict