-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AND-285] Open API Code Gen V2 Integration (#1296)
* Reformat open api generated code Reformat StreamVideoClient Add api file after generating new open api code Exclude auto gen files from spotless Fix script generated code Add generated code Update the script to generate open api kotlin code Add script to generate open api kotlin code * Revert the changes from stream-video-android-core/build.gradle.kts * minor changes in ClosedCaptionManager * Add some changes in UT * Add missing moshi adapters * Add api dump * Skipping AudioRoomTest to pass in the CI * Rename package name from org.openapitools.client to io.getstream.android.video.generated * Update the generate open api script * Fix issues in renaming the package names * Fix linting * Fix linting * Fix linting * Fix UT * Exclude auto generated classes from kover * Ignore autogenerated from kover and sonar * Ignore autogenerated from kover and sonar * Ignore model class from kover * Ignore model class from kover * remove comments * ignore classes from sonarqube * ignore classes from sonarqube --------- Co-authored-by: Aleksandar Apostolov <[email protected]>
- Loading branch information
1 parent
28fa825
commit 476c6ff
Showing
410 changed files
with
17,774 additions
and
20,530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
# Default values | ||
REPO_URL="[email protected]:GetStream/chat.git" | ||
REFERENCE_TYPE="branch" | ||
REFERENCE_VALUE="feature/rahullohra/kotlin_open_api_generator" | ||
API_SERVICE_CLASS_NAME="ApiService" | ||
MODEL_PACKAGE="org.openapitools.autogenerated.client.models" | ||
API_SERVICE_PACKAGE="org.openapitools.autogenerated.client.apis" | ||
MODEL_DIR="models" | ||
API_SERVICE_DIR="apis" | ||
MOSHI_ADAPTER_DIR="infrastructure" | ||
MOSHI_ADAPTER_PACKAGE="org.openapitools.autogenerated.client.infrastructure" | ||
CLASSES_TO_SKIP="PrivacySettingsResponse,PrivacySettings" | ||
KEEP_CLASSES="WSAuthMessageRequest.kt" | ||
OUTPUT_CLIENT_PATH="./stream-video-android-core/src/main/kotlin/org/openapitools/client" | ||
|
||
# Parse key-value arguments | ||
for arg in "$@"; do | ||
case $arg in | ||
--repo-url=*) | ||
REPO_URL="${arg#*=}" | ||
shift | ||
;; | ||
--ref-type=*) | ||
REFERENCE_TYPE="${arg#*=}" | ||
shift | ||
;; | ||
--ref-value=*) | ||
REFERENCE_VALUE="${arg#*=}" | ||
shift | ||
;; | ||
--source-path=*) | ||
SOURCE_PATH="${arg#*=}" | ||
shift | ||
;; | ||
--output-spec=*) | ||
OUTPUT_SPEC_PATH="${arg#*=}" | ||
shift | ||
;; | ||
--output-client=*) | ||
OUTPUT_CLIENT_PATH="${arg#*=}" | ||
shift | ||
;; | ||
--model-package-name=*) | ||
MODEL_PACKAGE="${arg#*=}" | ||
shift | ||
;; | ||
--model-dir=*) | ||
MODEL_DIR="${arg#*=}" | ||
shift | ||
;; | ||
--api-service-dir=*) | ||
API_SERVICE_DIR="${arg#*=}" | ||
shift | ||
;; | ||
--api-service-package-name=*) | ||
API_SERVICE_PACKAGE="${arg#*=}" | ||
shift | ||
;; | ||
--api-service-class-name=*) | ||
API_SERVICE_CLASS_NAME="${arg#*=}" | ||
shift | ||
;; | ||
--moshi-adapters-dir=*) | ||
MOSHI_ADAPTER_DIR="${arg#*=}" | ||
shift | ||
;; | ||
--moshi-adapters-package-name=*) | ||
MOSHI_ADAPTER_PACKAGE="${arg#*=}" | ||
shift | ||
;; | ||
--classes-to-skip=*) | ||
CLASSES_TO_SKIP="${arg#*=}" | ||
shift | ||
;; | ||
--keep-classes=*) | ||
KEEP_CLASSES="${arg#*=}" | ||
shift | ||
;; | ||
*) | ||
echo "❌ ERROR: Unknown argument: $arg" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# Define working directories | ||
PROJECT_ROOT="$(dirname "$(realpath "$0")")/" | ||
BUILD_DIR="$PROJECT_ROOT/build" | ||
CLONE_DIR="$BUILD_DIR/openapi-generator-repo" | ||
PROGRAM_PATH="$CLONE_DIR/cmd/chat-manager" | ||
SPEC_FILE="$CLONE_DIR/releases/video-openapi-clientside.yaml" | ||
OUTPUT_DIR="$CLONE_DIR/output" | ||
SOURCE_PATH=CLONE_DIR | ||
OUTPUT_SPEC_PATH="$CLONE_DIR/releases/video-openapi-clientside" | ||
OUTPUT_CLIENT_ABSOLUTE_PATH="$PROJECT_ROOT$OUTPUT_CLIENT_PATH" | ||
|
||
# Set environment variables | ||
export APP_CONFIG_FILE="configs/test.yaml" | ||
|
||
#mkdir -p $OUTPUT_CLIENT_PATH //Create and delete files here TODO Rahul | ||
|
||
# Step 1: Delete/Create directory, and keep classes | ||
if [[ ! -d "$OUTPUT_CLIENT_PATH" ]]; then | ||
echo "Error: Directory $OUTPUT_CLIENT_PATH does not exist." | ||
# Function to create a directory if it doesn't exist | ||
create_directory() { | ||
local DIR_PATH=$OUTPUT_CLIENT_PATH | ||
|
||
if [ -z $DIR_PATH ]; then | ||
echo "Usage: create_directory <directory_path>" | ||
return 1 | ||
fi | ||
|
||
if [ ! -d "$DIR_PATH" ]; then | ||
echo "Directory does not exist. Creating: $DIR_PATH" | ||
mkdir -p $DIR_PATH | ||
echo "Directory created successfully." | ||
else | ||
echo "Directory already exists: $DIR_PATH" | ||
fi | ||
} | ||
create_directory $OUTPUT_CLIENT_PATH | ||
|
||
else | ||
# Function to check if a file should be kept | ||
should_keep() { | ||
local file_name=$(basename "$1") | ||
for keep in "${KEEP_CLASSES[@]}"; do | ||
echo "file_name = $file_name, keep = $keep" | ||
if [[ "$file_name" == "$keep" ]]; then | ||
return 0 # File should be kept | ||
fi | ||
done | ||
return 1 # File should be deleted | ||
} | ||
|
||
# Iterate through files in the directory recursively | ||
find "$OUTPUT_CLIENT_PATH" -type f | while read -r file; do | ||
if ! should_keep "$file"; then | ||
rm "$file" | ||
echo "Deleted: $file" | ||
else | ||
echo "Kept: $file" | ||
fi | ||
done | ||
|
||
# Remove empty directories | ||
find "$OUTPUT_CLIENT_PATH" -type d -empty -delete | ||
|
||
echo "🧹🧹Cleanup completed!" | ||
fi | ||
|
||
# Step 2: Clone the repository with shallow depth | ||
echo "🚀 Cloning repository: $REPO_URL (Type: $REFERENCE_TYPE, Value: $REFERENCE_VALUE)..." | ||
rm -rf "$CLONE_DIR" | ||
git clone --depth=1 --branch "$REFERENCE_VALUE" "$REPO_URL" "$CLONE_DIR" | ||
cd "$CLONE_DIR" | ||
|
||
|
||
# Step 3: Checkout to the correct branch, tag, or commit | ||
if [ "$REFERENCE_TYPE" == "branch" ]; then | ||
git checkout "$REFERENCE_VALUE" | ||
elif [ "$REFERENCE_TYPE" == "tag" ]; then | ||
git checkout "tags/$REFERENCE_VALUE" | ||
elif [ "$REFERENCE_TYPE" == "commit" ]; then | ||
git checkout "$REFERENCE_VALUE" | ||
else | ||
echo "❌ ERROR: Invalid reference type '$REFERENCE_TYPE'. Use 'branch', 'tag', or 'commit'." | ||
exit 1 | ||
fi | ||
|
||
# Step 4: Run the Go program with OpenAPI arguments | ||
echo "⚙️ Running OpenAPI Spec Generation..." | ||
go run ./cmd/chat-manager openapi generate-spec \ | ||
-products video \ | ||
-version v1 \ | ||
-clientside \ | ||
-output "$OUTPUT_SPEC_PATH" | ||
|
||
# Step 5: Generating Kt files | ||
echo "⚙️ Running OpenAPI Client Generation..." | ||
go run ./cmd/chat-manager openapi generate-client \ | ||
--language kotlin \ | ||
--spec "$OUTPUT_SPEC_PATH.yaml" \ | ||
--api-service-class-name "$API_SERVICE_CLASS_NAME" \ | ||
--api-service-package "$API_SERVICE_PACKAGE" \ | ||
--api-service-dir "$API_SERVICE_DIR" \ | ||
--model-package "$MODEL_PACKAGE" \ | ||
--model-dir "$MODEL_DIR" \ | ||
--moshi-adapters-dir "$MOSHI_ADAPTER_DIR" \ | ||
--moshi-adapters-package "$MOSHI_ADAPTER_PACKAGE" \ | ||
--classes-to-skip "$CLASSES_TO_SKIP" \ | ||
--output "$OUTPUT_CLIENT_ABSOLUTE_PATH" | ||
|
||
echo "👉 Your autogenerated files are available under $OUTPUT_CLIENT_ABSOLUTE_PATH" | ||
|
||
# Step 6: Delete files | ||
#rm -rf "$CLONE_DIR" | ||
|
||
echo "✅ OpenAPI Kotlin client generation completed successfully!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
tasks.register<Exec>("generateOpenApiClient") { | ||
group = "Custom" | ||
description = "Generates open api client" | ||
|
||
val repoUrl = project.findProperty("repoUrl") as? String ?: "[email protected]:GetStream/chat.git" | ||
val refType = project.findProperty("refType") as? String ?: "branch" | ||
val refValue = project.findProperty("refValue") as? String ?: "feature/rahullohra/kotlin_open_api_generator" | ||
|
||
val modelPackageName = project.findProperty("modelPackage") as? String ?: "org.openapitools.client.models" | ||
val modelsDir = project.findProperty("modelsDir") as? String ?: "models" | ||
|
||
val apiServicePackageName = project.findProperty("apiServicePackage") as? String ?: "org.openapitools.client.apis" | ||
val apiServiceClassName = project.findProperty("apiServiceClassName") as? String ?: "ProductvideoApi" | ||
val apiServiceDir = project.findProperty("apiServiceDir") as? String ?: "apis" | ||
|
||
val moshiAdaptersDir = project.findProperty("moshiAdaptersDir") as? String ?: "infrastructure" | ||
val moshiAdapterPackage = project.findProperty("moshiAdapterPackageName") as? String ?: "org.openapitools.client.infrastructure" | ||
|
||
val classesToSkip = project.findProperty("classesToSkip") as? String ?: "PrivacySettingsResponse,PrivacySettings,StopRTMPBroadcastsRequest" | ||
|
||
// val outputSpec = project.findProperty("outputSpec") as? String ?: "./releases/video-openapi-clientside" | ||
val outputClient = project.findProperty("outputClient") as? String ?: "stream-video-android-core/src/main/kotlin/org/openapitools/client/v3" | ||
val keepClasses = project.findProperty("keepClasses") as? String ?: "WSAuthMessageRequest.kt" | ||
val buildDir = project.layout.buildDirectory.asFile.get() | ||
|
||
println("outputClient = $outputClient") | ||
println("path = $path") | ||
println("buildDir = $buildDir") | ||
println("workingDir = $workingDir") | ||
println("projectDir = ${projectDir}") | ||
println("project root dir = ${project.rootDir}") | ||
println("Keep Classes = ${keepClasses}") | ||
|
||
// return@register | ||
|
||
workingDir = project.rootDir | ||
val scriptFile = file("${project.rootDir}/generate_openapi_v2.sh") | ||
|
||
// Make sure the script exists | ||
if (!scriptFile.exists()) { | ||
throw GradleException("❌ ERROR: Script not found at ${scriptFile.absolutePath}") | ||
} | ||
|
||
// Ensure the script has execute permission | ||
scriptFile.setExecutable(true) | ||
|
||
commandLine("sh", scriptFile.absolutePath, | ||
"--repo-url=$repoUrl", | ||
"--ref-type=$refType", | ||
"--ref-value=$refValue", | ||
"--model-package-name=$modelPackageName", | ||
"--model-dir=$modelsDir", | ||
"--api-service-package-name=$apiServicePackageName", | ||
"--api-service-class-name=$apiServiceClassName", | ||
"--api-service-dir=$apiServiceDir", | ||
"--moshi-adapters-dir=$moshiAdaptersDir", | ||
"--moshi-adapters-package-name=$moshiAdapterPackage", | ||
"--classes-to-skip=$classesToSkip", | ||
"--keep-classes=$keepClasses", | ||
"--output-client=$outputClient", | ||
) | ||
|
||
doLast { | ||
println("✅ OpenAPI Kotlin client generation completed via Gradle!") | ||
} | ||
} |
Oops, something went wrong.