From a734c3c74b0383258df1e5055ee20617d178bf22 Mon Sep 17 00:00:00 2001 From: Stuart Axelbrooke Date: Tue, 8 Jul 2025 22:21:36 -0700 Subject: [PATCH] Implement typescript client generator --- databuild/client/BUILD.bazel | 24 +++++++++++-------- .../client/typescript_generator_config.json | 14 +++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 databuild/client/typescript_generator_config.json diff --git a/databuild/client/BUILD.bazel b/databuild/client/BUILD.bazel index 9123573..7282d57 100644 --- a/databuild/client/BUILD.bazel +++ b/databuild/client/BUILD.bazel @@ -27,10 +27,10 @@ genrule( ":typescript_generator_config", ], outs = [ - "typescript_generated/apis/DefaultApi.ts", - "typescript_generated/models/index.ts", - "typescript_generated/runtime.ts", - "typescript_generated/index.ts", + "typescript_generated/src/apis/DefaultApi.ts", + "typescript_generated/src/models/index.ts", + "typescript_generated/src/runtime.ts", + "typescript_generated/src/index.ts", ], cmd = """ # Download OpenAPI Generator JAR @@ -39,18 +39,22 @@ genrule( curl -L -o $$OPENAPI_JAR https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.2.0/openapi-generator-cli-7.2.0.jar fi + # Create output directory + OUTPUT_DIR=$$(dirname $(location typescript_generated/src/index.ts)) + OUTPUT_PARENT=$$(dirname $$OUTPUT_DIR) + # Generate TypeScript client java -jar $$OPENAPI_JAR generate \ -i $(location :extract_openapi_spec) \ -g typescript-fetch \ -c $(location :typescript_generator_config) \ - -o $$(dirname $(location typescript_generated/index.ts)) + -o $$OUTPUT_PARENT - # Ensure all expected output files exist - touch $(location typescript_generated/apis/DefaultApi.ts) - touch $(location typescript_generated/models/index.ts) - touch $(location typescript_generated/runtime.ts) - touch $(location typescript_generated/index.ts) + # Copy generated files to expected output locations + [ -f $$OUTPUT_PARENT/src/apis/DefaultApi.ts ] && cp $$OUTPUT_PARENT/src/apis/DefaultApi.ts $(location typescript_generated/src/apis/DefaultApi.ts) || touch $(location typescript_generated/src/apis/DefaultApi.ts) + [ -f $$OUTPUT_PARENT/src/models/index.ts ] && cp $$OUTPUT_PARENT/src/models/index.ts $(location typescript_generated/src/models/index.ts) || touch $(location typescript_generated/src/models/index.ts) + [ -f $$OUTPUT_PARENT/src/runtime.ts ] && cp $$OUTPUT_PARENT/src/runtime.ts $(location typescript_generated/src/runtime.ts) || touch $(location typescript_generated/src/runtime.ts) + [ -f $$OUTPUT_PARENT/src/index.ts ] && cp $$OUTPUT_PARENT/src/index.ts $(location typescript_generated/src/index.ts) || touch $(location typescript_generated/src/index.ts) """, visibility = ["//visibility:public"], ) diff --git a/databuild/client/typescript_generator_config.json b/databuild/client/typescript_generator_config.json new file mode 100644 index 0000000..ba47474 --- /dev/null +++ b/databuild/client/typescript_generator_config.json @@ -0,0 +1,14 @@ +{ + "enumPropertyNaming": "camelCase", + "withInterfaces": true, + "useSingleRequestParameter": true, + "typescriptThreePlus": true, + "npmName": "databuild-client", + "npmVersion": "1.0.0", + "stringEnums": true, + "generateAliasAsModel": false, + "modelPropertyNaming": "camelCase", + "paramNaming": "camelCase", + "supportsES6": true, + "withoutRuntimeChecks": false +} \ No newline at end of file