Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Add missing Lists API OpenAPI specifications #185865

Merged
merged 27 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cdfb700
add missing list container API OAS
maximpn Jun 9, 2024
78a13be
add missing list items API OAS
maximpn Jun 10, 2024
09508b9
add some missing lists API OAS
maximpn Jun 10, 2024
27040a7
add missing list DS management API OAS
maximpn Jun 10, 2024
c9e186b
add missing find list items API OAS
maximpn Jun 10, 2024
d88414b
add missing import and export list items API OAS
maximpn Jun 10, 2024
7f7b374
add lists plugin code generation script
maximpn Jun 10, 2024
c5810fd
move Lists API OAS to a package
maximpn Jun 11, 2024
0d64049
enable automatic kbn-securitysolution-lists-common OAS code generation
maximpn Jun 11, 2024
eb94235
add package dependencies
maximpn Jun 11, 2024
4f97999
make packages_codegen.sh executable
maximpn Jun 12, 2024
b42037b
add packages ownership
maximpn Jun 12, 2024
ef43e7f
update package info
maximpn Jun 12, 2024
c291e3d
split list common into list common and list schemas
maximpn Jun 12, 2024
3fa682a
rename meta to metadata
maximpn Jun 12, 2024
694c746
fix package imports
maximpn Jun 12, 2024
a6a74b9
move buildRouteValidationWithZod to kbn-zod-helpers package
maximpn Jun 13, 2024
e8e2768
replace Lists API route io-ts schemas with Zod schemas
maximpn Jun 13, 2024
15bbed3
add missing dependencies
maximpn Jun 13, 2024
1b40873
get rid of removed importListItemResponse
maximpn Jun 14, 2024
881a088
fix schemas
maximpn Jun 14, 2024
8a1ddef
fix brittle integration tests
maximpn Jun 14, 2024
f67f20f
make list item's value required
maximpn Jun 18, 2024
5d2af05
test the precise error message
maximpn Jun 18, 2024
5ef4a5d
move Lists API codegen to the security_solution_codegen script
maximpn Jun 18, 2024
7270a90
enable codegen only for schemas
maximpn Jun 18, 2024
a4a79d5
fix info messages
maximpn Jun 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,17 @@ source .buildkite/scripts/common/util.sh

echo --- Security Solution OpenAPI Code Generation

echo OpenAPI Common Package

(cd packages/kbn-openapi-common && yarn openapi:generate)
check_for_changed_files "yarn openapi:generate" true

echo Lists API Common Package

(cd packages/kbn-securitysolution-lists-common && yarn openapi:generate)
check_for_changed_files "yarn openapi:generate" true

echo Security Solution Plugin

(cd x-pack/plugins/security_solution && yarn openapi:generate)
check_for_changed_files "yarn openapi:generate" true
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ x-pack/plugins/observability_solution/observability_shared @elastic/observabilit
x-pack/test/security_api_integration/plugins/oidc_provider @elastic/kibana-security
test/common/plugins/otel_metrics @elastic/obs-ux-infra_services-team
packages/kbn-openapi-bundler @elastic/security-detection-rule-management
packages/kbn-openapi-common @elastic/security-detection-rule-management
packages/kbn-openapi-generator @elastic/security-detection-rule-management
packages/kbn-optimizer @elastic/kibana-operations
packages/kbn-optimizer-webpack-helpers @elastic/kibana-operations
Expand Down Expand Up @@ -751,6 +752,7 @@ packages/kbn-securitysolution-list-api @elastic/security-detection-engine
packages/kbn-securitysolution-list-constants @elastic/security-detection-engine
packages/kbn-securitysolution-list-hooks @elastic/security-detection-engine
packages/kbn-securitysolution-list-utils @elastic/security-detection-engine
packages/kbn-securitysolution-lists-common @elastic/security-detection-engine
packages/kbn-securitysolution-rules @elastic/security-detection-engine
packages/kbn-securitysolution-t-grid @elastic/security-detection-engine
packages/kbn-securitysolution-utils @elastic/security-detection-engine
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@
"@kbn/observability-shared-plugin": "link:x-pack/plugins/observability_solution/observability_shared",
"@kbn/oidc-provider-plugin": "link:x-pack/test/security_api_integration/plugins/oidc_provider",
"@kbn/open-telemetry-instrumented-plugin": "link:test/common/plugins/otel_metrics",
"@kbn/openapi-common": "link:packages/kbn-openapi-common",
"@kbn/osquery-io-ts-types": "link:packages/kbn-osquery-io-ts-types",
"@kbn/osquery-plugin": "link:x-pack/plugins/osquery",
"@kbn/paertial-results-example-plugin": "link:examples/partial_results_example",
Expand Down Expand Up @@ -761,6 +762,7 @@
"@kbn/securitysolution-list-constants": "link:packages/kbn-securitysolution-list-constants",
"@kbn/securitysolution-list-hooks": "link:packages/kbn-securitysolution-list-hooks",
"@kbn/securitysolution-list-utils": "link:packages/kbn-securitysolution-list-utils",
"@kbn/securitysolution-lists-common": "link:packages/kbn-securitysolution-lists-common",
"@kbn/securitysolution-rules": "link:packages/kbn-securitysolution-rules",
"@kbn/securitysolution-t-grid": "link:packages/kbn-securitysolution-t-grid",
"@kbn/securitysolution-utils": "link:packages/kbn-securitysolution-utils",
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-openapi-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# OpenAPI Common Schemas

