1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

Make it possible to validate enterprise schema with respondWithValidation (#2781)

Now respondWithValidation<T, S = SchemaId> can be called in oss and
enterprise to validate against needed schema.
This commit is contained in:
sjaanus 2023-01-02 12:08:27 +02:00 committed by GitHub
parent d5e47ac352
commit ec535ad7cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -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<S = SchemaId> {
schema: S;
errors: ErrorObject[];
}
@ -21,10 +21,10 @@ const ajv = new Ajv({
},
});
export const validateSchema = (
schema: SchemaId,
export const validateSchema = <S = SchemaId>(
schema: S,
data: unknown,
): ISchemaValidationErrors | undefined => {
): ISchemaValidationErrors<S> | undefined => {
if (!ajv.validate(schema, data)) {
return {
schema,

View File

@ -64,14 +64,14 @@ export class OpenApiService {
});
}
respondWithValidation<T>(
respondWithValidation<T, S = SchemaId>(
status: number,
res: Response<T>,
schema: SchemaId,
schema: S,
data: T,
headers: { [header: string]: string } = {},
): void {
const errors = validateSchema(schema, data);
const errors = validateSchema<S>(schema, data);
if (errors) {
this.logger.debug('Invalid response:', errors);