CCM-12896: Automatically Generate Typescript Types and Validator Code from Event JSON Schemas#138
Merged
gareth-allan merged 41 commits intomainfrom Dec 8, 2025
Merged
Conversation
gareth-allan
commented
Nov 28, 2025
gareth-allan
commented
Nov 28, 2025
gareth-allan
commented
Nov 28, 2025
gareth-allan
commented
Dec 3, 2025
nhsd-angel-pastor
previously approved these changes
Dec 4, 2025
sidnhs
previously approved these changes
Dec 4, 2025
nhsd-angel-pastor
previously approved these changes
Dec 4, 2025
tdroza-nhs
previously approved these changes
Dec 4, 2025
e84bd02
nhsd-angel-pastor
approved these changes
Dec 5, 2025
aidenvaines-cgi
approved these changes
Dec 8, 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/typescript-schema-generatorthat takes the JSON event schemas built from thedocs/src/cloudeventsdirectories and produces TypeScript type definitions for each event (usingjson-schema-to-typescript) as well as a JS validator function for each event (produced using Ajv's option to build standalone validation code).In order to generate the necessary code when it is needed as part of building/running tests, I've updated the
generate-dependenciesscript in the rootpackage.jsonso that it runs the minimal set ofmakecommands to build the "flattened" JSON schema for each event and then runs thegenerate-dependenciesscript in thesrc/typescript-schema-generatorworkspace (it actually runs it in all workspaces, but this is the only one with it defined) to generate types and validator code. I've also added ageneratetarget to the rootMakefilethat calls this NPM script and updated theconfigtarget to call it so that our standardmake configsetup command now generates the code for you.I've also updated the
mesh-pollplaceholder lambda, just as an example of how we might use these types/validators, and to prove that the package being build can be imported and used from the lambdas. #104 will replace this lambda with a Python version, so this isn't intended as a long-term change, but I also don't think there's any harm in merging it in.Context
This change means that we will now always have TypeScript types and validation code 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
My

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

nhs-notify-digital-lettersdirectory after runningmake config:A valid

ResourceSubmittedevent is accepted by the mesh-poll lambda:An invalid event causes an error:


Compared build times on this branch to another recently-built branch:


We can see that the build takes around two minutes longer, due to a slower "Test Stage" and slower deployment of the dynamic environment. This is because the auto-generated code is built in each of these stages.
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: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.