@cognigy/rest-api-client
Version:
Cognigy REST-Client
42 lines • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.actionOperationSchemaGenerator = void 0;
const actionOperationSchemaGenerator = (data) => {
const { action, commonKeys, hasId = true, valueSchema, } = data;
const schema = {
type: "object",
additionalProperties: false,
required: ["op"],
properties: {
op: { type: "string", enum: [action] },
},
};
if (valueSchema) {
schema.required.push("value");
const operationSchema = JSON.parse(JSON.stringify(valueSchema));
if (operationSchema.required) {
for (const key of commonKeys) {
const indexOfKey = operationSchema.required.indexOf(key);
if (indexOfKey !== -1) {
operationSchema.required[indexOfKey] = operationSchema.required[operationSchema.required.length - 1];
operationSchema.required.pop();
}
delete operationSchema.properties[key];
}
}
schema.properties.value = operationSchema;
}
if (hasId) {
schema.required.push("id");
schema.properties.id = { type: "string", format: "mongo-id" };
if (valueSchema) {
const clonedSchema = JSON.parse(JSON.stringify(valueSchema));
if (clonedSchema.properties.id) {
schema.properties.id = clonedSchema.properties.id;
}
}
}
return schema;
};
exports.actionOperationSchemaGenerator = actionOperationSchemaGenerator;
//# sourceMappingURL=BatchOperation.js.map