From a785465943a040533a21aedad14513f2854addd4 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Thu, 13 Jul 2023 10:29:54 +0200 Subject: [PATCH] openapi: update the splash endpoints and schemas for splash (#4227) This change updates the splash endpoints and related schemas for the admin ui tag. --- src/lib/openapi/index.ts | 6 +++-- src/lib/openapi/meta-schema-rules.test.ts | 2 -- src/lib/openapi/spec/index.ts | 3 ++- src/lib/openapi/spec/splash-request-schema.ts | 23 +++++++++++++++++++ .../openapi/spec/splash-response-schema.ts | 22 ++++++++++++++++++ src/lib/openapi/spec/splash-schema.ts | 22 ------------------ src/lib/routes/admin-api/user-splash.ts | 16 +++++++++---- src/test/e2e/api/admin/splash.e2e.test.ts | 8 ++++++- 8 files changed, 70 insertions(+), 32 deletions(-) create mode 100644 src/lib/openapi/spec/splash-request-schema.ts create mode 100644 src/lib/openapi/spec/splash-response-schema.ts delete mode 100644 src/lib/openapi/spec/splash-schema.ts diff --git a/src/lib/openapi/index.ts b/src/lib/openapi/index.ts index e2c86ecff7..67a7ab0084 100644 --- a/src/lib/openapi/index.ts +++ b/src/lib/openapi/index.ts @@ -108,7 +108,8 @@ import { setStrategySortOrderSchema, setUiConfigSchema, sortOrderSchema, - splashSchema, + splashRequestSchema, + splashResponseSchema, stateSchema, strategiesSchema, strategySchema, @@ -305,7 +306,8 @@ export const schemas: UnleashSchemas = { setStrategySortOrderSchema, setUiConfigSchema, sortOrderSchema, - splashSchema, + splashRequestSchema, + splashResponseSchema, stateSchema, strategiesSchema, strategySchema, diff --git a/src/lib/openapi/meta-schema-rules.test.ts b/src/lib/openapi/meta-schema-rules.test.ts index 6300f318aa..9966e32d10 100644 --- a/src/lib/openapi/meta-schema-rules.test.ts +++ b/src/lib/openapi/meta-schema-rules.test.ts @@ -111,7 +111,6 @@ const metaRules: Rule[] = [ 'resetPasswordSchema', 'sdkContextSchema', 'setUiConfigSchema', - 'splashSchema', 'stateSchema', 'strategiesSchema', 'uiConfigSchema', @@ -160,7 +159,6 @@ const metaRules: Rule[] = [ 'setStrategySortOrderSchema', 'setUiConfigSchema', 'sortOrderSchema', - 'splashSchema', 'strategiesSchema', 'uiConfigSchema', 'updateFeatureSchema', diff --git a/src/lib/openapi/spec/index.ts b/src/lib/openapi/spec/index.ts index 3d8bd261e6..38c34099bc 100644 --- a/src/lib/openapi/spec/index.ts +++ b/src/lib/openapi/spec/index.ts @@ -21,7 +21,8 @@ export * from './users-schema'; export * from './addons-schema'; export * from './events-schema'; export * from './groups-schema'; -export * from './splash-schema'; +export * from './splash-request-schema'; +export * from './splash-response-schema'; export * from './feature-schema'; export * from './patches-schema'; export * from './profile-schema'; diff --git a/src/lib/openapi/spec/splash-request-schema.ts b/src/lib/openapi/spec/splash-request-schema.ts new file mode 100644 index 0000000000..8deff88c7a --- /dev/null +++ b/src/lib/openapi/spec/splash-request-schema.ts @@ -0,0 +1,23 @@ +import { FromSchema } from 'json-schema-to-ts'; + +export const splashRequestSchema = { + $id: '#/components/schemas/splashRequestSchema', + type: 'object', + description: 'Data related to a user having seen a splash screen.', + required: ['userId', 'splashId'], + properties: { + userId: { + type: 'integer', + description: 'The ID of the user that was shown the splash screen.', + example: 1, + }, + splashId: { + type: 'string', + description: 'The ID of the splash screen that was shown.', + example: 'new-splash-screen', + }, + }, + components: {}, +} as const; + +export type SplashRequestSchema = FromSchema; diff --git a/src/lib/openapi/spec/splash-response-schema.ts b/src/lib/openapi/spec/splash-response-schema.ts new file mode 100644 index 0000000000..cf58cdcc28 --- /dev/null +++ b/src/lib/openapi/spec/splash-response-schema.ts @@ -0,0 +1,22 @@ +import { FromSchema } from 'json-schema-to-ts'; +import { splashRequestSchema } from './splash-request-schema'; + +export const splashResponseSchema = { + ...splashRequestSchema, + $id: '#/components/schemas/splashResponseSchema', + additionalProperties: false, + description: 'Data related to a user having seen a splash screen.', + required: [...splashRequestSchema.required, 'seen'], + properties: { + ...splashRequestSchema.properties, + seen: { + type: 'boolean', + description: + 'Indicates whether the user has seen the splash screen or not.', + example: true, + }, + }, + components: {}, +} as const; + +export type SplashResponseSchema = FromSchema; diff --git a/src/lib/openapi/spec/splash-schema.ts b/src/lib/openapi/spec/splash-schema.ts deleted file mode 100644 index c21cad3f6a..0000000000 --- a/src/lib/openapi/spec/splash-schema.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { FromSchema } from 'json-schema-to-ts'; - -export const splashSchema = { - $id: '#/components/schemas/splashSchema', - type: 'object', - additionalProperties: false, - required: ['userId', 'splashId', 'seen'], - properties: { - userId: { - type: 'number', - }, - splashId: { - type: 'string', - }, - seen: { - type: 'boolean', - }, - }, - components: {}, -} as const; - -export type SplashSchema = FromSchema; diff --git a/src/lib/routes/admin-api/user-splash.ts b/src/lib/routes/admin-api/user-splash.ts index aebe9bd463..4ccb1318ff 100644 --- a/src/lib/routes/admin-api/user-splash.ts +++ b/src/lib/routes/admin-api/user-splash.ts @@ -8,7 +8,9 @@ import { IAuthRequest } from '../unleash-types'; import { NONE } from '../../types/permissions'; import { OpenApiService } from '../../services/openapi-service'; import { createResponseSchema } from '../../openapi/util/create-response-schema'; -import { splashSchema, SplashSchema } from '../../openapi/spec/splash-schema'; +import { splashRequestSchema } from '../../openapi/spec/splash-request-schema'; +import { getStandardResponses } from '../../openapi'; +import { SplashResponseSchema } from 'lib/openapi/spec/splash-response-schema'; class UserSplashController extends Controller { private logger: Logger; @@ -39,7 +41,13 @@ class UserSplashController extends Controller { openApiService.validPath({ tags: ['Admin UI'], operationId: 'updateSplashSettings', - responses: { 200: createResponseSchema('splashSchema') }, + summary: 'Update splash settings', + description: + 'This operation updates splash settings for a user, indicating that they have seen a particualar splash screen.', + responses: { + 200: createResponseSchema('splashResponseSchema'), + ...getStandardResponses(400, 401, 403, 415), + }, }), ], }); @@ -47,7 +55,7 @@ class UserSplashController extends Controller { private async updateSplashSettings( req: IAuthRequest<{ id: string }>, - res: Response, + res: Response, ): Promise { const { user } = req; const { id } = req.params; @@ -61,7 +69,7 @@ class UserSplashController extends Controller { this.openApiService.respondWithValidation( 200, res, - splashSchema.$id, + splashRequestSchema.$id, await this.userSplashService.updateSplash(splash), ); } diff --git a/src/test/e2e/api/admin/splash.e2e.test.ts b/src/test/e2e/api/admin/splash.e2e.test.ts index 61d0c6db26..8963b3ba9f 100644 --- a/src/test/e2e/api/admin/splash.e2e.test.ts +++ b/src/test/e2e/api/admin/splash.e2e.test.ts @@ -33,7 +33,13 @@ beforeAll(async () => { ); }; - app = await setupAppWithCustomAuth(stores, preHook); + app = await setupAppWithCustomAuth(stores, preHook, { + experimental: { + flags: { + strictSchemaValidation: true, + }, + }, + }); }); afterAll(async () => {