зеркало из https://github.com/Azure/sway.git
ensure that the name of the readonly property is populated correctly
This commit is contained in:
Родитель
3e0d3e1e72
Коммит
6849b0fb84
|
@ -176,6 +176,7 @@ declare class Parameter {
|
|||
|
||||
declare interface ValidateOptions {
|
||||
readonly includeErrors?: string[]
|
||||
readonly isResponse?: boolean
|
||||
}
|
||||
|
||||
type Operation = {
|
||||
|
|
|
@ -207,7 +207,7 @@ function readOnlyValidator (report, schema, json) {
|
|||
}
|
||||
|
||||
var isResponse = this.validateOptions && this.validateOptions.isResponse;
|
||||
|
||||
|
||||
if (!isResponse && schema && schema.readOnly && json !== undefined) {
|
||||
let errorMessage = 'ReadOnly property `"{0}": ';
|
||||
|
||||
|
@ -216,11 +216,22 @@ function readOnlyValidator (report, schema, json) {
|
|||
} else {
|
||||
errorMessage += '{1}';
|
||||
}
|
||||
let propertyName = '';
|
||||
if (schema.title && typeof schema.title === 'string') {
|
||||
try {
|
||||
var result = JSON.parse(schema.title);
|
||||
if (result.path && Array.isArray(result.path) && result.path.length) {
|
||||
propertyName = result.path[result.path.length - 1];
|
||||
}
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
errorMessage += '`, cannot be sent in the request.';
|
||||
report.addCustomError(
|
||||
'READONLY_PROPERTY_NOT_ALLOWED_IN_REQUEST',
|
||||
errorMessage,
|
||||
[report.parentReport.path[0], json],
|
||||
[propertyName, json],
|
||||
null,
|
||||
schema
|
||||
);
|
||||
|
|
Загрузка…
Ссылка в новой задаче