Skip to content

Commit d01d51a

Browse files
authored
Add API version and custom headers (#41)
## Problem The SDK currently does not support adding a custom header for requests, which is necessary if we want to include API versions. ## Solution An API version number is added to the justfile and propagated throughout the sdk, to code generation and to `PineconeClient` to be sent with requests. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan All existing test cases pass.
1 parent e90d293 commit d01d51a

File tree

11 files changed

+300
-147
lines changed

11 files changed

+300
-147
lines changed

codegen/build-oas.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
#!/bin/bash
22

3+
version=$1
4+
5+
if [ -z "$version" ]; then
6+
echo "Version is required"
7+
exit 1
8+
fi
9+
310
pushd codegen/apis
411
just build
512
popd
613

714
outdir="openapi"
815

916
docker run --rm -v $(pwd):/workspace openapitools/openapi-generator-cli:v7.6.0 generate \
10-
--input-spec /workspace/codegen/apis/_build/2024-07/control_2024-07.oas.yaml \
17+
--input-spec /workspace/codegen/apis/_build/$version/control_$version.oas.yaml \
1118
--generator-name rust \
1219
--output /workspace/$outdir \
1320
--additional-properties "packageVersion=0.0.1"

codegen/build-proto.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
#!/bin/bash
22

3+
version=$1
4+
35
SCRIPT_DIR=$(dirname "$(realpath "$0")")
46
outdir="protos"
57

8+
if [ -z "$version" ]; then
9+
echo "Version is required"
10+
exit 1
11+
fi
12+
613
OUT_DIR=$SCRIPT_DIR/../$outdir
714

815
pushd $SCRIPT_DIR/apis
916
just build
1017
popd
1118

1219
pushd $SCRIPT_DIR/proto_build
13-
cargo run -- $OUT_DIR
20+
cargo run -- $OUT_DIR $version
1421
popd

codegen/proto_build/src/main.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ fn main() -> Result<(), Box<dyn Error>> {
55
let args: Vec<String> = std::env::args().collect();
66

77
let out_dir: &str;
8-
if args.len() > 1 {
8+
let version: &str;
9+
if args.len() == 3 {
910
out_dir = &args[1];
11+
version = &args[2];
1012
println!("OUT_DIR: {:?}", out_dir);
13+
println!("version: {:?}", version);
1114
} else {
12-
return Err("missing out_dir argument".into());
15+
return Err("Required 2 arguments: out_dir, version".into());
1316
}
1417

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

1721
// directory the main .proto file resides in
1822
let proto_dir = proto_path

justfile

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
build-openapi:
2-
./codegen/build-oas.sh
3-
cargo build -p openapi
1+
api_version := "2024-07"
42

5-
build-proto:
6-
./codegen/build-proto.sh
3+
# Generate version file
4+
generate-version:
5+
echo "/// Pinecone API version\npub const API_VERSION: &str = \"{{api_version}}\";" > pinecone_sdk/src/version.rs
6+
7+
# Build the OpenAPI and Protobuf definitions in `codegen/apis`
8+
build-apis:
9+
cd codegen/apis && just build
10+
11+
# Generate the control plane OpenAPI code based on the yaml files in `codegen/apis/_build`
12+
build-openapi: build-apis generate-version
13+
./codegen/build-oas.sh {{api_version}}
14+
15+
# Generate the data plane protobuf code based on the yaml files in `codegen/apis/_build`
16+
build-proto: build-apis generate-version
17+
./codegen/build-proto.sh {{api_version}}
18+
19+
# Generate all OpenAPI and protobuf code
20+
build-client: build-apis generate-version
21+
./codegen/build-oas.sh {{api_version}}
22+
./codegen/build-proto.sh {{api_version}}

pinecone_sdk/src/config.rs

-29
This file was deleted.

pinecone_sdk/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
77
#![warn(missing_docs)]
88

9-
/// Defines configurations for the Pinecone SDK.
10-
pub mod config;
11-
129
/// Defines the main entrypoint of the Pinecone SDK.
1310
pub mod pinecone;
1411

1512
/// Utility modules.
1613
pub mod utils;
14+
15+
/// Version information.
16+
pub mod version;

pinecone_sdk/src/pinecone/control.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl PineconeClient {
9191
};
9292

9393
// make openAPI call
94-
let res = manage_indexes_api::create_index(&self.openapi_config(), create_index_request)
94+
let res = manage_indexes_api::create_index(&self.openapi_config, create_index_request)
9595
.await
9696
.map_err(|e| PineconeError::from(e))?;
9797

@@ -191,7 +191,7 @@ impl PineconeClient {
191191
};
192192

193193
// make openAPI call
194-
let res = manage_indexes_api::create_index(&self.openapi_config(), create_index_request)
194+
let res = manage_indexes_api::create_index(&self.openapi_config, create_index_request)
195195
.await
196196
.map_err(|e| PineconeError::from(e))?;
197197

@@ -244,7 +244,7 @@ impl PineconeClient {
244244

245245
// Gets ready status of an index
246246
async fn is_ready(&self, name: &str) -> bool {
247-
let res = manage_indexes_api::describe_index(&self.openapi_config(), name).await;
247+
let res = manage_indexes_api::describe_index(&self.openapi_config, name).await;
248248
match res {
249249
Ok(index) => index.status.ready,
250250
Err(_) => false,
@@ -275,7 +275,7 @@ impl PineconeClient {
275275
/// ```
276276
pub async fn describe_index(&self, name: &str) -> Result<IndexModel, PineconeError> {
277277
// make openAPI call
278-
let res = manage_indexes_api::describe_index(&self.openapi_config(), name)
278+
let res = manage_indexes_api::describe_index(&self.openapi_config, name)
279279
.await
280280
.map_err(|e| PineconeError::from(e))?;
281281

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

@@ -356,7 +356,7 @@ impl PineconeClient {
356356

357357
// make openAPI call
358358
let res = manage_indexes_api::configure_index(
359-
&self.openapi_config(),
359+
&self.openapi_config,
360360
name,
361361
configure_index_request,
362362
)
@@ -390,7 +390,7 @@ impl PineconeClient {
390390
/// ```
391391
pub async fn delete_index(&self, name: &str) -> Result<(), PineconeError> {
392392
// make openAPI call
393-
let res = manage_indexes_api::delete_index(&self.openapi_config(), name)
393+
let res = manage_indexes_api::delete_index(&self.openapi_config, name)
394394
.await
395395
.map_err(|e| PineconeError::from(e))?;
396396

@@ -431,12 +431,10 @@ impl PineconeClient {
431431
};
432432

433433
// make openAPI call
434-
let res = manage_indexes_api::create_collection(
435-
&self.openapi_config(),
436-
create_collection_request,
437-
)
438-
.await
439-
.map_err(|e| PineconeError::from(e))?;
434+
let res =
435+
manage_indexes_api::create_collection(&self.openapi_config, create_collection_request)
436+
.await
437+
.map_err(|e| PineconeError::from(e))?;
440438

441439
Ok(res)
442440
}
@@ -464,7 +462,7 @@ impl PineconeClient {
464462
/// # }
465463
/// ```
466464
pub async fn describe_collection(&self, name: &str) -> Result<CollectionModel, PineconeError> {
467-
let res = manage_indexes_api::describe_collection(&self.openapi_config(), name)
465+
let res = manage_indexes_api::describe_collection(&self.openapi_config, name)
468466
.await
469467
.map_err(|e| PineconeError::from(e))?;
470468

@@ -494,7 +492,7 @@ impl PineconeClient {
494492
/// ```
495493
pub async fn list_collections(&self) -> Result<CollectionList, PineconeError> {
496494
// make openAPI call
497-
let res = manage_indexes_api::list_collections(&self.openapi_config())
495+
let res = manage_indexes_api::list_collections(&self.openapi_config)
498496
.await
499497
.map_err(|e| PineconeError::from(e))?;
500498

@@ -525,7 +523,7 @@ impl PineconeClient {
525523
/// ```
526524
pub async fn delete_collection(&self, name: &str) -> Result<(), PineconeError> {
527525
// make openAPI call
528-
let res = manage_indexes_api::delete_collection(&self.openapi_config(), name)
526+
let res = manage_indexes_api::delete_collection(&self.openapi_config, name)
529527
.await
530528
.map_err(|e| PineconeError::from(e))?;
531529

0 commit comments

Comments
 (0)