Skip to content

Commit db5ff40

Browse files
authored
[integration] Fix check_pipeline response schema (elastic#187050)
## Summary The response schema for the /pipeline (checkPipeline) route is incorrect. By defining it with: ``` export const PipelineResults = z.array(z.object({})); export const Errors = z.array(z.object({})); ``` makes the pipelineResults items response to be always empty objects after parsing: <img width="628" alt="pipeline_response" src="https://github.com/elastic/kibana/assets/17747913/9582460c-ea31-43ea-854c-b15ee28ad0f2"> ### Changes Docs: These objects in the array are documents (`Docs` schema), so the correct type (already existing) has been assigned. `"./common_attributes.schema.yaml#/components/schemas/Docs"` Errors: Since we check them and respond with 400 in case they exist, the `errors` entry will never exist in a 200 response. It has been removed from the (200) response schema. Response shape: The response results shape has also been aligned with the rest of API routes: `response.results.docs`
1 parent bacc276 commit db5ff40

File tree

6 files changed

+21
-39
lines changed

6 files changed

+21
-39
lines changed

x-pack/plugins/integration_assistant/common/api/model/common_attributes.schema.yaml

-12
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,3 @@ components:
142142
logo:
143143
type: string
144144
description: The logo of the integration.
145-
146-
PipelineResults:
147-
type: array
148-
description: An array of pipeline results.
149-
items:
150-
type: object
151-
152-
Errors:
153-
type: array
154-
description: An array of errors.
155-
items:
156-
type: object

x-pack/plugins/integration_assistant/common/api/model/common_attributes.ts

-12
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,3 @@ export const Integration = z.object({
155155
*/
156156
logo: z.string().optional(),
157157
});
158-
159-
/**
160-
* An array of pipeline results.
161-
*/
162-
export type PipelineResults = z.infer<typeof PipelineResults>;
163-
export const PipelineResults = z.array(z.object({}));
164-
165-
/**
166-
* An array of errors.
167-
*/
168-
export type Errors = z.infer<typeof Errors>;
169-
export const Errors = z.array(z.object({}));

x-pack/plugins/integration_assistant/common/api/model/response_schemas.schema.yaml

+8-5
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ components:
5757
CheckPipelineAPIResponse:
5858
type: object
5959
required:
60-
- pipelineResults
60+
- results
6161
properties:
62-
pipelineResults:
63-
$ref: "./common_attributes.schema.yaml#/components/schemas/PipelineResults"
64-
errors:
65-
$ref: "./common_attributes.schema.yaml#/components/schemas/Errors"
62+
results:
63+
type: object
64+
required:
65+
- docs
66+
properties:
67+
docs:
68+
$ref: "./common_attributes.schema.yaml#/components/schemas/Docs"

x-pack/plugins/integration_assistant/common/api/model/response_schemas.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { z } from 'zod';
1818

19-
import { Docs, Errors, Mapping, Pipeline, PipelineResults } from './common_attributes';
19+
import { Docs, Mapping, Pipeline } from './common_attributes';
2020

2121
export type EcsMappingAPIResponse = z.infer<typeof EcsMappingAPIResponse>;
2222
export const EcsMappingAPIResponse = z.object({
@@ -44,6 +44,7 @@ export const RelatedAPIResponse = z.object({
4444

4545
export type CheckPipelineAPIResponse = z.infer<typeof CheckPipelineAPIResponse>;
4646
export const CheckPipelineAPIResponse = z.object({
47-
pipelineResults: PipelineResults,
48-
errors: Errors.optional(),
47+
results: z.object({
48+
docs: Docs,
49+
}),
4950
});

x-pack/plugins/integration_assistant/public/components/create_integration/create_integration_assistant/steps/review_step/use_check_pipeline.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ export const useCheckPipeline = ({
4949

5050
const ecsGraphResult = await runCheckPipelineResults(parameters, deps);
5151
if (abortController.signal.aborted) return;
52-
if (isEmpty(ecsGraphResult?.pipelineResults) || ecsGraphResult?.errors?.length) {
52+
if (isEmpty(ecsGraphResult?.results.docs)) {
5353
setError('No results for the pipeline');
5454
return;
5555
}
5656
setResult({
5757
pipeline: customPipeline,
58-
docs: ecsGraphResult.pipelineResults,
58+
docs: ecsGraphResult.results.docs,
5959
});
6060
} catch (e) {
6161
if (abortController.signal.aborted) return;
62-
setError(`Error: ${e.body.message}`);
62+
setError(`Error: ${e.body.message ?? e.message}`);
6363
} finally {
6464
setIsGenerating(false);
6565
}

x-pack/plugins/integration_assistant/server/routes/pipeline_routes.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ export function registerPipelineRoutes(router: IRouter<IntegrationAssistantRoute
3737
const services = await context.resolve(['core']);
3838
const { client } = services.core.elasticsearch;
3939
try {
40-
const results = await testPipeline(rawSamples, pipeline, client);
41-
if (results?.errors && results.errors.length > 0) {
42-
return res.badRequest({ body: JSON.stringify(results.errors) });
40+
const { errors, pipelineResults } = await testPipeline(rawSamples, pipeline, client);
41+
if (errors?.length) {
42+
return res.badRequest({ body: JSON.stringify(errors) });
4343
}
44-
return res.ok({ body: CheckPipelineResponse.parse(results) });
44+
return res.ok({
45+
body: CheckPipelineResponse.parse({ results: { docs: pipelineResults } }),
46+
});
4547
} catch (e) {
4648
return res.badRequest({ body: e });
4749
}

0 commit comments

Comments
 (0)