From 6a8515b0a5461a0ea8b8fc95f5234cf91178041d Mon Sep 17 00:00:00 2001 From: Bruce D'Arcus Date: Fri, 26 May 2023 11:10:15 -0400 Subject: [PATCH] chore(schemas): fix schema generation bug Post-process the schema file to workaround upstream bug that seems common in schema generators. Refs: #146 Signed-off-by: Bruce D'Arcus --- scripts/make_schemas.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/make_schemas.ts b/scripts/make_schemas.ts index 93189593..3f2289ba 100644 --- a/scripts/make_schemas.ts +++ b/scripts/make_schemas.ts @@ -1,6 +1,9 @@ //import { createGenerator } from "npm:ts-json-schema-generator"; import { exec } from "https://deno.land/x/exec/mod.ts"; +/** + * An array of objects containing the path to the TypeScript file, the type to generate a schema for, and the path to the tsconfig.json file. + */ const configs = [ { path: "./npm/src/style.ts", @@ -39,6 +42,20 @@ for (const config of configs) { // console.log(command); exec(command); + + if (config.type === "Style") { + console.log("[schemas] Fixing CSL style schema ..."); + // why am I getting a file not found error here? + const schema = JSON.parse(await Deno.readTextFile(schemaFileName)); + // modify this property to workaround upstream bug + delete schema.properties.templates.$ref; + schema.properties.templates.type = "object"; + schema.properties.templates.patternProperties = { + "": { type: "#/definitions/InputReference" } + }; + + await Deno.writeTextFile(schemaFileName, JSON.stringify(schema)); + } } console.log("[schemas] Complete!");