-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Add Pydantic schemas in OpenAPI annotations (#19408)
* Update schema to use discriminators and add Pydantic parser
- Loading branch information
Showing
11 changed files
with
1,008 additions
and
211 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 |
---|---|---|
@@ -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; | ||
} | ||
}); |
Oops, something went wrong.