Skip to content

Commit

Permalink
allow to specify format validation in AJP
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubskopal committed Apr 1, 2020
1 parent b3e8e34 commit 1289af2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/framework/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface OpenApiValidatorOpts {
mode: 'bundle' | 'dereference';
};
operationHandlers?: false | string;
formatValidation?: false | 'fast' | 'fail';
}

export namespace OpenAPIV3 {
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class OpenApiValidator {
if (options.fileUploader == null) options.fileUploader = {};
if (options.$refParser == null) options.$refParser = { mode: 'bundle' };
if (options.operationHandlers == null) options.operationHandlers = false;
if (options.formatValidation == null) options.formatValidation = 'fast';

if (options.validateResponses === true) {
options.validateResponses = {
Expand Down Expand Up @@ -174,7 +175,7 @@ export class OpenApiValidator {
app: Application | Router,
context: OpenApiContext,
): void {
const { coerceTypes, unknownFormats, validateRequests } = this.options;
const { coerceTypes, unknownFormats, validateRequests, formatValidation } = this.options;
const { allowUnknownQueryParameters } = <ValidateRequestOpts>(
validateRequests
);
Expand All @@ -185,6 +186,7 @@ export class OpenApiValidator {
useDefaults: true,
unknownFormats,
allowUnknownQueryParameters,
format: formatValidation
});
const requestValidationHandler: OpenApiRequestHandler = (req, res, next) =>
requestValidator.validate(req, res, next);
Expand All @@ -196,7 +198,7 @@ export class OpenApiValidator {
app: Application | Router,
context: OpenApiContext,
): void {
const { coerceTypes, unknownFormats, validateResponses } = this.options;
const { coerceTypes, unknownFormats, validateResponses, formatValidation } = this.options;
const { removeAdditional } = <ValidateResponseOpts>validateResponses;

const responseValidator = new middlewares.ResponseValidator(
Expand All @@ -206,6 +208,7 @@ export class OpenApiValidator {
coerceTypes,
removeAdditional,
unknownFormats,
format: formatValidation
},
);

Expand Down

0 comments on commit 1289af2

Please sign in to comment.