diff --git a/deno.json b/deno.json index 9c8e3f6..ec2296c 100644 --- a/deno.json +++ b/deno.json @@ -2,7 +2,8 @@ "lock": false, "tasks": { "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": { "$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", "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": { "jsx": "react-jsx", diff --git a/generate-types.ts b/generate-types.ts new file mode 100644 index 0000000..231bdc1 --- /dev/null +++ b/generate-types.ts @@ -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(); +}