diff --git a/src/lib/openapi/index.ts b/src/lib/openapi/index.ts index 003ff62332..a0304587ed 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 0000000000..ae2faf57aa --- /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 0000000000..98b44e076d --- /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 0000000000..ef0e990a3e --- /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 +>;