Skip to content

Latest commit

 

History

History
81 lines (56 loc) · 1.96 KB

File metadata and controls

81 lines (56 loc) · 1.96 KB

python-schema-generator

This package provides a tool that generates Pydantic v2 models for the events that are defined in the JSON schemas that are built as part of this repository. The generated Pydantic models can be used to validate and parse NHS Notify Digital Letters events.

Setup

Use make install-dev to install the necessary dependencies for this application.

Generating Models

In order for this tool to function, you must first build the JSON schemas for the Digital Letters events. This is done automatically when the make config command is run, but if you need to rebuild them for some reason the simplest approach is to run the make generate command from the root of this repository.

Using the Generator

Once the JSON schemas have been built, Pydantic models can be generated by running the following from this directory:

make generate

This will:

  • Read all JSON event schemas from schemas/digital-letters/2025-10-draft/events/
  • Generate Pydantic v2 models using datamodel-code-generator
  • Output the models to ../digital-letters-events/digital_letters_events/models/

Output Structure

Generated models are placed in the digital-letters-events package:

  • ../digital-letters-events/digital_letters_events/models/ - Individual Pydantic model files
  • ../digital-letters-events/digital_letters_events/models/__init__.py - Combined index for easy imports

Testing

Run tests using:

make test

For coverage reporting:

make coverage

Development

Prerequisites

  • Python 3.11+
  • pip or poetry for dependency management

Installing Development Dependencies

make install-dev

Running Tests

make test