mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
Feat: Add openapi for feature events
This commit is contained in:
parent
472e300386
commit
19d1da8faf
@ -84,6 +84,7 @@ 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 { featureEventsSchema } from './spec/feature-events-schema';
|
||||
import { clientApplicationSchema } from './spec/client-application-schema';
|
||||
|
||||
// All schemas in `openapi/spec` should be listed here.
|
||||
@ -114,6 +115,7 @@ export const schemas = {
|
||||
exportParametersSchema,
|
||||
featureEnvironmentSchema,
|
||||
featureEnvironmentMetricsSchema,
|
||||
featureEventsSchema,
|
||||
featureSchema,
|
||||
featureMetricsSchema,
|
||||
featureUsageSchema,
|
||||
|
@ -1,4 +1,4 @@
|
||||
interface ISchemaObject {
|
||||
export interface ISchemaObject {
|
||||
[k: string]: IComponentSchema;
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ interface IComponentSchema {
|
||||
|
||||
export const includeSchemasRecursively = (
|
||||
schemas: ISchemaObject,
|
||||
): ISchemaObject =>
|
||||
): { [key: string]: ISchemaObject } =>
|
||||
Object.entries(schemas).reduce(([key, value], acc) => ({
|
||||
...acc,
|
||||
[key]: value,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { FromSchema } from 'json-schema-to-ts';
|
||||
import { includeSchemasRecursively } from '../nested-schemas';
|
||||
import { eventSchema } from './event-schema';
|
||||
|
||||
export const featureEventsSchema = {
|
||||
@ -16,10 +17,9 @@ export const featureEventsSchema = {
|
||||
},
|
||||
},
|
||||
components: {
|
||||
schemas: {
|
||||
schemas: includeSchemasRecursively({
|
||||
eventSchema,
|
||||
...eventSchema.components.schemas,
|
||||
},
|
||||
}),
|
||||
},
|
||||
} as const;
|
||||
|
||||
|
@ -13,6 +13,10 @@ import {
|
||||
EventsSchema,
|
||||
} from '../../../lib/openapi/spec/events-schema';
|
||||
import { serializeDates } from '../../../lib/types/serialize-dates';
|
||||
import {
|
||||
featureEventsSchema,
|
||||
FeatureEventsSchema,
|
||||
} from '../../../lib/openapi/spec/feature-events-schema';
|
||||
|
||||
const version = 1;
|
||||
export default class EventController extends Controller {
|
||||
@ -50,7 +54,21 @@ export default class EventController extends Controller {
|
||||
],
|
||||
});
|
||||
|
||||
this.get('/:name', this.getEventsForToggle);
|
||||
this.route({
|
||||
method: 'get',
|
||||
path: '/:name',
|
||||
handler: this.getEventsForToggle,
|
||||
permission: ADMIN,
|
||||
middleware: [
|
||||
openApiService.validPath({
|
||||
operationId: 'getEventsForToggle',
|
||||
tags: ['admin'],
|
||||
responses: {
|
||||
200: createResponseSchema('featureEventsSchema'),
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
fixEvents(events: IEvent[]): IEvent[] {
|
||||
@ -89,15 +107,22 @@ export default class EventController extends Controller {
|
||||
|
||||
async getEventsForToggle(
|
||||
req: Request<{ name: string }>,
|
||||
res: Response,
|
||||
res: Response<FeatureEventsSchema>,
|
||||
): Promise<void> {
|
||||
const toggleName = req.params.name;
|
||||
const events = await this.eventService.getEventsForToggle(toggleName);
|
||||
|
||||
res.json({
|
||||
const response = {
|
||||
version,
|
||||
toggleName,
|
||||
events: this.fixEvents(events),
|
||||
});
|
||||
events: serializeDates(this.fixEvents(events)),
|
||||
};
|
||||
|
||||
this.openApiService.respondWithValidation(
|
||||
200,
|
||||
res,
|
||||
featureEventsSchema.$id,
|
||||
response,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user