Skip to content

Commit

Permalink
refactor: remove response data from schema validation logging (#1748)
Browse files Browse the repository at this point in the history
* refactor: remove response data from schema validation logging

* refactor: update validation error snapshots

* refactor: add missing segments field to featureStrategySchema
  • Loading branch information
olav committed Jun 24, 2022
1 parent de4ba09 commit 286b016
Show file tree
Hide file tree
Showing 18 changed files with 17 additions and 76 deletions.
Expand Up @@ -2,7 +2,6 @@

exports[`apiTokenSchema empty 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand Down
Expand Up @@ -2,7 +2,6 @@

exports[`changePasswordSchema empty 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand Down
10 changes: 0 additions & 10 deletions src/lib/openapi/spec/__snapshots__/constraint-schema.test.ts.snap
Expand Up @@ -2,11 +2,6 @@

exports[`constraintSchema invalid operator name 1`] = `
Object {
"data": Object {
"contextName": "a",
"operator": "b",
"value": "1",
},
"errors": Array [
Object {
"instancePath": "/operator",
Expand Down Expand Up @@ -40,11 +35,6 @@ Object {

exports[`constraintSchema invalid value type 1`] = `
Object {
"data": Object {
"contextName": "a",
"operator": "NUM_LTE",
"value": 1,
},
"errors": Array [
Object {
"instancePath": "/value",
Expand Down
Expand Up @@ -2,7 +2,6 @@

exports[`contextFieldSchema empty 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand Down
Expand Up @@ -2,7 +2,6 @@

exports[`emailSchema 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand Down
Expand Up @@ -2,7 +2,6 @@

exports[`featureEnvironmentSchema empty 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand Down
34 changes: 0 additions & 34 deletions src/lib/openapi/spec/__snapshots__/feature-schema.test.ts.snap
Expand Up @@ -2,19 +2,6 @@

exports[`featureSchema constraints 1`] = `
Object {
"data": Object {
"name": "a",
"strategies": Array [
Object {
"constraints": Array [
Object {
"contextName": "a",
},
],
"name": "a",
},
],
},
"errors": Array [
Object {
"instancePath": "/strategies/0",
Expand All @@ -32,27 +19,6 @@ Object {

exports[`featureSchema overrides 1`] = `
Object {
"data": Object {
"name": "a",
"variants": Array [
Object {
"name": "a",
"overrides": Array [
Object {
"contextName": "a",
"values": "b",
},
],
"payload": Object {
"type": "a",
"value": "b",
},
"stickiness": "a",
"weight": 1,
"weightType": "a",
},
],
},
"errors": Array [
Object {
"instancePath": "/variants/0/overrides/0/values",
Expand Down
Expand Up @@ -2,7 +2,6 @@

exports[`featureTypeSchema empty 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand Down
13 changes: 0 additions & 13 deletions src/lib/openapi/spec/__snapshots__/me-schema.test.ts.snap
Expand Up @@ -2,7 +2,6 @@

exports[`meSchema empty 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand All @@ -20,11 +19,6 @@ Object {

exports[`meSchema missing permissions 1`] = `
Object {
"data": Object {
"user": Object {
"id": 1,
},
},
"errors": Array [
Object {
"instancePath": "",
Expand All @@ -42,13 +36,6 @@ Object {

exports[`meSchema missing splash 1`] = `
Object {
"data": Object {
"feedback": Array [],
"permissions": Array [],
"user": Object {
"id": 1,
},
},
"errors": Array [
Object {
"instancePath": "",
Expand Down
Expand Up @@ -2,7 +2,6 @@

exports[`roleSchema 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand Down
Expand Up @@ -2,9 +2,6 @@

exports[`sortOrderSchema invalid value type 1`] = `
Object {
"data": Object {
"a": "1",
},
"errors": Array [
Object {
"instancePath": "/a",
Expand Down
Expand Up @@ -2,7 +2,6 @@

exports[`strategySchema 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand Down
Expand Up @@ -2,7 +2,6 @@

exports[`tokenUserSchema 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand Down
Expand Up @@ -2,7 +2,6 @@

exports[`validatePasswordSchema empty 1`] = `
Object {
"data": Object {},
"errors": Array [
Object {
"instancePath": "",
Expand Down
1 change: 1 addition & 0 deletions src/lib/openapi/spec/feature-schema.test.ts
Expand Up @@ -14,6 +14,7 @@ test('featureSchema', () => {
operator: 'IN',
},
],
segments: [1],
},
],
variants: [
Expand Down
6 changes: 6 additions & 0 deletions src/lib/openapi/spec/feature-strategy-schema.ts
Expand Up @@ -17,6 +17,12 @@ export const featureStrategySchema = {
sortOrder: {
type: 'number',
},
segments: {
type: 'array',
items: {
type: 'number',
},
},
constraints: {
type: 'array',
items: {
Expand Down
10 changes: 4 additions & 6 deletions src/lib/openapi/validate.ts
Expand Up @@ -3,9 +3,8 @@ import addFormats from 'ajv-formats';
import { SchemaId, schemas } from './index';
import { omitKeys } from '../util/omit-keys';

interface ISchemaValidationErrors<T> {
interface ISchemaValidationErrors {
schema: SchemaId;
data: T;
errors: ErrorObject[];
}

Expand All @@ -17,14 +16,13 @@ const ajv = new Ajv({

addFormats(ajv, ['date-time']);

export const validateSchema = <T>(
export const validateSchema = (
schema: SchemaId,
data: T,
): ISchemaValidationErrors<T> | undefined => {
data: unknown,
): ISchemaValidationErrors | undefined => {
if (!ajv.validate(schema, data)) {
return {
schema,
data: data,
errors: ajv.errors ?? [],
};
}
Expand Down
Expand Up @@ -748,6 +748,12 @@ Object {
"parameters": Object {
"$ref": "#/components/schemas/parametersSchema",
},
"segments": Object {
"items": Object {
"type": "number",
},
"type": "array",
},
"sortOrder": Object {
"type": "number",
},
Expand Down

0 comments on commit 286b016

Please sign in to comment.