Skip to content

Add API version and custom headers #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion codegen/build-oas.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#!/bin/bash

version=$1

if [ -z "$version" ]; then
echo "Version is required"
exit 1
fi

pushd codegen/apis
just build
popd

outdir="openapi"

docker run --rm -v $(pwd):/workspace openapitools/openapi-generator-cli:v7.6.0 generate \
--input-spec /workspace/codegen/apis/_build/2024-07/control_2024-07.oas.yaml \
--input-spec /workspace/codegen/apis/_build/$version/control_$version.oas.yaml \
--generator-name rust \
--output /workspace/$outdir \
--additional-properties "packageVersion=0.0.1"
9 changes: 8 additions & 1 deletion codegen/build-proto.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#!/bin/bash

version=$1

SCRIPT_DIR=$(dirname "$(realpath "$0")")
outdir="protos"

if [ -z "$version" ]; then
echo "Version is required"
exit 1
fi

OUT_DIR=$SCRIPT_DIR/../$outdir

pushd $SCRIPT_DIR/apis
just build
popd

pushd $SCRIPT_DIR/proto_build
cargo run -- $OUT_DIR
cargo run -- $OUT_DIR $version
popd
10 changes: 7 additions & 3 deletions codegen/proto_build/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ fn main() -> Result<(), Box<dyn Error>> {
let args: Vec<String> = std::env::args().collect();

let out_dir: &str;
if args.len() > 1 {
let version: &str;
if args.len() == 3 {
out_dir = &args[1];
version = &args[2];
println!("OUT_DIR: {:?}", out_dir);
println!("version: {:?}", version);
} else {
return Err("missing out_dir argument".into());
return Err("Required 2 arguments: out_dir, version".into());
}

let proto_path: &Path = "../apis/_build/2024-07/data_2024-07.proto".as_ref();
let proto_path = format!("../apis/_build/{version}/data_{version}.proto");
let proto_path: &Path = proto_path.as_ref();

// directory the main .proto file resides in
let proto_dir = proto_path
Expand Down
26 changes: 21 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
build-openapi:
./codegen/build-oas.sh
cargo build -p openapi
api_version := "2024-07"

build-proto:
./codegen/build-proto.sh
# Generate version file
generate-version:
echo "/// Pinecone API version\npub const API_VERSION: &str = \"{{api_version}}\";" > pinecone_sdk/src/version.rs

# Build the OpenAPI and Protobuf definitions in `codegen/apis`
build-apis:
cd codegen/apis && just build

# Generate the control plane OpenAPI code based on the yaml files in `codegen/apis/_build`
build-openapi: build-apis generate-version
./codegen/build-oas.sh {{api_version}}

# Generate the data plane protobuf code based on the yaml files in `codegen/apis/_build`
build-proto: build-apis generate-version
./codegen/build-proto.sh {{api_version}}

# Generate all OpenAPI and protobuf code
build-client: build-apis generate-version
./codegen/build-oas.sh {{api_version}}
./codegen/build-proto.sh {{api_version}}
29 changes: 0 additions & 29 deletions pinecone_sdk/src/config.rs

This file was deleted.

6 changes: 3 additions & 3 deletions pinecone_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

#![warn(missing_docs)]

/// Defines configurations for the Pinecone SDK.
pub mod config;

/// Defines the main entrypoint of the Pinecone SDK.
pub mod pinecone;

/// Utility modules.
pub mod utils;

/// Version information.
pub mod version;
30 changes: 14 additions & 16 deletions pinecone_sdk/src/pinecone/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl PineconeClient {
};

// make openAPI call
let res = manage_indexes_api::create_index(&self.openapi_config(), create_index_request)
let res = manage_indexes_api::create_index(&self.openapi_config, create_index_request)
.await
.map_err(|e| PineconeError::from(e))?;

Expand Down Expand Up @@ -191,7 +191,7 @@ impl PineconeClient {
};

// make openAPI call
let res = manage_indexes_api::create_index(&self.openapi_config(), create_index_request)
let res = manage_indexes_api::create_index(&self.openapi_config, create_index_request)
.await
.map_err(|e| PineconeError::from(e))?;

Expand Down Expand Up @@ -244,7 +244,7 @@ impl PineconeClient {

// Gets ready status of an index
async fn is_ready(&self, name: &str) -> bool {
let res = manage_indexes_api::describe_index(&self.openapi_config(), name).await;
let res = manage_indexes_api::describe_index(&self.openapi_config, name).await;
match res {
Ok(index) => index.status.ready,
Err(_) => false,
Expand Down Expand Up @@ -275,7 +275,7 @@ impl PineconeClient {
/// ```
pub async fn describe_index(&self, name: &str) -> Result<IndexModel, PineconeError> {
// make openAPI call
let res = manage_indexes_api::describe_index(&self.openapi_config(), name)
let res = manage_indexes_api::describe_index(&self.openapi_config, name)
.await
.map_err(|e| PineconeError::from(e))?;

Expand Down Expand Up @@ -306,7 +306,7 @@ impl PineconeClient {
/// ```
pub async fn list_indexes(&self) -> Result<IndexList, PineconeError> {
// make openAPI call
let res = manage_indexes_api::list_indexes(&self.openapi_config())
let res = manage_indexes_api::list_indexes(&self.openapi_config)
.await
.map_err(|e| PineconeError::from(e))?;

Expand Down Expand Up @@ -356,7 +356,7 @@ impl PineconeClient {

// make openAPI call
let res = manage_indexes_api::configure_index(
&self.openapi_config(),
&self.openapi_config,
name,
configure_index_request,
)
Expand Down Expand Up @@ -390,7 +390,7 @@ impl PineconeClient {
/// ```
pub async fn delete_index(&self, name: &str) -> Result<(), PineconeError> {
// make openAPI call
let res = manage_indexes_api::delete_index(&self.openapi_config(), name)
let res = manage_indexes_api::delete_index(&self.openapi_config, name)
.await
.map_err(|e| PineconeError::from(e))?;

Expand Down Expand Up @@ -431,12 +431,10 @@ impl PineconeClient {
};

// make openAPI call
let res = manage_indexes_api::create_collection(
&self.openapi_config(),
create_collection_request,
)
.await
.map_err(|e| PineconeError::from(e))?;
let res =
manage_indexes_api::create_collection(&self.openapi_config, create_collection_request)
.await
.map_err(|e| PineconeError::from(e))?;

Ok(res)
}
Expand Down Expand Up @@ -464,7 +462,7 @@ impl PineconeClient {
/// # }
/// ```
pub async fn describe_collection(&self, name: &str) -> Result<CollectionModel, PineconeError> {
let res = manage_indexes_api::describe_collection(&self.openapi_config(), name)
let res = manage_indexes_api::describe_collection(&self.openapi_config, name)
.await
.map_err(|e| PineconeError::from(e))?;

Expand Down Expand Up @@ -494,7 +492,7 @@ impl PineconeClient {
/// ```
pub async fn list_collections(&self) -> Result<CollectionList, PineconeError> {
// make openAPI call
let res = manage_indexes_api::list_collections(&self.openapi_config())
let res = manage_indexes_api::list_collections(&self.openapi_config)
.await
.map_err(|e| PineconeError::from(e))?;

Expand Down Expand Up @@ -525,7 +523,7 @@ impl PineconeClient {
/// ```
pub async fn delete_collection(&self, name: &str) -> Result<(), PineconeError> {
// make openAPI call
let res = manage_indexes_api::delete_collection(&self.openapi_config(), name)
let res = manage_indexes_api::delete_collection(&self.openapi_config, name)
.await
.map_err(|e| PineconeError::from(e))?;

Expand Down
Loading
Loading