This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <bdarcus@gmail.com>
- Loading branch information
Showing
1 changed file
with
61 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
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!"); |