Skip to content

Commit 487d245

Browse files
committed
SOF-6944: accept schema as optional argument in validation method
1 parent 45d1fff commit 487d245

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

dist/js/entity/in_memory.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export declare class InMemoryEntity {
4949
* @summary Clone this entity
5050
*/
5151
clone(extraContext?: object): this;
52-
static validateData(data: AnyObject, clean?: boolean): AnyObject;
52+
static validateData(data: AnyObject, clean?: boolean, jsonSchema?: import("json-schema").JSONSchema7 | undefined): AnyObject;
5353
/**
5454
* @summary Validate entity contents against schema
5555
*/

dist/js/entity/in_memory.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,22 @@ class InMemoryEntity {
105105
...extraContext,
106106
});
107107
}
108-
static validateData(data, clean = false) {
109-
if (!this.jsonSchema) {
108+
static validateData(data, clean = false, jsonSchema = this.jsonSchema) {
109+
if (!jsonSchema) {
110110
return data;
111111
}
112112
const result = clean
113-
? ajv.validateAndClean(data, this.jsonSchema, {
113+
? ajv.validateAndClean(data, jsonSchema, {
114114
coerceTypes: this.allowJsonSchemaTypesCoercing,
115115
})
116-
: ajv.validate(data, this.jsonSchema);
116+
: ajv.validate(data, jsonSchema);
117117
if (!result.isValid) {
118118
throw new EntityError({
119119
code: ValidationErrorCode.IN_MEMORY_ENTITY_DATA_INVALID,
120120
details: {
121121
error: result === null || result === void 0 ? void 0 : result.errors,
122122
json: data,
123-
schema: this.jsonSchema,
123+
schema: jsonSchema,
124124
},
125125
});
126126
}

src/js/entity/in_memory.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,23 @@ export class InMemoryEntity {
116116
});
117117
}
118118

119-
static validateData(data: AnyObject, clean = false) {
120-
if (!this.jsonSchema) {
119+
static validateData(data: AnyObject, clean = false, jsonSchema = this.jsonSchema) {
120+
if (!jsonSchema) {
121121
return data;
122122
}
123123
const result = clean
124-
? ajv.validateAndClean(data, this.jsonSchema, {
124+
? ajv.validateAndClean(data, jsonSchema, {
125125
coerceTypes: this.allowJsonSchemaTypesCoercing,
126126
})
127-
: ajv.validate(data, this.jsonSchema);
127+
: ajv.validate(data, jsonSchema);
128128

129129
if (!result.isValid) {
130130
throw new EntityError({
131131
code: ValidationErrorCode.IN_MEMORY_ENTITY_DATA_INVALID,
132132
details: {
133133
error: result?.errors,
134134
json: data,
135-
schema: this.jsonSchema,
135+
schema: jsonSchema,
136136
},
137137
});
138138
}

0 commit comments

Comments
 (0)