Skip to content

Commit

Permalink
Merge commit '852e25a2bdeda7955c9b4abf7cc87edd5e5cc42b' into legacy/10.x
Browse files Browse the repository at this point in the history
  • Loading branch information
alovicu committed Jul 22, 2022
2 parents 2f9d9d8 + 852e25a commit 2d5757b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { Scopes } from '@vivocha/scopes';
import { json as jsonParser, urlencoded as urlencodedParser } from 'body-parser';
import { Eredita } from 'eredita';
import { NextFunction, RequestHandler, Router } from 'express';
import * as jp from 'jsonpolice';
import * as _ from 'lodash';
import { OpenAPIV3, ParameterObject, StaticSchemaObject } from 'openapi-police';
import { OpenAPIV3, ParameterObject, StaticSchemaObject, ValidationError, Schema } from 'openapi-police';
import { API } from './api';
import { Resource } from './resource';
import { APIRequest, APIRequestHandler, APIResponse, Method } from './types';
Expand Down Expand Up @@ -75,7 +74,7 @@ export abstract class Operation {
req.logger.debug(`validator ${key}.${parameter.name}, required ${required}, value ${req[key][parameter.name]}`);
if (typeof req[key][parameter.name] === 'undefined') {
if (required === true) {
throw new jp.ValidationError(`${key}.${parameter.name}`, (schema as any).scope, 'required');
throw new ValidationError(`${key}.${parameter.name}`, (schema as any).scope, 'required');
}
} else {
req[key][parameter.name] = await schema.validate(req[key][parameter.name], { setDefault: true }, `${key}.${parameter.name}`);
Expand Down Expand Up @@ -127,7 +126,7 @@ export abstract class Operation {
return async (req: APIRequest, res: APIResponse, next: NextFunction) => {
if (_.isEqual(req.body, {}) && !parseInt('' + req.header('content-length'))) {
if (required === true) {
next(new jp.ValidationError('body', jp.Schema.scope(schema), 'required'));
next(new ValidationError('body', Schema.scope(schema), 'required'));
} else {
next();
}
Expand Down

0 comments on commit 2d5757b

Please sign in to comment.