Skip to content

Commit

Permalink
add API response types
Browse files Browse the repository at this point in the history
  • Loading branch information
neptunian committed Feb 7, 2020
1 parent 227b694 commit 6d05c51
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
38 changes: 37 additions & 1 deletion x-pack/plugins/ingest_manager/common/types/rest_spec/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,45 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { schema } from '@kbn/config-schema';
import { AssetReference } from '../epm';
import {
AssetReference,
CategorySummaryList,
Installable,
RegistryPackage,
Installed,
NotInstalled,
} from '../epm';

export interface GetCategoriesResponse {
response: CategorySummaryList;
success: boolean;
}
export const GetPackagesRequestSchema = {
query: schema.object({
category: schema.maybe(schema.string()),
}),
};

export interface GetPackagesResponse {
response: Array<
Installable<
Pick<
RegistryPackage,
| 'name'
| 'title'
| 'version'
| 'description'
| 'type'
| 'icons'
| 'internal'
| 'download'
| 'path'
>
>
>;
success: boolean;
}

export const GetFileRequestSchema = {
params: schema.object({
pkgkey: schema.string(),
Expand All @@ -25,6 +56,11 @@ export const GetInfoRequestSchema = {
}),
};

export interface GetInfoResponse {
response: Installed | NotInstalled;
success: boolean;
}

export const InstallPackageRequestSchema = {
params: schema.object({
pkgkey: schema.string(),
Expand Down
34 changes: 18 additions & 16 deletions x-pack/plugins/ingest_manager/server/routes/epm/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import { TypeOf } from '@kbn/config-schema';
import { RequestHandler, CustomHttpResponseOptions } from 'kibana/server';
import {
GetCategoriesResponse,
GetPackagesRequestSchema,
GetPackagesResponse,
GetFileRequestSchema,
GetInfoRequestSchema,
GetInfoResponse,
InstallPackageRequestSchema,
InstallPackageResponse,
DeletePackageRequestSchema,
Expand All @@ -29,12 +32,11 @@ import { getClusterAccessor } from '../../services/epm/cluster_access';
export const getCategoriesHandler: RequestHandler = async (context, request, response) => {
try {
const res = await getCategories();
return response.ok({
body: {
response: res,
success: true,
},
});
const body: GetCategoriesResponse = {
response: res,
success: true,
};
return response.ok({ body });
} catch (e) {
return response.customError({
statusCode: 500,
Expand All @@ -53,11 +55,12 @@ export const getListHandler: RequestHandler<
savedObjectsClient,
category: request.query.category,
});
const body: GetPackagesResponse = {
response: res,
success: true,
};
return response.ok({
body: {
response: res,
success: true,
},
body,
});
} catch (e) {
return response.customError({
Expand Down Expand Up @@ -105,12 +108,11 @@ export const getInfoHandler: RequestHandler<TypeOf<typeof GetInfoRequestSchema.p
const { pkgkey } = request.params;
const savedObjectsClient = context.core.savedObjects.client;
const res = await getPackageInfo({ savedObjectsClient, pkgkey });
return response.ok({
body: {
response: res,
success: true,
},
});
const body: GetInfoResponse = {
response: res,
success: true,
};
return response.ok({ body });
} catch (e) {
return response.customError({
statusCode: 500,
Expand Down

0 comments on commit 6d05c51

Please sign in to comment.