diff --git a/oxide-openapi-gen-ts/package-lock.json b/oxide-openapi-gen-ts/package-lock.json index e3e9a87..9a9faa6 100644 --- a/oxide-openapi-gen-ts/package-lock.json +++ b/oxide-openapi-gen-ts/package-lock.json @@ -1,12 +1,12 @@ { "name": "@oxide/openapi-gen-ts", - "version": "0.1.12", + "version": "0.1.13", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@oxide/openapi-gen-ts", - "version": "0.1.12", + "version": "0.1.13", "license": "MPL-2.0", "dependencies": { "minimist": "^1.2.8", diff --git a/oxide-openapi-gen-ts/package.json b/oxide-openapi-gen-ts/package.json index 44ba88a..46d309a 100644 --- a/oxide-openapi-gen-ts/package.json +++ b/oxide-openapi-gen-ts/package.json @@ -1,6 +1,6 @@ { "name": "@oxide/openapi-gen-ts", - "version": "0.1.12", + "version": "0.1.13", "description": "OpenAPI client generator used to generate Oxide TypeScript SDK", "keywords": [ "oxide", diff --git a/oxide-openapi-gen-ts/src/index.ts b/oxide-openapi-gen-ts/src/index.ts index febc66d..c9e0d47 100644 --- a/oxide-openapi-gen-ts/src/index.ts +++ b/oxide-openapi-gen-ts/src/index.ts @@ -15,6 +15,7 @@ import { generateMSWHandlers } from "./client/msw-handlers"; import { generateTypeTests } from "./client/type-tests"; import { generateZodValidators } from "./client/zodValidators"; import { resolve } from "node:path"; +import { existsSync } from "node:fs"; import parseArgs from "minimist"; function helpAndExit(msg?: string): never { @@ -47,10 +48,13 @@ function parseFeatures(featuresArg: string | undefined) { helpAndExit(`Unrecognized feature '${feature}'.`); } } + + const validated = features as Feature[]; + return { - zod: features.includes("zod"), - msw: features.includes("msw"), - typetests: features.includes("typetests"), + zod: validated.includes("zod"), + msw: validated.includes("msw"), + typetests: validated.includes("typetests"), }; } @@ -58,6 +62,13 @@ async function generate(specFile: string, destDir: string, features: Features) { // destination directory is resolved relative to CWD const destDirAbs = resolve(process.cwd(), destDir); + if (!existsSync(destDirAbs)) { + throw new Error(`Error: destination directory does not exist. + Argument given: ${destDirAbs} + Resolved path: ${destDirAbs} +`); + } + const rawSpec = await SwaggerParser.parse(specFile); if (!("openapi" in rawSpec) || !rawSpec.openapi.startsWith("3.0")) { throw new Error("Only OpenAPI 3.0 is currently supported"); diff --git a/tools/gen.sh b/tools/gen.sh index bf5bec3..8baf909 100755 --- a/tools/gen.sh +++ b/tools/gen.sh @@ -19,5 +19,5 @@ SPEC_FILE="./spec.json" # TODO: we could get rid of this DL if a test didn't rely on it curl --fail "$SPEC_URL" -o $SPEC_FILE -npx tsx "$ROOT_DIR/oxide-openapi-gen-ts/src/index.ts" $SPEC_FILE $DEST_DIR -npx prettier --write --log-level error "$DEST_DIR" +npx tsx "$ROOT_DIR/oxide-openapi-gen-ts/src/index.ts" $SPEC_FILE $DEST_DIR --features zod,msw,typetests +npx prettier@3.2.5 --write --log-level error "$DEST_DIR"