mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
9448461aaa
* Docs: start experimenting with OpenAPI and docusaurus * Docs: add docusaurus-theme-openapi-docs pkg * Wip: current status * Docs: Add 'docusaurus-plugin-api-docs' * Move openapi into own sidebar; generate from localhost * Chore: Update docusaurus plugin for OpenAPI * Add website/yarn.lock to git * Fix: fix CSS warning by using flex-end instead of end * docs: make openapi generated code work again * docs: make tags work properly with openapi sidebar * Docs/chore: update OpenAPI tag scheme. Add a whole bunch of new tags to make it easier to understand available tags in OpenAPI. * docs: point to new openapi docs from old api docs * docs: typo * Docs: link restructure * docs: add operation indicators to openapi docs * docs: change badge color for operations * docs: update openapi-docs package It now sorts tags the same as the schema * docs: pluralize APIs in slug * docs: update links to generated api docs * docs: update openapi snapshot tests with new tags * docs: conditionally load spec from localhost or from file * docs: Remove changes relating to immediate switchover * refactor: rename types; extract into separate file * docs: fix api doc links
75 lines
2.6 KiB
TypeScript
75 lines
2.6 KiB
TypeScript
import { Request, Response } from 'express';
|
|
import { IUnleashConfig } from '../../types/option';
|
|
import { IUnleashServices } from '../../types/services';
|
|
import { NONE } from '../../types/permissions';
|
|
import Controller from '../controller';
|
|
import { OpenApiService } from '../../services/openapi-service';
|
|
import { createResponseSchema } from '../../openapi/util/create-response-schema';
|
|
import { endpointDescriptions } from '../../openapi/endpoint-descriptions';
|
|
import { getStandardResponses } from '../../../lib/openapi/util/standard-responses';
|
|
import { createRequestSchema } from '../../../lib/openapi/util/create-request-schema';
|
|
import {
|
|
PlaygroundResponseSchema,
|
|
playgroundResponseSchema,
|
|
} from '../../../lib/openapi/spec/playground-response-schema';
|
|
import { PlaygroundRequestSchema } from '../../../lib/openapi/spec/playground-request-schema';
|
|
import { PlaygroundService } from '../../../lib/services/playground-service';
|
|
|
|
export default class PlaygroundController extends Controller {
|
|
private openApiService: OpenApiService;
|
|
|
|
private playgroundService: PlaygroundService;
|
|
|
|
constructor(
|
|
config: IUnleashConfig,
|
|
{
|
|
openApiService,
|
|
playgroundService,
|
|
}: Pick<IUnleashServices, 'openApiService' | 'playgroundService'>,
|
|
) {
|
|
super(config);
|
|
this.openApiService = openApiService;
|
|
this.playgroundService = playgroundService;
|
|
|
|
this.route({
|
|
method: 'post',
|
|
path: '',
|
|
handler: this.evaluateContext,
|
|
permission: NONE,
|
|
middleware: [
|
|
openApiService.validPath({
|
|
operationId: 'getPlayground',
|
|
tags: ['Playground'],
|
|
responses: {
|
|
...getStandardResponses(400, 401),
|
|
200: createResponseSchema('playgroundResponseSchema'),
|
|
},
|
|
requestBody: createRequestSchema('playgroundRequestSchema'),
|
|
...endpointDescriptions.admin.playground,
|
|
}),
|
|
],
|
|
});
|
|
}
|
|
|
|
async evaluateContext(
|
|
req: Request<any, any, PlaygroundRequestSchema>,
|
|
res: Response<PlaygroundResponseSchema>,
|
|
): Promise<void> {
|
|
const response = {
|
|
input: req.body,
|
|
features: await this.playgroundService.evaluateQuery(
|
|
req.body.projects,
|
|
req.body.environment,
|
|
req.body.context,
|
|
),
|
|
};
|
|
|
|
this.openApiService.respondWithValidation(
|
|
200,
|
|
res,
|
|
playgroundResponseSchema.$id,
|
|
response,
|
|
);
|
|
}
|
|
}
|