feat: Add automatic type generation
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
parent
33ccbe3e34
commit
cdd424e6ca
|
|
@ -2,7 +2,8 @@
|
||||||
"lock": false,
|
"lock": false,
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"start": "deno run -A --watch=static/,routes/ dev.ts",
|
"start": "deno run -A --watch=static/,routes/ dev.ts",
|
||||||
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx"
|
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
|
||||||
|
"types:nrk": "deno run -A generate-types.ts && deno fmt ./lib"
|
||||||
},
|
},
|
||||||
"imports": {
|
"imports": {
|
||||||
"$fresh/": "https://deno.land/x/fresh@1.6.8/",
|
"$fresh/": "https://deno.land/x/fresh@1.6.8/",
|
||||||
|
|
@ -13,7 +14,8 @@
|
||||||
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
|
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
|
||||||
"twind": "https://esm.sh/twind@0.16.17",
|
"twind": "https://esm.sh/twind@0.16.17",
|
||||||
"twind/": "https://esm.sh/twind@0.16.17/",
|
"twind/": "https://esm.sh/twind@0.16.17/",
|
||||||
"zod": "https://deno.land/x/zod@v3.22.4/mod.ts"
|
"zod": "https://deno.land/x/zod@v3.22.4/mod.ts",
|
||||||
|
"openapi-typescript": "npm:openapi-typescript@6.7.5"
|
||||||
},
|
},
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
import openapiTS from "openapi-typescript";
|
||||||
|
|
||||||
|
const nrkTypes: { filename: string; url: URL }[] = [
|
||||||
|
{
|
||||||
|
filename: "./lib/nrk-search.ts",
|
||||||
|
url: new URL("https://psapi.nrk.no/documentation/openapi/search-radio/v1/openapi.yml"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
filename: "./lib/nrk-catalog.ts",
|
||||||
|
url: new URL("https://psapi.nrk.no/documentation/openapi/programsider-radio/openapi.yml"),
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
async function generateTypes() {
|
||||||
|
for (const type of nrkTypes) {
|
||||||
|
const contents = await openapiTS(type.url);
|
||||||
|
|
||||||
|
await Deno.writeTextFile(new URL(type.filename, import.meta.url), contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (import.meta.main) {
|
||||||
|
await generateTypes();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue