Skip to content

Commit

Permalink
Generate client using v0.6.0 openapi_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
walsha2 committed Oct 23, 2023
1 parent fbc7f76 commit c99bb7a
Show file tree
Hide file tree
Showing 40 changed files with 83 additions and 92 deletions.
95 changes: 43 additions & 52 deletions lib/src/generated/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,26 @@ class PineconeClientException implements io.HttpException {

/// Client for Pinecone API
///
/// `host`: Override host URL - else defaults to server host defined in spec
/// `baseUrl`: Override baseUrl URL - else defaults to server url defined in spec
///
/// `client`: Override HTTP client to use for requests
class PineconeClient {
PineconeClient({
this.apiKey = '',
String? host,
String? baseUrl,
http.Client? client,
}) {
}) : assert(
baseUrl == null || baseUrl.startsWith('http'),
'baseUrl must start with http',
) {
// Ensure trailing slash is removed from baseUrl
this.baseUrl = baseUrl?.replaceAll(RegExp(r'/$'), '');
// Create a retry client
this.client = RetryClient(client ?? http.Client());
// Ensure trailing slash is removed from host
this.host = host?.replaceAll(RegExp(r'/$'), '');
}

/// User provided override for host URL
late final String? host;
/// User provided override for baseUrl URL
late final String? baseUrl;

/// HTTP client for requests
late final http.Client client;
Expand Down Expand Up @@ -115,7 +118,7 @@ class PineconeClient {

/// Reusable request method
Future<http.Response> _request({
required String host,
required String baseUrl,
required String path,
required HttpMethod method,
Map<String, dynamic> queryParams = const {},
Expand All @@ -125,15 +128,14 @@ class PineconeClient {
String responseType = '',
Object? body,
}) async {
// Override with the user provided host
host = this.host ?? host;
// Override with the user provided baseUrl
baseUrl = this.baseUrl ?? baseUrl;

// Ensure a host is provided
if (host.isEmpty) {
throw Exception(
'\n\nHost is required, but none defined in spec or provided by user\n',
);
}
// Ensure a baseUrl is provided
assert(
baseUrl.isNotEmpty,
'baseUrl is required, but none defined in spec or provided by user',
);

// Ensure query parameters are strings or iterable of strings
queryParams = queryParams.map((key, value) {
Expand All @@ -145,30 +147,13 @@ class PineconeClient {
});

// Build the request URI
final secure = Uri.parse(host).scheme == 'https';
Uri uri;
String authority;
if (host.contains('http')) {
authority = Uri.parse(host).authority;
} else {
authority = Uri.parse(Uri.https(host).toString()).authority;
}
if (secure) {
uri = Uri.https(
authority,
path,
queryParams.isEmpty ? null : queryParams,
);
} else {
uri = Uri.http(
authority,
path,
queryParams.isEmpty ? null : queryParams,
);
Uri uri = Uri.parse(baseUrl + path);
if (queryParams.isNotEmpty) {
uri = uri.replace(queryParameters: queryParams);
}

// Build the headers
Map<String, String> headers = {}..addAll(headerParams);
Map<String, String> headers = {...headerParams};

// Define the request type being sent to server
if (requestType.isNotEmpty) {
Expand Down Expand Up @@ -263,7 +248,7 @@ class PineconeClient {
String environment = 'us-west1-gcp-free',
}) async {
final r = await _request(
host: 'https://controller.${environment}.pinecone.io',
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/collections',
method: HttpMethod.get,
isMultipart: false,
Expand Down Expand Up @@ -294,7 +279,7 @@ class PineconeClient {
required CreateCollectionRequest request,
}) async {
final _ = await _request(
host: 'https://controller.${environment}.pinecone.io',
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/collections',
method: HttpMethod.post,
isMultipart: false,
Expand Down Expand Up @@ -325,7 +310,7 @@ class PineconeClient {
required String collectionName,
}) async {
final r = await _request(
host: 'https://controller.${environment}.pinecone.io',
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/collections/$collectionName',
method: HttpMethod.get,
isMultipart: false,
Expand Down Expand Up @@ -356,7 +341,7 @@ class PineconeClient {
required String collectionName,
}) async {
final _ = await _request(
host: 'https://controller.${environment}.pinecone.io',
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/collections/$collectionName',
method: HttpMethod.delete,
isMultipart: false,
Expand All @@ -383,7 +368,7 @@ class PineconeClient {
String environment = 'us-west1-gcp-free',
}) async {
final r = await _request(
host: 'https://controller.${environment}.pinecone.io',
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/databases',
method: HttpMethod.get,
isMultipart: false,
Expand Down Expand Up @@ -414,7 +399,7 @@ class PineconeClient {
required CreateIndexRequest request,
}) async {
final _ = await _request(
host: 'https://controller.${environment}.pinecone.io',
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/databases',
method: HttpMethod.post,
isMultipart: false,
Expand Down Expand Up @@ -445,7 +430,7 @@ class PineconeClient {
required String indexName,
}) async {
final r = await _request(
host: 'https://controller.${environment}.pinecone.io',
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/databases/$indexName',
method: HttpMethod.get,
isMultipart: false,
Expand Down Expand Up @@ -476,7 +461,7 @@ class PineconeClient {
required String indexName,
}) async {
final _ = await _request(
host: 'https://controller.${environment}.pinecone.io',
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/databases/$indexName',
method: HttpMethod.delete,
isMultipart: false,
Expand Down Expand Up @@ -509,7 +494,7 @@ class PineconeClient {
required ConfigureIndexRequest request,
}) async {
final _ = await _request(
host: 'https://controller.${environment}.pinecone.io',
baseUrl: 'https://controller.${environment}.pinecone.io',
path: '/databases/$indexName',
method: HttpMethod.patch,
isMultipart: false,
Expand Down Expand Up @@ -546,7 +531,8 @@ class PineconeClient {
IndexStatsRequest? request,
}) async {
final r = await _request(
host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/describe_index_stats',
method: HttpMethod.post,
isMultipart: false,
Expand Down Expand Up @@ -584,7 +570,8 @@ class PineconeClient {
required QueryRequest request,
}) async {
final r = await _request(
host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/query',
method: HttpMethod.post,
isMultipart: false,
Expand Down Expand Up @@ -622,7 +609,8 @@ class PineconeClient {
required DeleteRequest request,
}) async {
final _ = await _request(
host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/vectors/delete',
method: HttpMethod.post,
isMultipart: false,
Expand Down Expand Up @@ -662,7 +650,8 @@ class PineconeClient {
String? namespace,
}) async {
final r = await _request(
host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/vectors/fetch',
method: HttpMethod.get,
isMultipart: false,
Expand Down Expand Up @@ -703,7 +692,8 @@ class PineconeClient {
required UpdateRequest request,
}) async {
final _ = await _request(
host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/vectors/update',
method: HttpMethod.post,
isMultipart: false,
Expand Down Expand Up @@ -740,7 +730,8 @@ class PineconeClient {
required UpsertRequest request,
}) async {
final r = await _request(
host: 'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
baseUrl:
'https://${indexName}-${projectId}.svc.${environment}.pinecone.io',
path: '/vectors/upsert',
method: HttpMethod.post,
isMultipart: false,
Expand Down
2 changes: 1 addition & 1 deletion oas/index_api/configure_index.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_index_api;
part of 'api.dart';

/// Configure index operation
final configureIndex = Operation(
Expand Down
2 changes: 1 addition & 1 deletion oas/index_api/create_collection.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_index_api;
part of 'api.dart';

/// Create collection operation
final createCollection = Operation(
Expand Down
2 changes: 1 addition & 1 deletion oas/index_api/create_index.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_index_api;
part of 'api.dart';

/// Create index operation
final createIndex = Operation(
Expand Down
2 changes: 1 addition & 1 deletion oas/index_api/delete_collection.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_index_api;
part of 'api.dart';

/// Delete collection operation
final deleteCollection = Operation(
Expand Down
2 changes: 1 addition & 1 deletion oas/index_api/delete_index.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_index_api;
part of 'api.dart';

/// Delete index operation
final deleteIndex = Operation(
Expand Down
2 changes: 1 addition & 1 deletion oas/index_api/describe_collection.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_index_api;
part of 'api.dart';

/// Describe collection operation
final describeCollection = Operation(
Expand Down
2 changes: 1 addition & 1 deletion oas/index_api/describe_index.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_index_api;
part of 'api.dart';

/// Describe index operation
final describeIndex = Operation(
Expand Down
2 changes: 1 addition & 1 deletion oas/index_api/list_collections.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_index_api;
part of 'api.dart';

/// List collections operation
final listCollections = Operation(
Expand Down
2 changes: 1 addition & 1 deletion oas/index_api/list_indexes.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_index_api;
part of 'api.dart';

/// List indexes operation
final listIndexes = Operation(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/collection.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Collection object
final schemaCollection = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/collection_status.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// An enumeration of the available pod types.
final schemaCollectionStatus = Schema.enumeration(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/configure_index_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Create collection request object
final schemaConfigureIndexRequest = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/create_collection_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Create collection request object
final schemaCreateCollectionRequest = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/create_index_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Create index request object
final schemaCreateIndexRequest = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/delete_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Create collection request object
final schemaDeleteRequest = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/fetch_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Vector fetch response object
final schemaFetchResponse = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/index.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Index object
final schemaIndex = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/index_database.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Index database object
final schemaIndexDatabase = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/index_state.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// An enumeration of the current index state.
final schemaIndexState = Schema.enumeration(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/index_stats.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Index stats object
final schemaIndexStats = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/index_stats_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Described index statistics request object
final schemaIndexStatsRequest = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/index_status.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Index status object
final schemaIndexStatus = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/pod_type.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// An enumeration of the available pod types.
final schemaPodType = Schema.enumeration(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/query_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Vector query request object
final schemaQueryRequest = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/query_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// Vector query response object
final schemaQueryResponse = Schema.object(
Expand Down
2 changes: 1 addition & 1 deletion oas/schema/search_metric.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of pinecone_schema;
part of 'schema.dart';

/// An enumeration of the available pod types.
final schemaSearchMetric = Schema.enumeration(
Expand Down
Loading

0 comments on commit c99bb7a

Please sign in to comment.