Skip to content

Commit

Permalink
feat(api): Add Pydantic schemas in OpenAPI annotations (#19408)
Browse files Browse the repository at this point in the history
* Update schema to use discriminators and add Pydantic parser
  • Loading branch information
webjunkie authored Jan 12, 2024
1 parent ae85bae commit 456af51
Show file tree
Hide file tree
Showing 11 changed files with 1,008 additions and 211 deletions.
28 changes: 28 additions & 0 deletions bin/build-schema.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node

// replaces ts-json-schema-generator -f tsconfig.json --path 'frontend/src/queries/schema.ts' --no-type-check > frontend/src/queries/schema.json

import fs from "fs";
import stableStringify from "safe-stable-stringify";
import tsj from "ts-json-schema-generator";

/** @type {import('ts-json-schema-generator/dist/src/Config').Config} */
const config = {
...tsj.DEFAULT_CONFIG,
path: "frontend/src/queries/schema.ts",
tsconfig: "tsconfig.json",
discriminatorType: "open-api",
skipTypeCheck: true,
};

const output_path = "frontend/src/queries/schema.json";

const schema = tsj.createGenerator(config).createSchema(config.type);
const stringify = config.sortProps ? stableStringify : JSON.stringify;
const schemaString = (config.minify ? stringify(schema) : stringify(schema, null, 2));

fs.writeFile(output_path, schemaString, (err) => {
if (err) {
throw err;
}
});
Loading

0 comments on commit 456af51

Please sign in to comment.