diff --git a/src/lib/openapi/spec/event-schema.test.ts b/src/lib/openapi/spec/event-schema.test.ts index af7259c90f..217c672414 100644 --- a/src/lib/openapi/spec/event-schema.test.ts +++ b/src/lib/openapi/spec/event-schema.test.ts @@ -19,7 +19,7 @@ test('eventSchema', () => { impressionData: true, }, preData: null, - tags: [], + tags: [{ type: 'simple', value: 'my-val' }], featureName: 'new-feature', project: 'my-project', environment: null, diff --git a/src/lib/openapi/spec/event-schema.ts b/src/lib/openapi/spec/event-schema.ts index db8869a7df..b68baa9e4e 100644 --- a/src/lib/openapi/spec/event-schema.ts +++ b/src/lib/openapi/spec/event-schema.ts @@ -35,7 +35,7 @@ export const eventSchema = { tags: { type: 'array', items: { - $ref: '#/components/schemas/tagSchema', + $ref: tagSchema.$id, }, }, }, diff --git a/src/lib/openapi/spec/events-schema.ts b/src/lib/openapi/spec/events-schema.ts index 77aa96416f..0fc6a1097d 100644 --- a/src/lib/openapi/spec/events-schema.ts +++ b/src/lib/openapi/spec/events-schema.ts @@ -13,7 +13,7 @@ export const eventsSchema = { }, events: { type: 'array', - items: { $ref: '#/components/schemas/eventSchema' }, + items: { $ref: eventSchema.$id }, }, }, components: { diff --git a/src/lib/routes/admin-api/event.ts b/src/lib/routes/admin-api/event.ts index ac9913fae6..51149aba58 100644 --- a/src/lib/routes/admin-api/event.ts +++ b/src/lib/routes/admin-api/event.ts @@ -6,6 +6,9 @@ import { ADMIN } from '../../types/permissions'; import { IEvent } from '../../types/events'; import Controller from '../controller'; import { anonymise } from '../../util/anonymise'; +import { OpenApiService } from '../../services/openapi-service'; +import { createResponseSchema } from 'lib/openapi'; +import { eventsSchema, EventsSchema } from 'lib/openapi/spec/events-schema'; const version = 1; export default class EventController extends Controller { @@ -13,14 +16,36 @@ export default class EventController extends Controller { private anonymise: boolean = false; + private openApiService: OpenApiService; + constructor( config: IUnleashConfig, - { eventService }: Pick, + { + eventService, + openApiService, + }: Pick, ) { super(config); this.eventService = eventService; this.anonymise = config.experimental?.anonymiseEventLog; - this.get('/', this.getEvents, ADMIN); + this.openApiService = openApiService; + + this.route({ + method: 'get', + path: '', + handler: this.getEvents, + permission: ADMIN, + middleware: [ + openApiService.validPath({ + operationId: 'getEvents', + tags: ['admin'], + responses: { + 200: createResponseSchema('eventsSchema'), + }, + }), + ], + }); + this.get('/:name', this.getEventsForToggle); } @@ -36,7 +61,7 @@ export default class EventController extends Controller { async getEvents( req: Request, - res: Response, + res: Response, ): Promise { const { project } = req.query; let events: IEvent[]; @@ -45,10 +70,17 @@ export default class EventController extends Controller { } else { events = await this.eventService.getEvents(); } - res.json({ + + const response: EventsSchema = { version, events: this.fixEvents(events), - }); + }; + this.openApiService.respondWithValidation( + 200, + res, + eventsSchema.$id, + response, + ); } async getEventsForToggle(