[Security Solution] Auto-bundle Exceptions API OpenAPI specs (#188408)

**Addresses**: https://github.com/elastic/kibana/issues/184428

## Summary

This PR adds scripts for automatic bundling of Exceptions API OpenAPI specs as a part of PR pipeline. Corresponding resulting bundles are automatically committed in the Lists common package `kbn-securitysolution-exceptions-common` in the `docs/openapi/ess/` and `docs/openapi/serverless` folders (similar to https://github.com/elastic/kibana/pull/186384).
This commit is contained in:
Maxim Palenov 2024-07-18 16:05:43 +02:00 committed by GitHub
parent edad80ce5f
commit 179b78b499
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 3769 additions and 5 deletions

View file

@ -10,4 +10,7 @@ echo --- Security Solution OpenAPI Bundling
check_for_changed_files "yarn openapi:bundle" true
(cd packages/kbn-securitysolution-lists-common && yarn openapi:bundle)
check_for_changed_files "yarn openapi:bundle" true
(cd packages/kbn-securitysolution-exceptions-common && yarn openapi:bundle)
check_for_changed_files "yarn openapi:bundle" true

View file

@ -5,6 +5,7 @@ info:
paths:
/api/exception_lists/_duplicate:
post:
x-labels: [serverless, ess]
operationId: DuplicateExceptionList
x-codegen-enabled: true
summary: Duplicates an exception list

View file

@ -5,6 +5,7 @@ info:
paths:
/api/exception_lists/_export:
post:
x-labels: [serverless, ess]
operationId: ExportExceptionList
x-codegen-enabled: true
summary: Exports an exception list

View file

@ -3,7 +3,7 @@ info:
title: Find exception lists API endpoint
version: '2023-10-31'
paths:
/api/exception_lists/items/_find:
/api/exception_lists/_find:
get:
x-labels: [serverless, ess]
operationId: FindExceptionLists

View file

@ -5,6 +5,7 @@ info:
paths:
/api/exception_lists/_import:
post:
x-labels: [serverless, ess]
operationId: ImportExceptionList
x-codegen-enabled: true
summary: Imports an exception list

View file

@ -5,6 +5,7 @@
"private": true,
"version": "1.0.0",
"scripts": {
"openapi:generate": "node scripts/openapi_generate"
"openapi:generate": "node scripts/openapi_generate",
"openapi:bundle": "node scripts/openapi_bundle"
}
}

View file

@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
require('../../../src/setup_node_env');
const { join, resolve } = require('path');
const { bundle } = require('@kbn/openapi-bundler');
const ROOT = resolve(__dirname, '..');
(async () => {
await bundle({
sourceGlob: join(ROOT, 'api/**/*.schema.yaml'),
outputFilePath: join(
ROOT,
'docs/openapi/serverless/security_solution_exceptions_api_{version}.bundled.schema.yaml'
),
options: {
includeLabels: ['serverless'],
specInfo: {
title: 'Security Solution Exceptions API (Elastic Cloud Serverless)',
description:
"Exceptions API allows you to manage detection rule exceptions to prevent a rule from generating an alert from incoming events even when the rule's other criteria are met.",
},
},
});
await bundle({
sourceGlob: join(ROOT, 'api/**/*.schema.yaml'),
outputFilePath: join(
ROOT,
'docs/openapi/ess/security_solution_exceptions_api_{version}.bundled.schema.yaml'
),
options: {
includeLabels: ['ess'],
specInfo: {
title: 'Security Solution Exceptions API (Elastic Cloud and self-hosted)',
description:
"Exceptions API allows you to manage detection rule exceptions to prevent a rule from generating an alert from incoming events even when the rule's other criteria are met.",
},
},
});
})();

View file

@ -17,14 +17,14 @@ const ROOT = resolve(__dirname, '..');
await generate({
title: 'OpenAPI Exceptions API Schemas',
rootDir: ROOT,
sourceGlob: './**/*.schema.yaml',
sourceGlob: './api/**/*.schema.yaml',
templateName: 'zod_operation_schema',
});
await generate({
title: 'Exceptions API client for tests',
rootDir: ROOT,
sourceGlob: './**/*.schema.yaml',
sourceGlob: './api/**/*.schema.yaml',
templateName: 'api_client_supertest',
skipLinting: true,
bundle: {

View file

@ -122,7 +122,7 @@ export function SecuritySolutionApiProvider({ getService }: FtrProviderContext)
},
findExceptionLists(props: FindExceptionListsProps) {
return supertest
.get('/api/exception_lists/items/_find')
.get('/api/exception_lists/_find')
.set('kbn-xsrf', 'true')
.set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31')
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')