This package contains common reusable schemas like `NonEmptyString` to be reused by any OpenAPI specification defined inside Kibana.
5 changes: 5 additions & 0 deletions packages/kbn-openapi-common/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/openapi-common",
"owner": "@elastic/security-detection-rule-management"
}
banderror marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions packages/kbn-openapi-common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"description": "OpenAPI common schemas for Kibana",
"license": "SSPL-1.0 OR Elastic License 2.0",
"name": "@kbn/openapi-common",
"private": true,
"version": "1.0.0",
"scripts": {
"openapi:generate": "node scripts/openapi_generate"
}
}

31 changes: 31 additions & 0 deletions packages/kbn-openapi-common/schemas/error_responses.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/

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

import { z } from 'zod';

export type PlatformErrorResponse = z.infer<typeof PlatformErrorResponse>;
export const PlatformErrorResponse = z.object({
statusCode: z.number().int(),
error: z.string(),
message: z.string(),
});

export type SiemErrorResponse = z.infer<typeof SiemErrorResponse>;
export const SiemErrorResponse = z.object({
status_code: z.number().int(),
message: z.string(),
});
32 changes: 32 additions & 0 deletions packages/kbn-openapi-common/schemas/error_responses.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.0.0
info:
title: Error response schemas
version: 'not applicable'
paths: {}
components:
x-codegen-enabled: true
schemas:
PlatformErrorResponse:
type: object
properties:
statusCode:
type: integer
error:
type: string
message:
type: string
required:
- statusCode
- error
- message

SiemErrorResponse:
type: object
properties:
status_code:
type: integer
message:
type: string
required:
- status_code
- message
33 changes: 33 additions & 0 deletions packages/kbn-openapi-common/schemas/primitives.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.
*/

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

import { z } from 'zod';

/**
* A string that is not empty and does not contain only whitespace
*/
export type NonEmptyString = z.infer<typeof NonEmptyString>;
export const NonEmptyString = z
.string()
.min(1)
.regex(/^(?! *$).+$/);

/**
* A universally unique identifier
*/
export type UUID = z.infer<typeof UUID>;
export const UUID = z.string().uuid();
18 changes: 18 additions & 0 deletions packages/kbn-openapi-common/schemas/primitives.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
openapi: 3.0.0
info:
title: Shared Primitives Schema
version: 'not applicable'
paths: {}
components:
x-codegen-enabled: true
schemas:
NonEmptyString:
type: string
pattern: ^(?! *$).+$
minLength: 1
description: A string that is not empty and does not contain only whitespace

