diff --git a/src/lib/openapi/index.ts b/src/lib/openapi/index.ts index 65f58c06f1..03460ca721 100644 --- a/src/lib/openapi/index.ts +++ b/src/lib/openapi/index.ts @@ -82,6 +82,8 @@ import { emailSchema } from './spec/email-schema'; import { strategySchema } from './spec/strategy-schema'; import { strategiesSchema } from './spec/strategies-schema'; import { upsertStrategySchema } from './spec/upsert-strategy-schema'; +import { eventSchema } from './spec/event-schema'; +import { eventsSchema } from './spec/events-schema'; import { clientApplicationSchema } from './spec/client-application-schema'; // All schemas in `openapi/spec` should be listed here. @@ -107,6 +109,8 @@ export const schemas = { emailSchema, environmentSchema, environmentsSchema, + eventSchema, + eventsSchema, exportParametersSchema, featureEnvironmentSchema, featureEnvironmentMetricsSchema, diff --git a/src/lib/openapi/spec/event-schema.test.ts b/src/lib/openapi/spec/event-schema.test.ts new file mode 100644 index 0000000000..af7259c90f --- /dev/null +++ b/src/lib/openapi/spec/event-schema.test.ts @@ -0,0 +1,31 @@ +import { validateSchema } from '../validate'; +import { EventSchema } from './event-schema'; + +test('eventSchema', () => { + const data: EventSchema = { + id: 899, + type: 'feature-created', + createdBy: 'user@company.com', + createdAt: '2022-05-31T13:32:20.560Z', + data: { + name: 'new-feature', + description: 'Toggle description', + type: 'release', + project: 'my-project', + stale: false, + variants: [], + createdAt: '2022-05-31T13:32:20.547Z', + lastSeenAt: null, + impressionData: true, + }, + preData: null, + tags: [], + featureName: 'new-feature', + project: 'my-project', + environment: null, + }; + + expect( + validateSchema('#/components/schemas/eventSchema', data), + ).toBeUndefined(); +}); diff --git a/src/lib/openapi/spec/event-schema.ts b/src/lib/openapi/spec/event-schema.ts index 8c05317e0d..db8869a7df 100644 --- a/src/lib/openapi/spec/event-schema.ts +++ b/src/lib/openapi/spec/event-schema.ts @@ -1,4 +1,5 @@ import { FromSchema } from 'json-schema-to-ts'; +import { tagSchema } from './tag-schema'; export const eventSchema = { $id: '#/components/schemas/eventSchema', @@ -20,6 +21,9 @@ export const eventSchema = { createdBy: { type: 'string', }, + environment: { + type: 'string', + }, project: { type: 'string', }, @@ -35,6 +39,11 @@ export const eventSchema = { }, }, }, + components: { + schemas: { + tagSchema, + }, + }, } as const; export type EventSchema = FromSchema; diff --git a/src/lib/openapi/spec/events-schema.test.ts b/src/lib/openapi/spec/events-schema.test.ts new file mode 100644 index 0000000000..d26c9ea4dd --- /dev/null +++ b/src/lib/openapi/spec/events-schema.test.ts @@ -0,0 +1,36 @@ +import { validateSchema } from '../validate'; +import { EventsSchema } from './events-schema'; + +test('eventsSchema', () => { + const data: EventsSchema = { + version: 1, + events: [ + { + id: 899, + type: 'feature-created', + createdBy: 'user@company.com', + createdAt: '2022-05-31T13:32:20.560Z', + data: { + name: 'new-feature', + description: 'Toggle description', + type: 'release', + project: 'my-project', + stale: false, + variants: [], + createdAt: '2022-05-31T13:32:20.547Z', + lastSeenAt: null, + impressionData: true, + }, + preData: null, + tags: [], + featureName: 'new-feature', + project: 'my-project', + environment: null, + }, + ], + }; + + expect( + validateSchema('#/components/schemas/eventsSchema', data), + ).toBeUndefined(); +}); diff --git a/src/lib/openapi/spec/events-schema.ts b/src/lib/openapi/spec/events-schema.ts new file mode 100644 index 0000000000..77aa96416f --- /dev/null +++ b/src/lib/openapi/spec/events-schema.ts @@ -0,0 +1,26 @@ +import { FromSchema } from 'json-schema-to-ts'; +import { eventSchema } from './event-schema'; + +export const eventsSchema = { + $id: '#/components/schemas/eventsSchema', + type: 'object', + additionalProperties: false, + required: ['version', 'events'], + properties: { + version: { + type: 'integer', + minimum: 1, + }, + events: { + type: 'array', + items: { $ref: '#/components/schemas/eventSchema' }, + }, + }, + components: { + schemas: { + eventSchema, + }, + }, +} as const; + +export type EventsSchema = FromSchema;