Implement typescript client generator
Some checks are pending
/ setup (push) Waiting to run

This commit is contained in:
Stuart Axelbrooke 2025-07-08 22:21:36 -07:00
parent 9e8928b11a
commit a734c3c74b
2 changed files with 28 additions and 10 deletions

View file

@ -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"],
)

View file

@ -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
}