Skip to content

Commit 16650ab

Browse files
authored
add support for update and delete schema field (#55)
- Pin OpenAPI generator version at 5.4.0
1 parent d79a911 commit 16650ab

File tree

7 files changed

+282
-5
lines changed

7 files changed

+282
-5
lines changed

generate/Dockerfile.generate

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FROM openapitools/openapi-generator-cli:latest-release
1+
FROM openapitools/openapi-generator-cli@sha256:bc3f07ee4032923c7158b1a4a59aadd1861c6b4227c58d8ded5ee2b6c075bf72

generate/generate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if [ -z "$TEMPLATES_PATH" ]; then
1616
die "TEMPLATES_PATH must be set, e.g. /path/to/sajari/sdk-node/generate/templates"
1717
fi
1818

19-
VERSION=4.5.2
19+
VERSION=4.6.2
2020

2121
docker-entrypoint.sh generate \
2222
-i /openapi.json \

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sajari/sdk-node",
3-
"version": "4.5.2",
3+
"version": "4.6.2",
44
"repository": "git@github.com:github.com/sajari/sdk-node.git",
55
"author": "Search.io",
66
"license": "MIT",

src/generated/api/schemaApi.ts

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,119 @@ export class SchemaApi {
345345
);
346346
});
347347
}
348+
/**
349+
* 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.
350+
* @summary Delete schema field
351+
* @param collectionId The collection the schema field belongs to, e.g. `my-collection`.
352+
* @param schemaFieldName The name of the schema field to delete.
353+
*/
354+
public async deleteSchemaField(
355+
collectionId: string,
356+
schemaFieldName: string,
357+
options: { headers: { [name: string]: string } } = { headers: {} }
358+
): Promise<{ response: http.IncomingMessage; body: any }> {
359+
const localVarPath =
360+
this.basePath +
361+
"/v4/collections/{collection_id}/schemaFields/{schema_field_name}"
362+
.replace(
363+
"{" + "collection_id" + "}",
364+
encodeURIComponent(String(collectionId))
365+
)
366+
.replace(
367+
"{" + "schema_field_name" + "}",
368+
encodeURIComponent(String(schemaFieldName))
369+
);
370+
let localVarQueryParameters: any = {};
371+
let localVarHeaderParams: any = (<any>Object).assign(
372+
{},
373+
this._defaultHeaders
374+
);
375+
const produces = ["application/json"];
376+
// give precedence to 'application/json'
377+
if (produces.indexOf("application/json") >= 0) {
378+
localVarHeaderParams.Accept = "application/json";
379+
} else {
380+
localVarHeaderParams.Accept = produces.join(",");
381+
}
382+
let localVarFormParams: any = {};
383+
384+
// verify required parameter 'collectionId' is not null or undefined
385+
if (collectionId === null || collectionId === undefined) {
386+
throw new Error(
387+
"Required parameter collectionId was null or undefined when calling deleteSchemaField."
388+
);
389+
}
390+
391+
// verify required parameter 'schemaFieldName' is not null or undefined
392+
if (schemaFieldName === null || schemaFieldName === undefined) {
393+
throw new Error(
394+
"Required parameter schemaFieldName was null or undefined when calling deleteSchemaField."
395+
);
396+
}
397+
398+
(<any>Object).assign(localVarHeaderParams, options.headers);
399+
400+
let localVarUseFormData = false;
401+
402+
let localVarRequestOptions: localVarRequest.Options = {
403+
method: "DELETE",
404+
qs: localVarQueryParameters,
405+
headers: localVarHeaderParams,
406+
uri: localVarPath,
407+
useQuerystring: this._useQuerystring,
408+
json: true,
409+
};
410+
411+
let authenticationPromise = Promise.resolve();
412+
if (
413+
this.authentications.BasicAuth.username &&
414+
this.authentications.BasicAuth.password
415+
) {
416+
authenticationPromise = authenticationPromise.then(() =>
417+
this.authentications.BasicAuth.applyToRequest(localVarRequestOptions)
418+
);
419+
}
420+
authenticationPromise = authenticationPromise.then(() =>
421+
this.authentications.default.applyToRequest(localVarRequestOptions)
422+
);
423+
424+
let interceptorPromise = authenticationPromise;
425+
for (const interceptor of this.interceptors) {
426+
interceptorPromise = interceptorPromise.then(() =>
427+
interceptor(localVarRequestOptions)
428+
);
429+
}
430+
431+
return interceptorPromise.then(() => {
432+
if (Object.keys(localVarFormParams).length) {
433+
if (localVarUseFormData) {
434+
(<any>localVarRequestOptions).formData = localVarFormParams;
435+
} else {
436+
localVarRequestOptions.form = localVarFormParams;
437+
}
438+
}
439+
return new Promise<{ response: http.IncomingMessage; body: any }>(
440+
(resolve, reject) => {
441+
localVarRequest(localVarRequestOptions, (error, response, body) => {
442+
if (error) {
443+
reject(error);
444+
} else {
445+
if (
446+
response.statusCode &&
447+
response.statusCode >= 200 &&
448+
response.statusCode <= 299
449+
) {
450+
body = ObjectSerializer.deserialize(body, "any");
451+
resolve({ response: response, body: body });
452+
} else {
453+
reject(new HttpError(response, body, response.statusCode));
454+
}
455+
}
456+
});
457+
}
458+
);
459+
});
460+
}
348461
/**
349462
* Retrieve a list of schema fields in a collection.
350463
* @summary List schema fields
@@ -469,4 +582,136 @@ export class SchemaApi {
469582
});
470583
});
471584
}
585+
/**
586+
* Update the details of a schema field. Only `name` and `description` can be updated.
587+
* @summary Update schema field
588+
* @param collectionId The collection the schema field belongs to, e.g. &#x60;my-collection&#x60;.
589+
* @param schemaFieldName The name of the schema field to update.
590+
* @param schemaField The schema field details to update.
591+
* @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.
592+
*/
593+
public async updateSchemaField(
594+
collectionId: string,
595+
schemaFieldName: string,
596+
schemaField: SchemaField,
597+
updateMask?: string,
598+
options: { headers: { [name: string]: string } } = { headers: {} }
599+
): Promise<{ response: http.IncomingMessage; body: SchemaField }> {
600+
const localVarPath =
601+
this.basePath +
602+
"/v4/collections/{collection_id}/schemaFields/{schema_field_name}"
603+
.replace(
604+
"{" + "collection_id" + "}",
605+
encodeURIComponent(String(collectionId))
606+
)
607+
.replace(
608+
"{" + "schema_field_name" + "}",
609+
encodeURIComponent(String(schemaFieldName))
610+
);
611+
let localVarQueryParameters: any = {};
612+
let localVarHeaderParams: any = (<any>Object).assign(
613+
{},
614+
this._defaultHeaders
615+
);
616+
const produces = ["application/json"];
617+
// give precedence to 'application/json'
618+
if (produces.indexOf("application/json") >= 0) {
619+
localVarHeaderParams.Accept = "application/json";
620+
} else {
621+
localVarHeaderParams.Accept = produces.join(",");
622+
}
623+
let localVarFormParams: any = {};
624+
625+
// verify required parameter 'collectionId' is not null or undefined
626+
if (collectionId === null || collectionId === undefined) {
627+
throw new Error(
628+
"Required parameter collectionId was null or undefined when calling updateSchemaField."
629+
);
630+
}
631+
632+
// verify required parameter 'schemaFieldName' is not null or undefined
633+
if (schemaFieldName === null || schemaFieldName === undefined) {
634+
throw new Error(
635+
"Required parameter schemaFieldName was null or undefined when calling updateSchemaField."
636+
);
637+
}
638+
639+
// verify required parameter 'schemaField' is not null or undefined
640+
if (schemaField === null || schemaField === undefined) {
641+
throw new Error(
642+
"Required parameter schemaField was null or undefined when calling updateSchemaField."
643+
);
644+
}
645+
646+
if (updateMask !== undefined) {
647+
localVarQueryParameters["update_mask"] = ObjectSerializer.serialize(
648+
updateMask,
649+
"string"
650+
);
651+
}
652+
653+
(<any>Object).assign(localVarHeaderParams, options.headers);
654+
655+
let localVarUseFormData = false;
656+
657+
let localVarRequestOptions: localVarRequest.Options = {
658+
method: "PATCH",
659+
qs: localVarQueryParameters,
660+
headers: localVarHeaderParams,
661+
uri: localVarPath,
662+
useQuerystring: this._useQuerystring,
663+
json: true,
664+
body: ObjectSerializer.serialize(schemaField, "SchemaField"),
665+
};
666+
667+
let authenticationPromise = Promise.resolve();
668+
if (
669+
this.authentications.BasicAuth.username &&
670+
this.authentications.BasicAuth.password
671+
) {
672+
authenticationPromise = authenticationPromise.then(() =>
673+
this.authentications.BasicAuth.applyToRequest(localVarRequestOptions)
674+
);
675+
}
676+
authenticationPromise = authenticationPromise.then(() =>
677+
this.authentications.default.applyToRequest(localVarRequestOptions)
678+
);
679+
680+
let interceptorPromise = authenticationPromise;
681+
for (const interceptor of this.interceptors) {
682+
interceptorPromise = interceptorPromise.then(() =>
683+
interceptor(localVarRequestOptions)
684+
);
685+
}
686+
687+
return interceptorPromise.then(() => {
688+
if (Object.keys(localVarFormParams).length) {
689+
if (localVarUseFormData) {
690+
(<any>localVarRequestOptions).formData = localVarFormParams;
691+
} else {
692+
localVarRequestOptions.form = localVarFormParams;
693+
}
694+
}
695+
return new Promise<{ response: http.IncomingMessage; body: SchemaField }>(
696+
(resolve, reject) => {
697+
localVarRequest(localVarRequestOptions, (error, response, body) => {
698+
if (error) {
699+
reject(error);
700+
} else {
701+
if (
702+
response.statusCode &&
703+
response.statusCode >= 200 &&
704+
response.statusCode <= 299
705+
) {
706+
body = ObjectSerializer.deserialize(body, "SchemaField");
707+
resolve({ response: response, body: body });
708+
} else {
709+
reject(new HttpError(response, body, response.statusCode));
710+
}
711+
}
712+
});
713+
}
714+
);
715+
});
716+
}
472717
}

src/schema.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,36 @@ export class SchemaClient extends Client {
6767
throw handleError(e);
6868
}
6969
}
70+
71+
async updateField(
72+
fieldName: string,
73+
field: SchemaField,
74+
...options: Array<
75+
(updateMask?: Record<string, boolean>) => void
76+
>
77+
) {
78+
const updateMask: Record<string, boolean> = {};
79+
80+
for (const opt of options) {
81+
opt(updateMask);
82+
}
83+
84+
const um = Object.keys(updateMask).map((field) => field);
85+
86+
try {
87+
const res = await this.client.updateSchemaField(this.collectionId, fieldName, field, um.join(","));
88+
return res.body;
89+
} catch (e) {
90+
throw handleError(e);
91+
}
92+
}
93+
94+
async deleteField(fieldName: string) {
95+
try {
96+
const res = await this.client.deleteSchemaField(this.collectionId, fieldName);
97+
return res.body;
98+
} catch (e) {
99+
throw handleError(e);
100+
}
101+
}
70102
}

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Code generated by generate-version.ts. DO NOT EDIT.
22

3-
export const version = "4.5.2";
3+
export const version = "4.6.2";

0 commit comments

Comments
 (0)