UUID:
type: string
format: uuid
description: A universally unique identifier
22 changes: 22 additions & 0 deletions packages/kbn-openapi-common/scripts/openapi_generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 { resolve } = require('path');
const { generate } = require('@kbn/openapi-generator');

const ROOT = resolve(__dirname, '..');

(async () => {
await generate({
title: 'OpenAPI Common Schemas (kbn-openapi-common)',
rootDir: ROOT,
sourceGlob: './schemas/**/*.schema.yaml',
templateName: 'zod_operation_schema',
});
})();
10 changes: 10 additions & 0 deletions packages/kbn-openapi-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"outDir": "target/types",
"types": ["jest", "node"]
},
"exclude": ["target/**/*"],
"extends": "../../tsconfig.base.json",
"include": ["**/*.ts"],
"kbn_references": []
}
20 changes: 20 additions & 0 deletions packages/kbn-securitysolution-lists-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Security Solution Lists common package

The package contains common files for the Lists feature.

`common` in the name highlights that this package is intended to combine any common entities related to Lists in this package. E.g. the other `kbn-securitysolution-list-*` packages
content should be moved here while `kbn-securitysolution-io-ts-list-types` package should be
gone eventually.

## API folder

`api` folder contains OpenAPI schemas for Security Solution Lists feature. There are automatically generated Zod schemas and TS types for each schemas located in corresponding
`*.gen.ts` files.

**Please add any Lists feature related schemas to this package.**

TS types and/or Zod schemas can be imported in a plugin or another package like

```ts
import { CreateListRequestBody } from '@kbn/securitysolution-lists-common/api';
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.
*/

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Create list API endpoint
* version: 2023-10-31
*/

import { z } from 'zod';

import {
ListId,
ListName,
ListDescription,
ListType,
ListMetadata,
} from '../model/list_common.gen';
import { List } from '../model/list_schemas.gen';

export type CreateListRequestBody = z.infer<typeof CreateListRequestBody>;
export const CreateListRequestBody = z.object({
id: ListId.optional(),
name: ListName,
description: ListDescription,
type: ListType,
serializer: z.string().optional(),
deserializer: z.string().optional(),
meta: ListMetadata.optional(),
version: z.number().int().min(1).optional().default(1),
});
export type CreateListRequestBodyInput = z.input<typeof CreateListRequestBody>;

export type CreateListResponse = z.infer<typeof CreateListResponse>;
export const CreateListResponse = List;
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
openapi: 3.0.0
info:
title: Create list API endpoint
version: '2023-10-31'
paths:
/api/lists:
post:
x-labels: [serverless, ess]
operationId: CreateList
x-codegen-enabled: true
summary: Creates a list
tags:
- List API
requestBody:
description: List's properties
required: true
content:
application/json:
schema:
type: object
properties:
id:
$ref: '../model/list_common.schema.yaml#/components/schemas/ListId'
name:
$ref: '../model/list_common.schema.yaml#/components/schemas/ListName'
description:
$ref: '../model/list_common.schema.yaml#/components/schemas/ListDescription'
type:
$ref: '../model/list_common.schema.yaml#/components/schemas/ListType'
serializer:
type: string
deserializer:
type: string
meta:
$ref: '../model/list_common.schema.yaml#/components/schemas/ListMetadata'
version:
type: integer
minimum: 1
default: 1
required:
- name
- description
- type
responses:
200:
description: Successful response
content:
application/json:
schema:
$ref: '../model/list_schemas.schema.yaml#/components/schemas/List'
400:
description: Invalid input data response
content:
application/json:
schema:
oneOf:
- $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse'
- $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse'
401:
description: Unsuccessful authentication response
content:
application/json:
schema:
$ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse'
403:
description: Not enough privileges response
content:
application/json:
schema:
$ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse'
409:
description: List already exists response
content:
application/json:
schema:
$ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse'
500:
description: Internal server error response
content:
application/json:
schema:
$ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Create list DS API endpoint
* version: 2023-10-31
*/

import { z } from 'zod';

export type CreateListIndexResponse = z.infer<typeof CreateListIndexResponse>;
export const CreateListIndexResponse = z.object({
acknowledged: z.boolean(),
});
Loading