diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a4cc0ae..3920f4d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,7 +37,7 @@ jobs: run: pnpm lint - name: Generate openapi types - run: pnpm gen:type + run: pnpm gen - name: Build run: pnpm build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8b8240a..0b2a44d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,7 +27,7 @@ jobs: run: pnpm install --frozen-lockfile - name: Generate openapi types - run: pnpm gen:type + run: pnpm gen - name: Build run: pnpm build diff --git a/flake.nix b/flake.nix index 03a93bf..ac892f1 100644 --- a/flake.nix +++ b/flake.nix @@ -21,6 +21,7 @@ devShells = forAllSystems (pkgs: { default = pkgs.mkShell { packages = with pkgs; [ + jq nodejs_24 pnpm ]; diff --git a/package.json b/package.json index b8bafcc..695f4a2 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,8 @@ "build": "tsdown", "test": "vitest", "gen:type": "openapi-typescript ./public.json -o ./gen/unsplash.d.ts", + "gen:alias": "jq --raw-output -f scripts/gen-alias.jq < public.json > ./gen/aliases.d.ts", + "gen": "pnpm gen:type && pnpm gen:alias", "lint": "oxlint", "format": "oxfmt", "typecheck": "tsc", diff --git a/scripts/gen-alias.jq b/scripts/gen-alias.jq new file mode 100644 index 0000000..7eeecb5 --- /dev/null +++ b/scripts/gen-alias.jq @@ -0,0 +1,4 @@ +"import { components } from \"./unsplash.d.ts\";", +(.components.schemas +| keys[] +| "export type \(. | sub("\\."; ""; "g")) = components[\"schemas\"][\"\(.)\"];") diff --git a/src/index.ts b/src/index.ts index 3c78a86..fa3988d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import createFetchClient, { type ClientOptions, type Client } from "openapi-fetch"; import type { paths } from "../gen/unsplash.d.ts"; // generated by openapi-typescript -export type { paths } from "../gen/unsplash.d.ts"; // generated by openapi-typescript +export type { paths, components } from "../gen/unsplash.d.ts"; // generated by openapi-typescript +export type * from "../gen/aliases.d.ts"; export type * from "openapi-fetch"; export { trackNonHotLinkedPhotoView } from "./beacon.ts";