mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-10 17:53:36 +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 { upsertStrategySchema } from './spec/upsert-strategy-schema';
|
||||||
import { eventSchema } from './spec/event-schema';
|
import { eventSchema } from './spec/event-schema';
|
||||||
import { eventsSchema } from './spec/events-schema';
|
import { eventsSchema } from './spec/events-schema';
|
||||||
|
import { featureEventsSchema } from './spec/feature-events-schema';
|
||||||
import { clientApplicationSchema } from './spec/client-application-schema';
|
import { clientApplicationSchema } from './spec/client-application-schema';
|
||||||
|
|
||||||
// All schemas in `openapi/spec` should be listed here.
|
// All schemas in `openapi/spec` should be listed here.
|
||||||
@ -114,6 +115,7 @@ export const schemas = {
|
|||||||
exportParametersSchema,
|
exportParametersSchema,
|
||||||
featureEnvironmentSchema,
|
featureEnvironmentSchema,
|
||||||
featureEnvironmentMetricsSchema,
|
featureEnvironmentMetricsSchema,
|
||||||
|
featureEventsSchema,
|
||||||
featureSchema,
|
featureSchema,
|
||||||
featureMetricsSchema,
|
featureMetricsSchema,
|
||||||
featureUsageSchema,
|
featureUsageSchema,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
interface ISchemaObject {
|
export interface ISchemaObject {
|
||||||
[k: string]: IComponentSchema;
|
[k: string]: IComponentSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ interface IComponentSchema {
|
|||||||
|
|
||||||
export const includeSchemasRecursively = (
|
export const includeSchemasRecursively = (
|
||||||
schemas: ISchemaObject,
|
schemas: ISchemaObject,
|
||||||
): ISchemaObject =>
|
): { [key: string]: ISchemaObject } =>
|
||||||
Object.entries(schemas).reduce(([key, value], acc) => ({
|
Object.entries(schemas).reduce(([key, value], acc) => ({
|
||||||
...acc,
|
...acc,
|
||||||
[key]: value,
|
[key]: value,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { FromSchema } from 'json-schema-to-ts';
|
import { FromSchema } from 'json-schema-to-ts';
|
||||||
|
import { includeSchemasRecursively } from '../nested-schemas';
|
||||||
import { eventSchema } from './event-schema';
|
import { eventSchema } from './event-schema';
|
||||||
|
|
||||||
export const featureEventsSchema = {
|
export const featureEventsSchema = {
|
||||||
@ -16,10 +17,9 @@ export const featureEventsSchema = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
schemas: {
|
schemas: includeSchemasRecursively({
|
||||||
eventSchema,
|
eventSchema,
|
||||||
...eventSchema.components.schemas,
|
}),
|
||||||
},
|
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
@ -13,6 +13,10 @@ import {
|
|||||||
EventsSchema,
|
EventsSchema,
|
||||||
} from '../../../lib/openapi/spec/events-schema';
|
} from '../../../lib/openapi/spec/events-schema';
|
||||||
import { serializeDates } from '../../../lib/types/serialize-dates';
|
import { serializeDates } from '../../../lib/types/serialize-dates';
|
||||||
|
import {
|
||||||
|
featureEventsSchema,
|
||||||
|
FeatureEventsSchema,
|
||||||
|
} from '../../../lib/openapi/spec/feature-events-schema';
|
||||||
|
|
||||||
const version = 1;
|
const version = 1;
|
||||||
export default class EventController extends Controller {
|
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[] {
|
fixEvents(events: IEvent[]): IEvent[] {
|
||||||
@ -89,15 +107,22 @@ export default class EventController extends Controller {
|
|||||||
|
|
||||||
async getEventsForToggle(
|
async getEventsForToggle(
|
||||||
req: Request<{ name: string }>,
|
req: Request<{ name: string }>,
|
||||||
res: Response,
|
res: Response<FeatureEventsSchema>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const toggleName = req.params.name;
|
const toggleName = req.params.name;
|
||||||
const events = await this.eventService.getEventsForToggle(toggleName);
|
const events = await this.eventService.getEventsForToggle(toggleName);
|
||||||
|
|
||||||
res.json({
|
const response = {
|
||||||
version,
|
version,
|
||||||
toggleName,
|
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