-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add openapi code generation script and api versioning (#235)
## Problem We need a way to generate code from updated openapi specs ## Solution - Copy & modify overall approach used in python repository for similar purpose - Create new `codegen/` directory to be the home for code generation stuff - Use git submodules to get information from `apis` repo - Build using the `typescript-fetch` generator in the v7 openapi generator cli. This is the same as we have used in the past, to keep the diff somewhat small. - Build data and control planes separately and copy outputs into `src/pinecone-generated-ts-fetch` directory in source. This has been the traditional home for these generated files. - Since we're no longer mashing specs together ahead of code generation, I need to adjust import paths to find either `pinecone-generated-ts-fetch/control` or `pinecone-generated-ts-fetch/data` as appropriate - In addition to the default generated output, write a constant called `X_PINECONE_API_VERSION` in each generated module. This will be used when building header configuration with `X-Pinecone-Api-Version` for each request. ## Type of Change - [x] Infrastructure change (CI configs, etc) ## Test Plan `npm run generate:openapi`
- Loading branch information
Showing
145 changed files
with
6,322 additions
and
4,913 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 = git@github.com: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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
dist | ||
node_modules | ||
src/pinecone-generated-ts-fetch | ||
codegen |
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,81 @@ | ||
#!/bin/bash | ||
|
||
set -eux -o pipefail | ||
|
||
version=$1 # e.g. 2024-07 | ||
modules=("control" "data") | ||
|
||
destination="src/pinecone-generated-ts-fetch" | ||
build_dir="build" | ||
|
||
update_apis_repo() { | ||
echo "Updating apis repo" | ||
pushd codegen/apis | ||
git fetch | ||
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.0 generate \ | ||
--input-spec "/workspace/$oas_file" \ | ||
--generator-name typescript-fetch \ | ||
--output "/workspace/${build_dir}" | ||
|
||
# Copy the generated module to the correct location | ||
rm -rf "${destination}/${module_name}" | ||
mkdir -p "${destination}/${module_name}" | ||
cp -r ${build_dir}/* "${destination}/${module_name}" | ||
|
||
echo "export const X_PINECONE_API_VERSION = '${version}';" > ${destination}/${module_name}/api_version.ts | ||
echo "export * from './api_version';" >> ${destination}/${module_name}/index.ts | ||
} | ||
|
||
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
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
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
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.