137 lines
6.8 KiB
Python
137 lines
6.8 KiB
Python
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
|
|
|
|
# Extract OpenAPI spec from the dedicated spec generator binary
|
|
genrule(
|
|
name = "extract_openapi_spec",
|
|
srcs = [],
|
|
outs = ["openapi.json"],
|
|
cmd = """
|
|
$(location //databuild:openapi_spec_generator) > $@
|
|
""",
|
|
tools = [
|
|
"//databuild:openapi_spec_generator",
|
|
],
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
# TypeScript generator configuration
|
|
filegroup(
|
|
name = "typescript_generator_config",
|
|
srcs = ["typescript_generator_config.json"],
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
# Generate TypeScript client using OpenAPI Generator JAR
|
|
genrule(
|
|
name = "typescript_client",
|
|
srcs = [
|
|
":extract_openapi_spec",
|
|
":typescript_generator_config",
|
|
],
|
|
outs = [
|
|
"typescript_generated/src/apis/DefaultApi.ts",
|
|
"typescript_generated/src/apis/index.ts",
|
|
"typescript_generated/src/models/index.ts",
|
|
"typescript_generated/src/models/ActivityResponse.ts",
|
|
"typescript_generated/src/models/AnalyzeRequest.ts",
|
|
"typescript_generated/src/models/AnalyzeResponse.ts",
|
|
"typescript_generated/src/models/BuildEventSummary.ts",
|
|
"typescript_generated/src/models/BuildRequest.ts",
|
|
"typescript_generated/src/models/BuildRequestResponse.ts",
|
|
"typescript_generated/src/models/BuildStatusRequest.ts",
|
|
"typescript_generated/src/models/BuildStatusResponse.ts",
|
|
"typescript_generated/src/models/BuildSummary.ts",
|
|
"typescript_generated/src/models/BuildsListResponse.ts",
|
|
"typescript_generated/src/models/CancelBuildRequest.ts",
|
|
"typescript_generated/src/models/JobDailyStats.ts",
|
|
"typescript_generated/src/models/JobMetricsRequest.ts",
|
|
"typescript_generated/src/models/JobMetricsResponse.ts",
|
|
"typescript_generated/src/models/JobRunSummary.ts",
|
|
"typescript_generated/src/models/JobSummary.ts",
|
|
"typescript_generated/src/models/JobsListResponse.ts",
|
|
"typescript_generated/src/models/PartitionEventsRequest.ts",
|
|
"typescript_generated/src/models/PartitionEventsResponse.ts",
|
|
"typescript_generated/src/models/PartitionStatusRequest.ts",
|
|
"typescript_generated/src/models/PartitionStatusResponse.ts",
|
|
"typescript_generated/src/models/PartitionSummary.ts",
|
|
"typescript_generated/src/models/PartitionsListResponse.ts",
|
|
"typescript_generated/src/runtime.ts",
|
|
"typescript_generated/src/index.ts",
|
|
],
|
|
cmd = """
|
|
# Download OpenAPI Generator JAR
|
|
OPENAPI_JAR=/tmp/openapi-generator-cli.jar
|
|
if [ ! -f $$OPENAPI_JAR ]; then
|
|
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 temporary directory for generation
|
|
TEMP_DIR=$$(mktemp -d)
|
|
|
|
# Generate TypeScript client to temp directory
|
|
java -jar $$OPENAPI_JAR generate \
|
|
-i $(location :extract_openapi_spec) \
|
|
-g typescript-fetch \
|
|
-c $(location :typescript_generator_config) \
|
|
-o $$TEMP_DIR
|
|
|
|
# Copy generated files to expected output locations
|
|
cp $$TEMP_DIR/src/apis/DefaultApi.ts $(location typescript_generated/src/apis/DefaultApi.ts)
|
|
cp $$TEMP_DIR/src/apis/index.ts $(location typescript_generated/src/apis/index.ts)
|
|
cp $$TEMP_DIR/src/models/index.ts $(location typescript_generated/src/models/index.ts)
|
|
cp $$TEMP_DIR/src/models/ActivityResponse.ts $(location typescript_generated/src/models/ActivityResponse.ts)
|
|
cp $$TEMP_DIR/src/models/AnalyzeRequest.ts $(location typescript_generated/src/models/AnalyzeRequest.ts)
|
|
cp $$TEMP_DIR/src/models/AnalyzeResponse.ts $(location typescript_generated/src/models/AnalyzeResponse.ts)
|
|
cp $$TEMP_DIR/src/models/BuildEventSummary.ts $(location typescript_generated/src/models/BuildEventSummary.ts)
|
|
cp $$TEMP_DIR/src/models/BuildRequest.ts $(location typescript_generated/src/models/BuildRequest.ts)
|
|
cp $$TEMP_DIR/src/models/BuildRequestResponse.ts $(location typescript_generated/src/models/BuildRequestResponse.ts)
|
|
cp $$TEMP_DIR/src/models/BuildStatusRequest.ts $(location typescript_generated/src/models/BuildStatusRequest.ts)
|
|
cp $$TEMP_DIR/src/models/BuildStatusResponse.ts $(location typescript_generated/src/models/BuildStatusResponse.ts)
|
|
cp $$TEMP_DIR/src/models/BuildSummary.ts $(location typescript_generated/src/models/BuildSummary.ts)
|
|
cp $$TEMP_DIR/src/models/BuildsListResponse.ts $(location typescript_generated/src/models/BuildsListResponse.ts)
|
|
cp $$TEMP_DIR/src/models/CancelBuildRequest.ts $(location typescript_generated/src/models/CancelBuildRequest.ts)
|
|
cp $$TEMP_DIR/src/models/JobDailyStats.ts $(location typescript_generated/src/models/JobDailyStats.ts)
|
|
cp $$TEMP_DIR/src/models/JobMetricsRequest.ts $(location typescript_generated/src/models/JobMetricsRequest.ts)
|
|
cp $$TEMP_DIR/src/models/JobMetricsResponse.ts $(location typescript_generated/src/models/JobMetricsResponse.ts)
|
|
cp $$TEMP_DIR/src/models/JobRunSummary.ts $(location typescript_generated/src/models/JobRunSummary.ts)
|
|
cp $$TEMP_DIR/src/models/JobSummary.ts $(location typescript_generated/src/models/JobSummary.ts)
|
|
cp $$TEMP_DIR/src/models/JobsListResponse.ts $(location typescript_generated/src/models/JobsListResponse.ts)
|
|
cp $$TEMP_DIR/src/models/PartitionEventsRequest.ts $(location typescript_generated/src/models/PartitionEventsRequest.ts)
|
|
cp $$TEMP_DIR/src/models/PartitionEventsResponse.ts $(location typescript_generated/src/models/PartitionEventsResponse.ts)
|
|
cp $$TEMP_DIR/src/models/PartitionStatusRequest.ts $(location typescript_generated/src/models/PartitionStatusRequest.ts)
|
|
cp $$TEMP_DIR/src/models/PartitionStatusResponse.ts $(location typescript_generated/src/models/PartitionStatusResponse.ts)
|
|
cp $$TEMP_DIR/src/models/PartitionSummary.ts $(location typescript_generated/src/models/PartitionSummary.ts)
|
|
cp $$TEMP_DIR/src/models/PartitionsListResponse.ts $(location typescript_generated/src/models/PartitionsListResponse.ts)
|
|
cp $$TEMP_DIR/src/runtime.ts $(location typescript_generated/src/runtime.ts)
|
|
cp $$TEMP_DIR/src/index.ts $(location typescript_generated/src/index.ts)
|
|
""",
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
# TypeScript configuration for the client
|
|
ts_config(
|
|
name = "ts_config",
|
|
src = "tsconfig.json",
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
# Create a proper TypeScript project from the generated files
|
|
ts_project(
|
|
name = "typescript_lib",
|
|
srcs = [":typescript_client"],
|
|
allow_js = True,
|
|
declaration = True,
|
|
resolve_json_module = True,
|
|
transpiler = "tsc",
|
|
tsconfig = ":ts_config",
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
# Main TypeScript client target
|
|
filegroup(
|
|
name = "typescript",
|
|
srcs = [
|
|
":typescript_client",
|
|
],
|
|
visibility = ["//visibility:public"],
|
|
)
|