CCM-12896: Generate Python Models#151
Merged
gareth-allan merged 20 commits intomainfrom Dec 17, 2025
Merged
Conversation
gareth-allan
commented
Dec 16, 2025
Ian-Hodges
reviewed
Dec 16, 2025
Ian-Hodges
approved these changes
Dec 17, 2025
tdroza-nhs
approved these changes
Dec 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a new application in
src/python-schema-generatorthat takes the JSON event schemas built from thedocs/src/cloudeventsdirectories and produces Pydantic V2 model classes for each event (using datamodel-code-generator).The Python model classes are generated in the existing
src/digital-letters-eventspackage, so that using them from Python uses the same package name as when using the Typescript types. Note that in order to be able to generate Pydantic classes from our schemas I have add to add a pre-generation step which uses the json-schema-merge-allof package to merge theallOfentries in the schemas, as datamodel-code-generator was otherwise producing empty classes to represent string fields that used anallOfproperty.Context
This change means that we will now always have Pydantic model classes for each event that we have a schema defined for in the digital letters domain, and that any changes to the event schemas will automatically result in updated code.
Validation
Made some example changes to convert the mesh-poll lambda to Python and have it validate incoming data using the generated models: feature/CCM-12896_generate_python_models...test/CCM-12896_demo_pydantic_usage#diff-8a1058fb005c5dc6646f1c7f79d30ef5e549d0122909d209b88c0a375ddfc6f1

My

nhs-notify-digital-lettersdirectory before runningmake config:My

nhs-notify-digital-lettersdirectory after runningmake config:Compared the runtime of the workflow for this branch:

Against a branch taken from main:

We can see that the build times are largely unchanged.
Dev Container
To verify the changes work in the dev container.
Ran

make cleanoutside of a container and verified there were no generated files insrc/digital-letters-events/digital_letters_events:Then reopened the workspace in a new

Notify Loaded 1.0.17dev container and verified the files had been generated (make configis run as part of the post-create command for the dev container:Type of changes
Checklist
Sensitive Information Declaration
To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.