Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
chore(schemas): fix schema generation bug
Browse files Browse the repository at this point in the history
Post-process the schema file to workaround upstream bug that seems
common in schema generators.

Refs: #146

Signed-off-by: Bruce D'Arcus <bdarcus@gmail.com>
  • Loading branch information
bdarcus committed May 26, 2023
1 parent d06a103 commit 29d9288
Showing 1 changed file with 61 additions and 39 deletions.
100 changes: 61 additions & 39 deletions scripts/make_schemas.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,66 @@
//import { createGenerator } from "npm:ts-json-schema-generator";
//import * as path from "https://deno.land/std/path/mod.ts";
//import { DenoDir } from "https://deno.land/x/deno_cache@0.4.1/mod.ts";
import console from "https://deno.land/std@0.177.0/node/console.ts";
import { exec } from "https://deno.land/x/exec/mod.ts";
//import { sleep } from "https://deno.land/x/sleep/mod.ts";

const configs = [
{
path: "./npm/src/style.ts",
type: "Style",
tsconfig: "tsconfig.json",
},

{
path: "./npm/src/reference.ts",
type: "InputReference",
tsconfig: "tsconfig.json",
},
{
path: "./npm/src/bibliography.ts",
type: "InputBibliography",
tsconfig: "tsconfig.json",
},
{
path: "./npm/src/citation.ts",
type: "Citation",
tsconfig: "tsconfig.json",
},
];

console.log("");

for (const config of configs) {
// need to run on npm code, so make sure to run the make_npm.ts script first
const schemaFileName = `./schemas/csl-${
config["type"].toLowerCase()
}-schema.json`;
const command =
`typescript-json-schema --no-type-check ${config.path} ${config.type} --out ${schemaFileName}`;

console.log(`[schemas] Generating ${schemaFileName}...`);
// console.log(command);

exec(command);
function generateSchemas() {
console.log("");

const configs = [
{
path: "./npm/src/style.ts",
type: "Style",
tsconfig: "tsconfig.json",
},

{
path: "./npm/src/reference.ts",
type: "InputReference",
tsconfig: "tsconfig.json",
},
{
path: "./npm/src/bibliography.ts",
type: "InputBibliography",
tsconfig: "tsconfig.json",
},
{
path: "./npm/src/citation.ts",
type: "Citation",
tsconfig: "tsconfig.json",
},
];

for (const config of configs) {
// need to run on npm code, so make sure to run the make_npm.ts script first
const schemaFileName = `./schemas/csl-${
config["type"].toLowerCase()
}-schema.json`;
const command =
`typescript-json-schema --no-type-check ${config.path} ${config.type} --out ${schemaFileName}`;

console.log(`[schemas] Generating ${schemaFileName} ...`);

exec(command);
}
}

function fixSchemas() {
console.log("[schemas] Fixing style schema ...");
const schemaFileName = `./schemas/csl-style-schema.json`;
const schema = JSON.parse(Deno.readTextFileSync(schemaFileName));

// why doesn't this work???
schema.properties.templates = {
type: "object",
patternProperties: {
"": { type: "#/definitions/InputReference" },
},
};
Deno.writeTextFileSync(schemaFileName, JSON.stringify(schema));
}

generateSchemas();
fixSchemas();

console.log("[schemas] Complete!");

0 comments on commit 29d9288

Please sign in to comment.