Rename internal JSON schema functions to match new return type (#1699)
This commit is contained in:
parent
d7cf019b4a
commit
d182e55527
@ -75,7 +75,7 @@ class JsonSchema {
|
|||||||
getObjectPropertySchema(property) {
|
getObjectPropertySchema(property) {
|
||||||
this._schemaPush(this._startSchema, null);
|
this._schemaPush(this._startSchema, null);
|
||||||
try {
|
try {
|
||||||
const schemaInfo = this._getObjectPropertySchemaPath(property);
|
const schemaInfo = this._getObjectPropertySchemaInfo(property);
|
||||||
return schemaInfo !== null ? new JsonSchema(schemaInfo.schema, this._rootSchema) : null;
|
return schemaInfo !== null ? new JsonSchema(schemaInfo.schema, this._rootSchema) : null;
|
||||||
} finally {
|
} finally {
|
||||||
this._schemaPop();
|
this._schemaPop();
|
||||||
@ -85,7 +85,7 @@ class JsonSchema {
|
|||||||
getArrayItemSchema(index) {
|
getArrayItemSchema(index) {
|
||||||
this._schemaPush(this._startSchema, null);
|
this._schemaPush(this._startSchema, null);
|
||||||
try {
|
try {
|
||||||
const schemaInfo = this._getArrayItemSchemaPath(index);
|
const schemaInfo = this._getArrayItemSchemaInfo(index);
|
||||||
return schemaInfo !== null ? new JsonSchema(schemaInfo.schema, this._rootSchema) : null;
|
return schemaInfo !== null ? new JsonSchema(schemaInfo.schema, this._rootSchema) : null;
|
||||||
} finally {
|
} finally {
|
||||||
this._schemaPop();
|
this._schemaPop();
|
||||||
@ -162,7 +162,7 @@ class JsonSchema {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
_getObjectPropertySchemaPath(property) {
|
_getObjectPropertySchemaInfo(property) {
|
||||||
const {properties} = this._schema;
|
const {properties} = this._schema;
|
||||||
if (this._isObject(properties)) {
|
if (this._isObject(properties)) {
|
||||||
const propertySchema = properties[property];
|
const propertySchema = properties[property];
|
||||||
@ -182,7 +182,7 @@ class JsonSchema {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_getArrayItemSchemaPath(index) {
|
_getArrayItemSchemaInfo(index) {
|
||||||
const {items} = this._schema;
|
const {items} = this._schema;
|
||||||
if (this._isObject(items)) {
|
if (this._isObject(items)) {
|
||||||
return {schema: items, path: 'items'};
|
return {schema: items, path: 'items'};
|
||||||
@ -521,7 +521,7 @@ class JsonSchema {
|
|||||||
this._validateArrayContains(value);
|
this._validateArrayContains(value);
|
||||||
|
|
||||||
for (let i = 0; i < length; ++i) {
|
for (let i = 0; i < length; ++i) {
|
||||||
const schemaInfo = this._getArrayItemSchemaPath(i);
|
const schemaInfo = this._getArrayItemSchemaInfo(i);
|
||||||
if (schemaInfo === null) {
|
if (schemaInfo === null) {
|
||||||
throw this._createError(`No schema found for array[${i}]`);
|
throw this._createError(`No schema found for array[${i}]`);
|
||||||
}
|
}
|
||||||
@ -586,7 +586,7 @@ class JsonSchema {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const property of properties) {
|
for (const property of properties) {
|
||||||
const schemaInfo = this._getObjectPropertySchemaPath(property);
|
const schemaInfo = this._getObjectPropertySchemaInfo(property);
|
||||||
if (schemaInfo === null) {
|
if (schemaInfo === null) {
|
||||||
throw this._createError(`No schema found for ${property}`);
|
throw this._createError(`No schema found for ${property}`);
|
||||||
}
|
}
|
||||||
@ -682,7 +682,7 @@ class JsonSchema {
|
|||||||
if (Array.isArray(required)) {
|
if (Array.isArray(required)) {
|
||||||
for (const property of required) {
|
for (const property of required) {
|
||||||
properties.delete(property);
|
properties.delete(property);
|
||||||
const schemaInfo = this._getObjectPropertySchemaPath(property);
|
const schemaInfo = this._getObjectPropertySchemaInfo(property);
|
||||||
if (schemaInfo === null) { continue; }
|
if (schemaInfo === null) { continue; }
|
||||||
const propertyValue = Object.prototype.hasOwnProperty.call(value, property) ? value[property] : void 0;
|
const propertyValue = Object.prototype.hasOwnProperty.call(value, property) ? value[property] : void 0;
|
||||||
value[property] = this._getValidValueOrDefault(property, propertyValue, schemaInfo);
|
value[property] = this._getValidValueOrDefault(property, propertyValue, schemaInfo);
|
||||||
@ -690,7 +690,7 @@ class JsonSchema {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const property of properties) {
|
for (const property of properties) {
|
||||||
const schemaInfo = this._getObjectPropertySchemaPath(property);
|
const schemaInfo = this._getObjectPropertySchemaInfo(property);
|
||||||
if (schemaInfo === null) {
|
if (schemaInfo === null) {
|
||||||
Reflect.deleteProperty(value, property);
|
Reflect.deleteProperty(value, property);
|
||||||
} else {
|
} else {
|
||||||
@ -703,7 +703,7 @@ class JsonSchema {
|
|||||||
|
|
||||||
_populateArrayDefaults(value) {
|
_populateArrayDefaults(value) {
|
||||||
for (let i = 0, ii = value.length; i < ii; ++i) {
|
for (let i = 0, ii = value.length; i < ii; ++i) {
|
||||||
const schemaInfo = this._getArrayItemSchemaPath(i);
|
const schemaInfo = this._getArrayItemSchemaInfo(i);
|
||||||
if (schemaInfo === null) { continue; }
|
if (schemaInfo === null) { continue; }
|
||||||
const propertyValue = value[i];
|
const propertyValue = value[i];
|
||||||
value[i] = this._getValidValueOrDefault(i, propertyValue, schemaInfo);
|
value[i] = this._getValidValueOrDefault(i, propertyValue, schemaInfo);
|
||||||
@ -712,7 +712,7 @@ class JsonSchema {
|
|||||||
const {minItems, maxItems} = this._schema;
|
const {minItems, maxItems} = this._schema;
|
||||||
if (typeof minItems === 'number' && value.length < minItems) {
|
if (typeof minItems === 'number' && value.length < minItems) {
|
||||||
for (let i = value.length; i < minItems; ++i) {
|
for (let i = value.length; i < minItems; ++i) {
|
||||||
const schemaInfo = this._getArrayItemSchemaPath(i);
|
const schemaInfo = this._getArrayItemSchemaInfo(i);
|
||||||
if (schemaInfo === null) { break; }
|
if (schemaInfo === null) { break; }
|
||||||
const item = this._getValidValueOrDefault(i, void 0, schemaInfo);
|
const item = this._getValidValueOrDefault(i, void 0, schemaInfo);
|
||||||
value.push(item);
|
value.push(item);
|
||||||
|
Loading…
Reference in New Issue
Block a user