From 80cf27476b416f73e0d5e39e1b3d08313471ca16 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Fri, 28 Apr 2023 14:56:00 +0200 Subject: [PATCH] openapi: enable `allErrors` and update snapshots (#3622) ## What This PR changes our AJV configuration to return all errors it finds with a schema instead of stopping at the first one. Because of this, a number of the snapshot tests that we have must be updated. ## Why DX! As someone using an API: if I send a faulty request, I'd rather have the API tell me about the five things that are wrong than for me to learn about one thing, send a new request, learn about another thing, send a new request, .... etc. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .../api-token-schema.test.ts.snap | 9 ++++ .../change-password-schema.test.ts.snap | 9 ++++ .../client-application-schema.test.ts.snap | 27 +++++++++++ .../client-features-schema.test.ts.snap | 9 ++++ .../feature-environment-schema.test.ts.snap | 9 ++++ .../feature-type-schema.test.ts.snap | 27 +++++++++++ .../spec/__snapshots__/me-schema.test.ts.snap | 45 +++++++++++++++++++ .../__snapshots__/role-schema.test.ts.snap | 18 ++++++++ ...et-strategy-sort-order-schema.test.ts.snap | 9 ++++ .../strategy-schema.test.ts.snap | 45 +++++++++++++++++++ .../token-user-schema.test.ts.snap | 45 +++++++++++++++++++ src/lib/openapi/validate.ts | 1 + 12 files changed, 253 insertions(+) diff --git a/src/lib/openapi/spec/__snapshots__/api-token-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/api-token-schema.test.ts.snap index 64e2448e9d..6ebf0dd545 100644 --- a/src/lib/openapi/spec/__snapshots__/api-token-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/api-token-schema.test.ts.snap @@ -12,6 +12,15 @@ exports[`apiTokenSchema empty 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'type'", + "params": { + "missingProperty": "type", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/apiTokenSchema", } diff --git a/src/lib/openapi/spec/__snapshots__/change-password-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/change-password-schema.test.ts.snap index aca3944d34..bf2b1f238d 100644 --- a/src/lib/openapi/spec/__snapshots__/change-password-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/change-password-schema.test.ts.snap @@ -12,6 +12,15 @@ exports[`changePasswordSchema empty 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'password'", + "params": { + "missingProperty": "password", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/changePasswordSchema", } diff --git a/src/lib/openapi/spec/__snapshots__/client-application-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/client-application-schema.test.ts.snap index 14692b1f35..521b99ca9a 100644 --- a/src/lib/openapi/spec/__snapshots__/client-application-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/client-application-schema.test.ts.snap @@ -12,6 +12,33 @@ exports[`clientApplicationSchema no fields 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'interval'", + "params": { + "missingProperty": "interval", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'started'", + "params": { + "missingProperty": "started", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'strategies'", + "params": { + "missingProperty": "strategies", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/clientApplicationSchema", } diff --git a/src/lib/openapi/spec/__snapshots__/client-features-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/client-features-schema.test.ts.snap index c76a460bb4..81da2a5a08 100644 --- a/src/lib/openapi/spec/__snapshots__/client-features-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/client-features-schema.test.ts.snap @@ -12,6 +12,15 @@ exports[`clientFeaturesSchema no fields 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'features'", + "params": { + "missingProperty": "features", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/clientFeaturesSchema", } diff --git a/src/lib/openapi/spec/__snapshots__/feature-environment-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/feature-environment-schema.test.ts.snap index 16f81462c0..9e26e1c162 100644 --- a/src/lib/openapi/spec/__snapshots__/feature-environment-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/feature-environment-schema.test.ts.snap @@ -12,6 +12,15 @@ exports[`featureEnvironmentSchema empty 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'enabled'", + "params": { + "missingProperty": "enabled", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/featureEnvironmentSchema", } diff --git a/src/lib/openapi/spec/__snapshots__/feature-type-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/feature-type-schema.test.ts.snap index 1c0caf3f72..4291101757 100644 --- a/src/lib/openapi/spec/__snapshots__/feature-type-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/feature-type-schema.test.ts.snap @@ -12,6 +12,33 @@ exports[`featureTypeSchema empty 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'name'", + "params": { + "missingProperty": "name", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'description'", + "params": { + "missingProperty": "description", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'lifetimeDays'", + "params": { + "missingProperty": "lifetimeDays", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/featureTypeSchema", } diff --git a/src/lib/openapi/spec/__snapshots__/me-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/me-schema.test.ts.snap index 8aa2c3b240..842d5ad390 100644 --- a/src/lib/openapi/spec/__snapshots__/me-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/me-schema.test.ts.snap @@ -12,6 +12,33 @@ exports[`meSchema empty 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'permissions'", + "params": { + "missingProperty": "permissions", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'feedback'", + "params": { + "missingProperty": "feedback", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'splash'", + "params": { + "missingProperty": "splash", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/meSchema", } @@ -29,6 +56,24 @@ exports[`meSchema missing permissions 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'feedback'", + "params": { + "missingProperty": "feedback", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'splash'", + "params": { + "missingProperty": "splash", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/meSchema", } diff --git a/src/lib/openapi/spec/__snapshots__/role-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/role-schema.test.ts.snap index 0a0d9c868f..16e917d8e9 100644 --- a/src/lib/openapi/spec/__snapshots__/role-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/role-schema.test.ts.snap @@ -12,6 +12,24 @@ exports[`roleSchema 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'type'", + "params": { + "missingProperty": "type", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'name'", + "params": { + "missingProperty": "name", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/roleSchema", } diff --git a/src/lib/openapi/spec/__snapshots__/set-strategy-sort-order-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/set-strategy-sort-order-schema.test.ts.snap index bbf7b10369..e28008e55b 100644 --- a/src/lib/openapi/spec/__snapshots__/set-strategy-sort-order-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/set-strategy-sort-order-schema.test.ts.snap @@ -12,6 +12,15 @@ exports[`setStrategySortOrderSchema missing id 1`] = ` }, "schemaPath": "#/items/required", }, + { + "instancePath": "/1", + "keyword": "required", + "message": "must have required property 'id'", + "params": { + "missingProperty": "id", + }, + "schemaPath": "#/items/required", + }, ], "schema": "#/components/schemas/setStrategySortOrderSchema", } diff --git a/src/lib/openapi/spec/__snapshots__/strategy-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/strategy-schema.test.ts.snap index 9d6432203a..e54253404d 100644 --- a/src/lib/openapi/spec/__snapshots__/strategy-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/strategy-schema.test.ts.snap @@ -12,6 +12,51 @@ exports[`strategySchema 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'displayName'", + "params": { + "missingProperty": "displayName", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'description'", + "params": { + "missingProperty": "description", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'editable'", + "params": { + "missingProperty": "editable", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'deprecated'", + "params": { + "missingProperty": "deprecated", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'parameters'", + "params": { + "missingProperty": "parameters", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/strategySchema", } diff --git a/src/lib/openapi/spec/__snapshots__/token-user-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/token-user-schema.test.ts.snap index 60e82e687c..553e7ce0c4 100644 --- a/src/lib/openapi/spec/__snapshots__/token-user-schema.test.ts.snap +++ b/src/lib/openapi/spec/__snapshots__/token-user-schema.test.ts.snap @@ -12,6 +12,51 @@ exports[`tokenUserSchema 1`] = ` }, "schemaPath": "#/required", }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'name'", + "params": { + "missingProperty": "name", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'email'", + "params": { + "missingProperty": "email", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'token'", + "params": { + "missingProperty": "token", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'createdBy'", + "params": { + "missingProperty": "createdBy", + }, + "schemaPath": "#/required", + }, + { + "instancePath": "", + "keyword": "required", + "message": "must have required property 'role'", + "params": { + "missingProperty": "role", + }, + "schemaPath": "#/required", + }, ], "schema": "#/components/schemas/tokenUserSchema", } diff --git a/src/lib/openapi/validate.ts b/src/lib/openapi/validate.ts index 256fa63e9d..c89a38a7cb 100644 --- a/src/lib/openapi/validate.ts +++ b/src/lib/openapi/validate.ts @@ -18,6 +18,7 @@ const ajv = new Ajv({ 'date-time': true, uri: true, }, + allErrors: true, }); export const addAjvSchema = (schemaObjects: any[]): any => {