@travetto/schema 3.1.7 → 3.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/validate/validator.ts +11 -3
package/package.json
CHANGED
|
@@ -56,8 +56,16 @@ export class SchemaValidator {
|
|
|
56
56
|
* @param relative The relative path of object traversal
|
|
57
57
|
*/
|
|
58
58
|
static #validateFieldSchema(fieldSchema: FieldConfig, val: unknown, relative: string = ''): ValidationError[] {
|
|
59
|
-
|
|
59
|
+
return this.#validateFieldSchemaRaw(fieldSchema, val, `${relative}${relative ? '.' : ''}${fieldSchema.name}`);
|
|
60
|
+
}
|
|
60
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Validate a single field config against a passed in value
|
|
64
|
+
* @param fieldSchema The field schema configuration
|
|
65
|
+
* @param val The raw value, could be an array or not
|
|
66
|
+
* @param path The current path of validation traversal
|
|
67
|
+
*/
|
|
68
|
+
static #validateFieldSchemaRaw(fieldSchema: FieldConfig, val: unknown, path: string = ''): ValidationError[] {
|
|
61
69
|
const hasValue = !(val === undefined || val === null || (typeof val === 'string' && val === '') || (Array.isArray(val) && val.length === 0));
|
|
62
70
|
|
|
63
71
|
if (!hasValue) {
|
|
@@ -316,10 +324,10 @@ export class SchemaValidator {
|
|
|
316
324
|
* @param method The method being invoked
|
|
317
325
|
* @param params The params to validate
|
|
318
326
|
*/
|
|
319
|
-
static async validateMethod<T>(cls: Class<T>, method: string, params: unknown[]): Promise<void> {
|
|
327
|
+
static async validateMethod<T>(cls: Class<T>, method: string, params: unknown[], prefixes: (string | undefined)[] = []): Promise<void> {
|
|
320
328
|
const errors: ValidationError[] = [];
|
|
321
329
|
for (const field of SchemaRegistry.getMethodSchema(cls, method)) {
|
|
322
|
-
errors.push(...this.#
|
|
330
|
+
errors.push(...this.#validateFieldSchemaRaw(field, params[field.index!], prefixes[field.index!]));
|
|
323
331
|
}
|
|
324
332
|
if (errors.length) {
|
|
325
333
|
throw new ValidationResultError(errors);
|