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 77511f3
Showing 1 changed file with 58 additions and 39 deletions.
97 changes: 58 additions & 39 deletions scripts/make_schemas.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
//import { createGenerator } from "npm:ts-json-schema-generator";
import console from "https://deno.land/std@0.177.0/node/console.ts";
import { exec } from "https://deno.land/x/exec/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 77511f3

Please sign in to comment.