Skip to content

Commit

Permalink
Added support for readOnly keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
frankcalise committed Oct 16, 2019
1 parent ffe2d40 commit 16ea18e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/middlewares/openapi.request.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ export class RequestValidator {
requestBody = this._apiDocs.components.requestBodies[id];
}

if (requestBody) {
// check request body for readonly properties
const r = this.ajv.getSchema(
requestBody.content['application/json'].schema['$ref'],
);
Object.keys(r.schema.properties).forEach(itemKey => {
console.log(itemKey);
const readOnly = r.schema.properties[itemKey].hasOwnProperty(
'readOnly',
);
if (readOnly) {
const message = `${itemKey} is a readonly property`;
throw validationError(400, path, message);
}
});
}

let body = this.requestBodyToSchema(path, contentType, requestBody);
let requiredAdds = requestBody && requestBody.required ? ['body'] : [];

Expand Down

0 comments on commit 16ea18e

Please sign in to comment.