From ec535ad7cc7663b654cf072881c84f8f6e85d27b Mon Sep 17 00:00:00 2001 From: sjaanus Date: Mon, 2 Jan 2023 12:08:27 +0200 Subject: [PATCH] Make it possible to validate enterprise schema with respondWithValidation (#2781) Now respondWithValidation can be called in oss and enterprise to validate against needed schema. --- src/lib/openapi/validate.ts | 10 +++++----- src/lib/services/openapi-service.ts | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/openapi/validate.ts b/src/lib/openapi/validate.ts index 48a1a59e22d..78e3df2bcb9 100644 --- a/src/lib/openapi/validate.ts +++ b/src/lib/openapi/validate.ts @@ -2,8 +2,8 @@ import Ajv, { ErrorObject } from 'ajv'; import { SchemaId, schemas } from './index'; import { omitKeys } from '../util/omit-keys'; -interface ISchemaValidationErrors { - schema: SchemaId; +export interface ISchemaValidationErrors { + schema: S; errors: ErrorObject[]; } @@ -21,10 +21,10 @@ const ajv = new Ajv({ }, }); -export const validateSchema = ( - schema: SchemaId, +export const validateSchema = ( + schema: S, data: unknown, -): ISchemaValidationErrors | undefined => { +): ISchemaValidationErrors | undefined => { if (!ajv.validate(schema, data)) { return { schema, diff --git a/src/lib/services/openapi-service.ts b/src/lib/services/openapi-service.ts index 58a4d48e6ce..fd938b1914d 100644 --- a/src/lib/services/openapi-service.ts +++ b/src/lib/services/openapi-service.ts @@ -64,14 +64,14 @@ export class OpenApiService { }); } - respondWithValidation( + respondWithValidation( status: number, res: Response, - schema: SchemaId, + schema: S, data: T, headers: { [header: string]: string } = {}, ): void { - const errors = validateSchema(schema, data); + const errors = validateSchema(schema, data); if (errors) { this.logger.debug('Invalid response:', errors);