Skip to content

Commit

Permalink
[Automatic Import] Modify codegen to autogenerate openAPI spec code (#…
Browse files Browse the repository at this point in the history
…193243)

## Summary

#186085 introduced OpenAPI spec
for Automatic Import APIs. Since there was a
[bug](#186221) `x-codegen-enabled`
was set to `false`.

This PR modifies it to `true` and `node scripts/generate_openapi`
generated new API classes for the spec.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
bhapas authored Sep 18, 2024
1 parent f5975d2 commit e4180d2
Show file tree
Hide file tree
Showing 33 changed files with 223 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { Integration } from '../../common/api/model/common_attributes';
import { Integration } from '../../common';

export const testIntegration: Integration = {
name: 'integration',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { SamplesFormatName } from '../../common/api/model/common_attributes';
import { SamplesFormatName } from '../../common';
import type { Pipeline } from '../../common';

export const categorizationInitialPipeline: Pipeline = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { SamplesFormatName } from '../../common/api/model/common_attributes';
import { SamplesFormatName } from '../../common';

export const ecsMappingExpectedResults = {
mapping: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { SamplesFormatName } from '../../common/api/model/common_attributes';
import { SamplesFormatName } from '../../common';

export const kvState = {
lastExecutedChain: 'testchain',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { SamplesFormatName } from '../../common/api/model/common_attributes';
import { SamplesFormatName } from '../../common';

export const logFormatDetectionTestState = {
lastExecutedChain: 'testchain',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { SamplesFormatName } from '../../common/api/model/common_attributes';
import { SamplesFormatName } from '../../common';
import type { Pipeline } from '../../common';

export const relatedInitialPipeline: Pipeline = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import { z } from '@kbn/zod';

import {
PackageName,
DataStreamName,
LogSamples,
Connector,
LangSmithOptions,
DataStreamName,
PackageName,
} from '../model/common_attributes';
import { AnalyzeLogsAPIResponse } from '../model/response_schemas';
} from '../model/common_attributes.gen';
import { AnalyzeLogsAPIResponse } from '../model/response_schemas.gen';

export type AnalyzeLogsRequestBody = z.infer<typeof AnalyzeLogsRequestBody>;
export const AnalyzeLogsRequestBody = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ paths:
post:
summary: Analyzes log samples and processes them.
operationId: AnalyzeLogs
x-codegen-enabled: false
x-codegen-enabled: true
description: Analyzes log samples and processes them
tags:
- Analyze Logs API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { expectParseSuccess } from '@kbn/zod-helpers';
import { AnalyzeLogsRequestBody } from './analyze_logs_route';
import { AnalyzeLogsRequestBody } from './analyze_logs_route.gen';
import { getAnalyzeLogsRequestBody } from '../model/api_test.mock';

describe('Analyze Logs request schema', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
* 2.0.
*/

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Integration Assistatnt Build Integrarion API endpoint
* version: 1
*/

import { z } from '@kbn/zod';

import { Integration } from '../model/common_attributes';
import { Integration } from '../model/common_attributes.gen';

export type BuildIntegrationRequestBody = z.infer<typeof BuildIntegrationRequestBody>;
export const BuildIntegrationRequestBody = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ paths:
post:
summary: Builds Integration with the given input samples
operationId: BuildIntegration
x-codegen-enabled: false
x-codegen-enabled: true
description: Build Integration for the given input samples
tags:
- Build Integration API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,36 @@
* 2.0.
*/

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Integration Assistatnt Categorization API endpoint
* version: 1
*/

import { z } from '@kbn/zod';

import {
Connector,
DataStreamName,
LangSmithOptions,
PackageName,
Pipeline,
DataStreamName,
RawSamples,
Pipeline,
Connector,
SamplesFormat,
} from '../model/common_attributes';
import { CategorizationAPIResponse } from '../model/response_schemas';
LangSmithOptions,
} from '../model/common_attributes.gen';
import { CategorizationAPIResponse } from '../model/response_schemas.gen';

export type CategorizationRequestBody = z.infer<typeof CategorizationRequestBody>;
export const CategorizationRequestBody = z.object({
packageName: PackageName,
dataStreamName: DataStreamName,
rawSamples: RawSamples,
samplesFormat: SamplesFormat,
currentPipeline: Pipeline,
connectorId: Connector,
samplesFormat: SamplesFormat,
langSmithOptions: LangSmithOptions.optional(),
});
export type CategorizationRequestBodyInput = z.input<typeof CategorizationRequestBody>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ paths:
post:
summary: Builds Categorization processors based on the samples
operationId: Categorization
x-codegen-enabled: false
x-codegen-enabled: true
description: Perform Categorization for the given ecs mappings.
tags:
- Categorization API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { expectParseSuccess } from '@kbn/zod-helpers';
import { CategorizationRequestBody } from './categorization_route';
import { CategorizationRequestBody } from './categorization_route.gen';
import { getCategorizationRequestMock } from '../model/api_test.mock';

describe('Categorization request schema', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
* 2.0.
*/

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Integration Assistatnt Check Pipeline API endpoint
* version: 1
*/

import { z } from '@kbn/zod';

import { Pipeline, RawSamples } from '../model/common_attributes';
import { CheckPipelineAPIResponse } from '../model/response_schemas';
import { RawSamples, Pipeline } from '../model/common_attributes.gen';
import { CheckPipelineAPIResponse } from '../model/response_schemas.gen';

export type CheckPipelineRequestBody = z.infer<typeof CheckPipelineRequestBody>;
export const CheckPipelineRequestBody = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ paths:
post:
summary: Checks if the pipeline is valid for the given samples
operationId: CheckPipeline
x-codegen-enabled: false
x-codegen-enabled: true
description: Check latest pipeline against the input samples.
tags:
- Check Pipeline API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import {
PackageName,
DataStreamName,
RawSamples,
SamplesFormat,
Mapping,
Connector,
LangSmithOptions,
SamplesFormat,
} from '../model/common_attributes';
import { ESProcessorItem } from '../model/processor_attributes';
import { EcsMappingAPIResponse } from '../model/response_schemas';
} from '../model/common_attributes.gen';
import { ESProcessorItem } from '../model/processor_attributes.gen';
import { EcsMappingAPIResponse } from '../model/response_schemas.gen';

export type EcsMappingRequestBody = z.infer<typeof EcsMappingRequestBody>;
export const EcsMappingRequestBody = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ paths:
post:
summary: Builds ECS Mapping based on the input samples
operationId: EcsMapping
x-codegen-enabled: false
x-codegen-enabled: true
description: Perform ECS mapping for the given input JSON samples
tags:
- ECS Mapping API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { expectParseSuccess } from '@kbn/zod-helpers';
import { EcsMappingRequestBody } from './ecs_route';
import { EcsMappingRequestBody } from './ecs_route.gen';
import { getEcsMappingRequestMock } from '../model/api_test.mock';

describe('Ecs Mapping request schema', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* 2.0.
*/

import type { AnalyzeLogsRequestBody } from '../analyze_logs/analyze_logs_route';
import type { BuildIntegrationRequestBody } from '../build_integration/build_integration';
import type { CategorizationRequestBody } from '../categorization/categorization_route';
import type { EcsMappingRequestBody } from '../ecs/ecs_route';
import type { RelatedRequestBody } from '../related/related_route';
import type { DataStream, Integration, Pipeline } from './common_attributes';
import type { AnalyzeLogsRequestBody } from '../analyze_logs/analyze_logs_route.gen';
import type { BuildIntegrationRequestBody } from '../build_integration/build_integration.gen';
import type { CategorizationRequestBody } from '../categorization/categorization_route.gen';
import type { EcsMappingRequestBody } from '../ecs/ecs_route.gen';
import type { RelatedRequestBody } from '../related/related_route.gen';
import type { DataStream, Integration, Pipeline } from './common_attributes.gen';

const rawSamples = ['{"test1": "test1"}'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
* 2.0.
*/

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Common Rule Attributes
* version: not applicable
*/

import { z } from '@kbn/zod';

import { ESProcessorItem } from './processor_attributes';
import { ESProcessorItem } from './processor_attributes.gen';

/**
* Package name for the integration to be built.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ info:
version: "not applicable"
paths: {}
components:
x-codegen-enabled: false
x-codegen-enabled: true
schemas:
PackageName:
type: string
Expand Down
Loading

0 comments on commit e4180d2

Please sign in to comment.