Skip to content

Commit

Permalink
openapi-request-validator: Added check for whether readOnly prop is i…
Browse files Browse the repository at this point in the history
…n list of required fields before splicing out (fixes #717) (#719)
  • Loading branch information
artclark42 committed Apr 8, 2021
1 parent 96787cc commit 0eb6bc0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/openapi-request-validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,9 @@ function sanitizeReadonlyPropertiesFromRequired(
.filter((i) => i !== undefined)
.forEach((value) => {
const index = schema.required.indexOf(value);
schema.required.splice(index, 1);
if (index !== -1) {
schema.required.splice(index, 1);
}
});
}
return schema;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module.exports = {
validateArgs: {
properties: [],
requestBody: {
description: 'a test body',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/TestBody',
},
},
},
},
componentSchemas: {
TestBody: {
properties: {
foo: {
type: 'string',
},
bar: {
type: 'string',
readOnly: true,
},
},
required: ['foo'],
},
},
},
request: {
body: {},
headers: {
'content-type': 'application/json',
},
},
expectedError: {
status: 400,
errors: [
{
path: 'foo',
errorCode: 'required.openapi.requestValidation',
message: "should have required property 'foo'",
location: 'body',
},
],
},
};

0 comments on commit 0eb6bc0

Please sign in to comment.