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,
|
impressionData: true,
|
||||||
},
|
},
|
||||||
preData: null,
|
preData: null,
|
||||||
tags: [],
|
tags: [{ type: 'simple', value: 'my-val' }],
|
||||||
featureName: 'new-feature',
|
featureName: 'new-feature',
|
||||||
project: 'my-project',
|
project: 'my-project',
|
||||||
environment: null,
|
environment: null,
|
||||||
|
@ -35,7 +35,7 @@ export const eventSchema = {
|
|||||||
tags: {
|
tags: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
items: {
|
items: {
|
||||||
$ref: '#/components/schemas/tagSchema',
|
$ref: tagSchema.$id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -13,7 +13,7 @@ export const eventsSchema = {
|
|||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
items: { $ref: '#/components/schemas/eventSchema' },
|
items: { $ref: eventSchema.$id },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
@ -6,6 +6,9 @@ import { ADMIN } from '../../types/permissions';
|
|||||||
import { IEvent } from '../../types/events';
|
import { IEvent } from '../../types/events';
|
||||||
import Controller from '../controller';
|
import Controller from '../controller';
|
||||||
import { anonymise } from '../../util/anonymise';
|
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;
|
const version = 1;
|
||||||
export default class EventController extends Controller {
|
export default class EventController extends Controller {
|
||||||
@ -13,14 +16,36 @@ export default class EventController extends Controller {
|
|||||||
|
|
||||||
private anonymise: boolean = false;
|
private anonymise: boolean = false;
|
||||||
|
|
||||||
|
private openApiService: OpenApiService;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
config: IUnleashConfig,
|
config: IUnleashConfig,
|
||||||
{ eventService }: Pick<IUnleashServices, 'eventService'>,
|
{
|
||||||
|
eventService,
|
||||||
|
openApiService,
|
||||||
|
}: Pick<IUnleashServices, 'eventService' | 'openApiService'>,
|
||||||
) {
|
) {
|
||||||
super(config);
|
super(config);
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
this.anonymise = config.experimental?.anonymiseEventLog;
|
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);
|
this.get('/:name', this.getEventsForToggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +61,7 @@ export default class EventController extends Controller {
|
|||||||
|
|
||||||
async getEvents(
|
async getEvents(
|
||||||
req: Request<any, any, any, { project?: string }>,
|
req: Request<any, any, any, { project?: string }>,
|
||||||
res: Response,
|
res: Response<EventsSchema>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { project } = req.query;
|
const { project } = req.query;
|
||||||
let events: IEvent[];
|
let events: IEvent[];
|
||||||
@ -45,10 +70,17 @@ export default class EventController extends Controller {
|
|||||||
} else {
|
} else {
|
||||||
events = await this.eventService.getEvents();
|
events = await this.eventService.getEvents();
|
||||||
}
|
}
|
||||||
res.json({
|
|
||||||
|
const response: EventsSchema = {
|
||||||
version,
|
version,
|
||||||
events: this.fixEvents(events),
|
events: this.fixEvents(events),
|
||||||
});
|
};
|
||||||
|
this.openApiService.respondWithValidation(
|
||||||
|
200,
|
||||||
|
res,
|
||||||
|
eventsSchema.$id,
|
||||||
|
response,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getEventsForToggle(
|
async getEventsForToggle(
|
||||||
|
Loading…
Reference in New Issue
Block a user