diff --git a/src/middlewares/openapi.request.validator.ts b/src/middlewares/openapi.request.validator.ts index d1393529..15a119f1 100644 --- a/src/middlewares/openapi.request.validator.ts +++ b/src/middlewares/openapi.request.validator.ts @@ -97,13 +97,14 @@ export class RequestValidator { const body = ( bodySchemaParser.parse(path, pathSchema, contentType) ); - - const required = ['query', 'headers', 'params']; - const properties = { ...parameters.schema, body: body }; - if (body.required) required.push('body'); + ; + const required = body.required ? ['body'] : []; // $schema: "http://json-schema.org/draft-04/schema#", - const schema = { required, properties }; + const schema = { + required: ['query', 'headers', 'params'].concat(required), + properties: { ...parameters.schema, body: body }, + }; const validator = this.ajv.compile(schema); return (req: OpenApiRequest, res: Response, next: NextFunction): void => {