From 4a4196c66a6df3de3057079060465f49099ba21a Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Thu, 8 Feb 2024 16:16:55 +0200 Subject: [PATCH] feat: preliminary project applications schema (#6152) Currently keeping flat structure and separate out into multiple requests(schemas) if needed. In future, we will also add dates. --- src/lib/openapi/index.ts | 4 +++ .../spec/project-application-schema.ts | 36 +++++++++++++++++++ .../spec/project-applications-schema.test.ts | 17 +++++++++ .../spec/project-applications-schema.ts | 20 +++++++++++ 4 files changed, 77 insertions(+) create mode 100644 src/lib/openapi/spec/project-application-schema.ts create mode 100644 src/lib/openapi/spec/project-applications-schema.test.ts create mode 100644 src/lib/openapi/spec/project-applications-schema.ts diff --git a/src/lib/openapi/index.ts b/src/lib/openapi/index.ts index 003ff62332b4..a0304587eda1 100644 --- a/src/lib/openapi/index.ts +++ b/src/lib/openapi/index.ts @@ -193,6 +193,8 @@ import { advancedPlaygroundEnvironmentFeatureSchema } from './spec/advanced-play import { createFeatureNamingPatternSchema } from './spec/create-feature-naming-pattern-schema'; import { segmentStrategiesSchema } from './spec/segment-strategies-schema'; import { featureDependenciesSchema } from './spec/feature-dependencies-schema'; +import { projectApplicationsSchema } from './spec/project-applications-schema'; +import { projectApplicationSchema } from './spec/project-application-schema'; // Schemas must have an $id property on the form "#/components/schemas/mySchema". export type SchemaId = (typeof schemas)[keyof typeof schemas]['$id']; @@ -322,6 +324,8 @@ export const schemas: UnleashSchemas = { playgroundSegmentSchema, playgroundStrategySchema, profileSchema, + projectApplicationSchema, + projectApplicationsSchema, projectEnvironmentSchema, projectSchema, projectsSchema, diff --git a/src/lib/openapi/spec/project-application-schema.ts b/src/lib/openapi/spec/project-application-schema.ts new file mode 100644 index 000000000000..ae2faf57aa69 --- /dev/null +++ b/src/lib/openapi/spec/project-application-schema.ts @@ -0,0 +1,36 @@ +import { FromSchema } from 'json-schema-to-ts'; + +export const projectApplicationSchema = { + $id: '#/components/schemas/projectApplicationSchema', + type: 'object', + additionalProperties: false, + required: ['appName', 'instanceId', 'sdkVersion', 'environment'], + description: 'A project application instance.', + properties: { + appName: { + type: 'string', + description: + 'Name of the application that is using the SDK. This is the same as the appName in the SDK configuration.', + }, + instanceId: { + type: 'string', + description: + 'The unique identifier of the application instance. This is the same as the instanceId in the SDK configuration', + }, + sdkVersion: { + type: 'string', + description: + 'The version of the SDK that is being used by the application', + }, + environment: { + type: 'string', + description: + 'The environment that the application is running in. This is coming from token configured in the SDK configuration.', + }, + }, + components: {}, +} as const; + +export type ProjectApplicationSchema = FromSchema< + typeof projectApplicationSchema +>; diff --git a/src/lib/openapi/spec/project-applications-schema.test.ts b/src/lib/openapi/spec/project-applications-schema.test.ts new file mode 100644 index 000000000000..98b44e076d52 --- /dev/null +++ b/src/lib/openapi/spec/project-applications-schema.test.ts @@ -0,0 +1,17 @@ +import { validateSchema } from '../validate'; +import { ProjectApplicationsSchema } from './project-applications-schema'; + +test('projectApplicationsSchema', () => { + const data: ProjectApplicationsSchema = [ + { + appName: 'my-weba-app', + instanceId: 'app1:3:4', + sdkVersion: '4.1.1', + environment: 'production', + }, + ]; + + expect( + validateSchema('#/components/schemas/projectApplicationsSchema', data), + ).toBeUndefined(); +}); diff --git a/src/lib/openapi/spec/project-applications-schema.ts b/src/lib/openapi/spec/project-applications-schema.ts new file mode 100644 index 000000000000..ef0e990a3e77 --- /dev/null +++ b/src/lib/openapi/spec/project-applications-schema.ts @@ -0,0 +1,20 @@ +import { FromSchema } from 'json-schema-to-ts'; +import { projectApplicationSchema } from './project-application-schema'; + +export const projectApplicationsSchema = { + $id: '#/components/schemas/projectApplicationsSchema', + type: 'array', + description: 'A list of project applications', + items: { + $ref: '#/components/schemas/projectApplicationSchema', + }, + components: { + schemas: { + projectApplicationSchema, + }, + }, +} as const; + +export type ProjectApplicationsSchema = FromSchema< + typeof projectApplicationsSchema +>;