Skip to content

Commit

Permalink
build schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Dec 23, 2019
1 parent c0d5725 commit 8062123
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/middlewares/openapi.request.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ export class RequestValidator {
const body = <OpenAPIV3.SchemaObject>(
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 => {
Expand Down

0 comments on commit 8062123

Please sign in to comment.