-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add codegen script and update generated code for 2024-07 (#140)
## Problem Need to update generated code for the upcoming 2024-07 API release. ## Solution This PR closely follows the approach used in the python and typescript repositories. - I create a new `codegen` directory to act as the home for everything codegen related. Inside this directory there are several things: - Git submodule of our apis repo - A `build-oas.sh` script which does everything to generate the code off the spec The script does the following: - Pulls in the latest from the apis repo - Builds the api repo to produce versioned spec files - Generates java code off the spec file. - Copies files into their respective places in `src/` Run the script like this, passing api version number as a positional argument: ```sh ./codegen/build-oas.sh 2024-07 ``` ## Non-generated changes The updated spec produced slightly different generated code than in the past. In order for the project to compile, I had to make some adjustments: - Options for metric type are now part of the `IndexModel` class instead of a standalone metric object, requiring a small refactor along the lines of `IndexMetric.COSINE.toString()` to `IndexModel.MetricEnum.COSINE.toString()` and similar for other metric types. - The name and organization of create index spec objects has changed. Now you use: - `IndexSpec` instead of `CreateInexRequestSpec`. - `PodSpec` instead of `CreateIndexRequestSpecPod` - `PodSpecMetadataConfig` instead of `CreateIndexRequestSpecPodMetadataConfig` ## Type of Change - [x] None of the above: Update generated core, adjust usage for new generated classes ## Test Plan Code builds and tests pass
- Loading branch information
Showing
62 changed files
with
2,505 additions
and
1,027 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "codegen/apis"] | ||
path = codegen/apis | ||
url = [email protected]:pinecone-io/apis.git |
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,87 @@ | ||
#!/bin/bash | ||
|
||
set -eux -o pipefail | ||
|
||
version=$1 # e.g. 2024-07 | ||
modules=("control") | ||
|
||
destination="src/main/java/org/openapitools" | ||
build_dir="gen" | ||
|
||
update_apis_repo() { | ||
echo "Updating apis repo" | ||
pushd codegen/apis | ||
git fetch | ||
git checkout main | ||
git pull | ||
just build | ||
popd | ||
} | ||
|
||
verify_spec_version() { | ||
local version=$1 | ||
echo "Verifying spec version $version exists in apis repo" | ||
if [ -z "$version" ]; then | ||
echo "Version is required" | ||
exit 1 | ||
fi | ||
|
||
verify_directory_exists "codegen/apis/_build/${version}" | ||
} | ||
|
||
verify_file_exists() { | ||
local filename=$1 | ||
if [ ! -f "$filename" ]; then | ||
echo "File does not exist at $filename" | ||
exit 1 | ||
fi | ||
} | ||
|
||
verify_directory_exists() { | ||
local directory=$1 | ||
if [ ! -d "$directory" ]; then | ||
echo "Directory does not exist at $directory" | ||
exit 1 | ||
fi | ||
} | ||
|
||
generate_client() { | ||
local module_name=$1 | ||
|
||
oas_file="codegen/apis/_build/${version}/${module_name}_${version}.oas.yaml" | ||
|
||
verify_file_exists $oas_file | ||
|
||
# Cleanup previous build files | ||
echo "Cleaning up previous build files" | ||
rm -rf "${build_dir}" | ||
|
||
# Generate client module | ||
docker run --rm -v $(pwd):/workspace openapitools/openapi-generator-cli:v7.0.1 generate \ | ||
--input-spec "/workspace/$oas_file" \ | ||
--generator-name java \ | ||
--additional-properties=dateLibrary='java8',disallowAdditionalPropertiesIfNotPresent=false \ | ||
--output "/workspace/${build_dir}" | ||
|
||
# Copy the generated module to the correct location | ||
rm -rf "${destination}/${module_name}" | ||
mkdir -p "${destination}/${module_name}" | ||
|
||
path_to_copy="${build_dir}/src/main/java/org/openapitools/client" | ||
cp -r $path_to_copy "${destination}/${module_name}" | ||
|
||
# Adjust package names in generated file | ||
find "${destination}/${module_name}" -name "*.java" | while IFS= read -r file; do | ||
sed -i '' "s/org\.openapitools\.client/org\.openapitools\.${module_name}\.client/g" "$file" | ||
done | ||
} | ||
|
||
update_apis_repo | ||
verify_spec_version $version | ||
|
||
rm -rf "${destination}" | ||
mkdir -p "${destination}" | ||
|
||
for module in "${modules[@]}"; do | ||
generate_client $module | ||
done |
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
Oops, something went wrong.