Skip to content

Commit

Permalink
add support for update and delete schema field (#55)
Browse files Browse the repository at this point in the history
- Pin OpenAPI generator version at 5.4.0
  • Loading branch information
jkaho authored May 4, 2022
1 parent d79a911 commit 16650ab
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 5 deletions.
2 changes: 1 addition & 1 deletion generate/Dockerfile.generate
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM openapitools/openapi-generator-cli:latest-release
FROM openapitools/openapi-generator-cli@sha256:bc3f07ee4032923c7158b1a4a59aadd1861c6b4227c58d8ded5ee2b6c075bf72
2 changes: 1 addition & 1 deletion generate/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [ -z "$TEMPLATES_PATH" ]; then
die "TEMPLATES_PATH must be set, e.g. /path/to/sajari/sdk-node/generate/templates"
fi

VERSION=4.5.2
VERSION=4.6.2

docker-entrypoint.sh generate \
-i /openapi.json \
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sajari/sdk-node",
"version": "4.5.2",
"version": "4.6.2",
"repository": "[email protected]:github.com/sajari/sdk-node.git",
"author": "Search.io",
"license": "MIT",
Expand Down
245 changes: 245 additions & 0 deletions src/generated/api/schemaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,119 @@ export class SchemaApi {
);
});
}
/**
* Deleting a schema field removes it from all records within the collection, however, references to the schema field in pipelines are not removed. > Note: This operation cannot be reversed.
* @summary Delete schema field
* @param collectionId The collection the schema field belongs to, e.g. `my-collection`.
* @param schemaFieldName The name of the schema field to delete.
*/
public async deleteSchemaField(
collectionId: string,
schemaFieldName: string,
options: { headers: { [name: string]: string } } = { headers: {} }
): Promise<{ response: http.IncomingMessage; body: any }> {
const localVarPath =
this.basePath +
"/v4/collections/{collection_id}/schemaFields/{schema_field_name}"
.replace(
"{" + "collection_id" + "}",
encodeURIComponent(String(collectionId))
)
.replace(
"{" + "schema_field_name" + "}",
encodeURIComponent(String(schemaFieldName))
);
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign(
{},
this._defaultHeaders
);
const produces = ["application/json"];
// give precedence to 'application/json'
if (produces.indexOf("application/json") >= 0) {
localVarHeaderParams.Accept = "application/json";
} else {
localVarHeaderParams.Accept = produces.join(",");
}
let localVarFormParams: any = {};

// verify required parameter 'collectionId' is not null or undefined
if (collectionId === null || collectionId === undefined) {
throw new Error(
"Required parameter collectionId was null or undefined when calling deleteSchemaField."
);
}

// verify required parameter 'schemaFieldName' is not null or undefined
if (schemaFieldName === null || schemaFieldName === undefined) {
throw new Error(
"Required parameter schemaFieldName was null or undefined when calling deleteSchemaField."
);
}

(<any>Object).assign(localVarHeaderParams, options.headers);

let localVarUseFormData = false;

let localVarRequestOptions: localVarRequest.Options = {
method: "DELETE",
qs: localVarQueryParameters,
headers: localVarHeaderParams,
uri: localVarPath,
useQuerystring: this._useQuerystring,
json: true,
};

let authenticationPromise = Promise.resolve();
if (
this.authentications.BasicAuth.username &&
this.authentications.BasicAuth.password
) {
authenticationPromise = authenticationPromise.then(() =>
this.authentications.BasicAuth.applyToRequest(localVarRequestOptions)
);
}
authenticationPromise = authenticationPromise.then(() =>
this.authentications.default.applyToRequest(localVarRequestOptions)
);

let interceptorPromise = authenticationPromise;
for (const interceptor of this.interceptors) {
interceptorPromise = interceptorPromise.then(() =>
interceptor(localVarRequestOptions)
);
}

return interceptorPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
(<any>localVarRequestOptions).formData = localVarFormParams;
} else {
localVarRequestOptions.form = localVarFormParams;
}
}
return new Promise<{ response: http.IncomingMessage; body: any }>(
(resolve, reject) => {
localVarRequest(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
} else {
if (
response.statusCode &&
response.statusCode >= 200 &&
response.statusCode <= 299
) {
body = ObjectSerializer.deserialize(body, "any");
resolve({ response: response, body: body });
} else {
reject(new HttpError(response, body, response.statusCode));
}
}
});
}
);
});
}
/**
* Retrieve a list of schema fields in a collection.
* @summary List schema fields
Expand Down Expand Up @@ -469,4 +582,136 @@ export class SchemaApi {
});
});
}
/**
* Update the details of a schema field. Only `name` and `description` can be updated.
* @summary Update schema field
* @param collectionId The collection the schema field belongs to, e.g. &#x60;my-collection&#x60;.
* @param schemaFieldName The name of the schema field to update.
* @param schemaField The schema field details to update.
* @param updateMask The list of fields to update, separated by a comma, e.g. &#x60;name,description&#x60;. Each field should be in snake case. For each field that you want to update, provide a corresponding value in the schema field object containing the new value.
*/
public async updateSchemaField(
collectionId: string,
schemaFieldName: string,
schemaField: SchemaField,
updateMask?: string,
options: { headers: { [name: string]: string } } = { headers: {} }
): Promise<{ response: http.IncomingMessage; body: SchemaField }> {
const localVarPath =
this.basePath +
"/v4/collections/{collection_id}/schemaFields/{schema_field_name}"
.replace(
"{" + "collection_id" + "}",
encodeURIComponent(String(collectionId))
)
.replace(
"{" + "schema_field_name" + "}",
encodeURIComponent(String(schemaFieldName))
);
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign(
{},
this._defaultHeaders
);
const produces = ["application/json"];
// give precedence to 'application/json'
if (produces.indexOf("application/json") >= 0) {
localVarHeaderParams.Accept = "application/json";
} else {
localVarHeaderParams.Accept = produces.join(",");
}
let localVarFormParams: any = {};

// verify required parameter 'collectionId' is not null or undefined
if (collectionId === null || collectionId === undefined) {
throw new Error(
"Required parameter collectionId was null or undefined when calling updateSchemaField."
);
}

// verify required parameter 'schemaFieldName' is not null or undefined
if (schemaFieldName === null || schemaFieldName === undefined) {
throw new Error(
"Required parameter schemaFieldName was null or undefined when calling updateSchemaField."
);
}

// verify required parameter 'schemaField' is not null or undefined
if (schemaField === null || schemaField === undefined) {
throw new Error(
"Required parameter schemaField was null or undefined when calling updateSchemaField."
);
}

if (updateMask !== undefined) {
localVarQueryParameters["update_mask"] = ObjectSerializer.serialize(
updateMask,
"string"
);
}

(<any>Object).assign(localVarHeaderParams, options.headers);

let localVarUseFormData = false;

let localVarRequestOptions: localVarRequest.Options = {
method: "PATCH",
qs: localVarQueryParameters,
headers: localVarHeaderParams,
uri: localVarPath,
useQuerystring: this._useQuerystring,
json: true,
body: ObjectSerializer.serialize(schemaField, "SchemaField"),
};

let authenticationPromise = Promise.resolve();
if (
this.authentications.BasicAuth.username &&
this.authentications.BasicAuth.password
) {
authenticationPromise = authenticationPromise.then(() =>
this.authentications.BasicAuth.applyToRequest(localVarRequestOptions)
);
}
authenticationPromise = authenticationPromise.then(() =>
this.authentications.default.applyToRequest(localVarRequestOptions)
);

let interceptorPromise = authenticationPromise;
for (const interceptor of this.interceptors) {
interceptorPromise = interceptorPromise.then(() =>
interceptor(localVarRequestOptions)
);
}

return interceptorPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
(<any>localVarRequestOptions).formData = localVarFormParams;
} else {
localVarRequestOptions.form = localVarFormParams;
}
}
return new Promise<{ response: http.IncomingMessage; body: SchemaField }>(
(resolve, reject) => {
localVarRequest(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
} else {
if (
response.statusCode &&
response.statusCode >= 200 &&
response.statusCode <= 299
) {
body = ObjectSerializer.deserialize(body, "SchemaField");
resolve({ response: response, body: body });
} else {
reject(new HttpError(response, body, response.statusCode));
}
}
});
}
);
});
}
}
32 changes: 32 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,36 @@ export class SchemaClient extends Client {
throw handleError(e);
}
}

async updateField(
fieldName: string,
field: SchemaField,
...options: Array<
(updateMask?: Record<string, boolean>) => void
>
) {
const updateMask: Record<string, boolean> = {};

for (const opt of options) {
opt(updateMask);
}

const um = Object.keys(updateMask).map((field) => field);

try {
const res = await this.client.updateSchemaField(this.collectionId, fieldName, field, um.join(","));
return res.body;
} catch (e) {
throw handleError(e);
}
}

async deleteField(fieldName: string) {
try {
const res = await this.client.deleteSchemaField(this.collectionId, fieldName);
return res.body;
} catch (e) {
throw handleError(e);
}
}
}
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Code generated by generate-version.ts. DO NOT EDIT.

export const version = "4.5.2";
export const version = "4.6.2";

0 comments on commit 16650ab

Please sign in to comment.