Skip to content

Commit

Permalink
feat: preliminary project applications schema (#6152)
Browse files Browse the repository at this point in the history
Currently keeping flat structure and separate out into multiple
requests(schemas) if needed.
In future, we will also add dates.
  • Loading branch information
sjaanus committed Feb 8, 2024
1 parent bb2f889 commit 4a4196c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/openapi/index.ts
Expand Up @@ -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'];
Expand Down Expand Up @@ -322,6 +324,8 @@ export const schemas: UnleashSchemas = {
playgroundSegmentSchema,
playgroundStrategySchema,
profileSchema,
projectApplicationSchema,
projectApplicationsSchema,
projectEnvironmentSchema,
projectSchema,
projectsSchema,
Expand Down
36 changes: 36 additions & 0 deletions 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
>;
17 changes: 17 additions & 0 deletions 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();
});
20 changes: 20 additions & 0 deletions 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
>;

0 comments on commit 4a4196c

Please sign in to comment.