-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Support bundling ESS and Serverless OAS separately (
#184348) **Resolves: elastic/security-team#9516 ## Summary As a part of Serverless API reference documentation effort we need to have an ability to produce independent Serverless and ESS OpenAPI specification (OAS) bundles. This PR addresses this issue by adding a new custom property `x-labels` (applicable to OAS operation objects) representing an array of strings and bundling configuration option to exclude anything marked with specific labels. ## How does it work? Added functionality allows to mark **OAS operation object** (objects defined under an API endpoint path as a HTTP method like `get`, `post` and etc) with arbitrary labels by using `x-labels` custom property like in an example below ```yaml paths: /api/some_path: get: x-labels: - label1 - label2 ``` This labelling **DOESN'T** change produced bundle by itself. It's required to use bundler's `includeLabels` option to include API endpoint operation object(s). `includeLabels` accepts a list of labels. An operation object is included when it has a label matching labels passed to `includeLabels`. In mathematical terms operation object's labels set intersects with `includeLabels`. ## How to use it for producing separate Serverless and ESS bundles? - Mark OAS operation objects (HTTP methods like `get` or `post`) with `x-labels` custom property. An example below has all operation objects under `/api/some_path` path labeled with `ess` label as well as operation objects under `/api/another_path` path. On top of that `GET /api/another_path` has `serverless` label as well. ```yaml ... paths: /api/some_path: get: x-labels: [ess] ... post: x-labels: [ess] ... /api/another_path: get: x-labels: [ess, serverless] ... post: x-labels: [ess] ... ... ``` - Configure bundler with bundling options to include specific labels. `options.includeLabels` is responsible for including document nodes labeled with specific labels. You need two bundler invocations with different `options.includeLabels` values like below ```js bundle({ // (1) ... options: { includeLabels: ['serverless'], }, }); bundle({ // (2) ... options: { includeLabels: ['ess'], }, }); ``` It will produce two following bundles (1) for Serverless ```yaml ... paths: /api/another_path: get: ... ... ``` and (2) for ESS ```yaml ... paths: /api/some_path: get: ... post: ... /api/another_path: get: ... post: ... ... ``` You may notice (2) has everything included since each operation object is labeled with `ess` label.
- Loading branch information
Showing
62 changed files
with
1,645 additions
and
502 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Document abstraction. We don't mind OpenAPI `3.0` and `3.1` differences. | ||
*/ | ||
export type Document = Record<string, unknown>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
230 changes: 0 additions & 230 deletions
230
packages/kbn-openapi-bundler/src/bundler/process_document.test.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.