From fae9a883c2bef314c9944dfe3a64d5927445ac40 Mon Sep 17 00:00:00 2001 From: Howard Askew <19271569+howaskew@users.noreply.github.com> Date: Wed, 21 Oct 2026 11:14:29 +0100 Subject: [PATCH 1/2] fix(typescript): Keep the extension prefix in @type for extension classes Generated TypeScript models used the unprefixed class name as the @type literal and in the Joi schema, so beta and test-interface classes were typed as e.g. 'Bar' and 'OpenBookingSimulateAction'. In JSON-LD these classes are only reachable through their extension prefix, and real data (including the data-models place_example_1.json example) uses 'beta:Bar', 'beta:Cafe', 'test:OpenBookingSimulateAction' and so on. OpenActive and schema.org classes keep their unprefixed names, as the OpenActive context defines terms for OpenActive classes and uses schema.org as its @vocab. This fixes two of the three tsc errors in the models-ts data-models example tests (place_example_1.spec.ts). Only the 8 beta and 16 test interface model files change. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/generators/typescript/index.js | 26 +++++++++++++++++++++ src/generators/typescript/model.ts.mustache | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/generators/typescript/index.js b/src/generators/typescript/index.js index 5d265d3..f766710 100644 --- a/src/generators/typescript/index.js +++ b/src/generators/typescript/index.js @@ -58,6 +58,32 @@ class TypeScript extends Generator { return true; } + /** + * The value of `@type` that identifies this model in JSON-LD data. + * + * OpenActive and schema.org types are written without a prefix, because the OpenActive context defines terms for + * OpenActive types and uses schema.org as its `@vocab`. Types from extensions (e.g. `beta:Bar` or + * `test:OpenBookingSimulateAction`) are only reachable through their extension's prefix, so the prefix is kept. + * + * @param {Model} model + */ + getJsonLdTypeName(model) { + const prefix = this.getPrefix(model.type); + if (prefix && prefix !== 'schema') { + return model.type; + } + return this.getPropNameFromFQP(model.type); + } + + createModelData(model, extensions) { + const data = super.createModelData(model, extensions); + return { + ...data, + /** e.g. Place, Thing, beta:Bar */ + jsonLdTypeName: this.getJsonLdTypeName(model), + }; + } + async renderModel(data) { this.modelTemplate = this.modelTemplate || diff --git a/src/generators/typescript/model.ts.mustache b/src/generators/typescript/model.ts.mustache index 5a2255d..5b47311 100644 --- a/src/generators/typescript/model.ts.mustache +++ b/src/generators/typescript/model.ts.mustache @@ -12,7 +12,7 @@ import * as schema from '../schema'; {{/classDoc}} */ export type {{{ className }}} = { - '@type': '{{{ modelTypePropName }}}'; + '@type': '{{{ jsonLdTypeName }}}'; '@context'?: string | string[]; {{#fieldList}} {{#if description }} @@ -58,7 +58,7 @@ export type {{{ className }}}OrSubClass = {{/classDoc}} */ export const {{{ className }}}JoiSchema = Joi.object({ - '@type': Joi.string().valid('{{{ modelTypePropName }}}').required(), + '@type': Joi.string().valid('{{{ jsonLdTypeName }}}').required(), '@context': Joi.alternatives().try([Joi.string(), Joi.array().items(Joi.string())]), {{#fieldList}} {{{ renderMemberName }}}: {{{ propertyJoiType }}}, From 490339f42beecf2481c1dd262f63521b17c36876 Mon Sep 17 00:00:00 2001 From: Howard Askew <19271569+howaskew@users.noreply.github.com> Date: Wed, 21 Oct 2026 13:18:06 +0100 Subject: [PATCH 2/2] ci: Build and test the generated TypeScript models in models-ts Add a test-ts job that runs the models-ts Update Data Model workflow with this models-lib ref: it generates the TypeScript models into models-ts, then builds and tests them, without creating a pull request. Generator changes that produce invalid TypeScript are then caught on the models-lib pull request instead of after a data-models release. Supersedes #69, and needs the models-ts workflow to accept workflow_call (models-ts ci/testable-build-v2, replacing models-ts #7). Also update actions/checkout and actions/setup-node to v4. Co-Authored-By: Claude Opus 5.5 (1M context) --- .github/workflows/generate-models.yaml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/generate-models.yaml b/.github/workflows/generate-models.yaml index aa15c77..0b51789 100644 --- a/.github/workflows/generate-models.yaml +++ b/.github/workflows/generate-models.yaml @@ -17,12 +17,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: path: models-lib - name: Use Node.js 18.17.1 - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: 18.17.1 @@ -37,3 +37,11 @@ jobs: run: npm start -- generate ${{ matrix.language }} --destination ../output/ working-directory: models-lib + # Generate the TypeScript models from this ref inside models-ts, then build and test them there, + # so that changes which produce invalid TypeScript are caught before they reach models-ts + test-ts: + needs: generate + uses: openactive/models-ts/.github/workflows/create-data-model-pr.yaml@main + with: + models-lib_ref: ${{ github.ref }} +