mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
Feat(broken): add openapi validation to getEvents endpoint
This commit is contained in:
parent
8c5cefc34a
commit
718a1b4906
@ -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,
|
||||
|
@ -35,7 +35,7 @@ export const eventSchema = {
|
||||
tags: {
|
||||
type: 'array',
|
||||
items: {
|
||||
$ref: '#/components/schemas/tagSchema',
|
||||
$ref: tagSchema.$id,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -13,7 +13,7 @@ export const eventsSchema = {
|
||||
},
|
||||
events: {
|
||||
type: 'array',
|
||||
items: { $ref: '#/components/schemas/eventSchema' },
|
||||
items: { $ref: eventSchema.$id },
|
||||
},
|
||||
},
|
||||
components: {
|
||||
|
@ -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<IUnleashServices, 'eventService'>,
|
||||
{
|
||||
eventService,
|
||||
openApiService,
|
||||
}: Pick<IUnleashServices, 'eventService' | 'openApiService'>,
|
||||
) {
|
||||
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<any, any, any, { project?: string }>,
|
||||
res: Response,
|
||||
res: Response<EventsSchema>,
|
||||
): Promise<void> {
|
||||
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(
|
||||
|
Loading…
Reference in New Issue
Block a user