Skip to content

Commit

Permalink
Make it possible to validate enterprise schema with respondWithValida…
Browse files Browse the repository at this point in the history
…tion (#2781)

Now respondWithValidation<T, S = SchemaId> can be called in oss and
enterprise to validate against needed schema.
  • Loading branch information
sjaanus committed Jan 2, 2023
1 parent d5e47ac commit ec535ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/lib/openapi/validate.ts
Expand Up @@ -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[];
}

Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/services/openapi-service.ts
Expand Up @@ -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);
Expand Down

0 comments on commit ec535ad

Please sign in to comment.