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] Adjust OpenAPI specs bundler for doc requirements #181944

Merged
merged 37 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2859339
fix remove props processor to remove props with false and undefined v…
maximpn Apr 19, 2024
3a78854
improve ref inlining to separate from prop removal
maximpn Apr 19, 2024
451b82e
merge documents into one yaml OAS spec
maximpn Apr 22, 2024
11de7b3
flatten folded allOf
maximpn Apr 22, 2024
ad3ba3b
reorganize document merge functionality
maximpn Apr 25, 2024
a97ac7b
reduce folded all of items
maximpn Apr 25, 2024
58e09b3
reorganize node processors
maximpn Apr 26, 2024
42509a3
split output bundled specs by versions
maximpn Apr 26, 2024
568a33d
check for ref conflicts in one schema file
maximpn Apr 26, 2024
14bcdd9
fix bundler tests
maximpn Apr 26, 2024
6424396
fix a bug in merge all of items processor
maximpn Apr 29, 2024
6192736
add bundler functional tests for allOf cases
maximpn Apr 29, 2024
a9c827b
extend inlining tests
maximpn Apr 29, 2024
c9a107b
allow specifying custom info object
maximpn Apr 29, 2024
6f7d2be
extend OpenAPI bundler tests with more complex scenarios
maximpn Apr 29, 2024
5a9a557
hide /engine/settings endpoint from the public endpoints bundle
maximpn Apr 29, 2024
4f42b12
update README
maximpn Apr 29, 2024
3b3caf6
improve code readability
maximpn Apr 30, 2024
8fa6b3a
improve readability
maximpn Apr 30, 2024
8e447d7
merge path parameters
maximpn Apr 30, 2024
9551308
do not allow to merge OAS with incompatible versions
maximpn Apr 30, 2024
578e151
prevent creation of optional fields with undefined value
maximpn Apr 30, 2024
153bb33
improve version OAS conflict error message
maximpn May 1, 2024
e668ef1
give an explanation of folded allOf
maximpn May 6, 2024
3125d6d
simplify allOf's flattening functionality
maximpn May 6, 2024
8a8d104
avoid duplicated required fields
maximpn May 6, 2024
30b2a3b
improve readability
maximpn May 6, 2024
aac6959
update the comment
maximpn May 6, 2024
5eae808
fix OAS incompatibility in tests
maximpn May 6, 2024
06bc432
add tests to verify x- props get removed
maximpn May 6, 2024
29f5955
allow to stringify document circular references
maximpn May 6, 2024
43d72f6
simplify merging non conflicting allOf items implementation
maximpn May 6, 2024
a83cdfb
add shouldRemove processor's cb function
maximpn May 6, 2024
b738427
rename node processors methods for better readability
maximpn May 6, 2024
d81b14c
mark /api/risk_scores/calculation/entity API as internal
maximpn May 8, 2024
ee0c313
improve tests readability
maximpn May 8, 2024
843b844
get rid of rootDir
maximpn May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions packages/kbn-openapi-bundler/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# OpenAPI Specs Bundler for Kibana

`@kbn/openapi-bundler` is a tool for transforming multiple OpenAPI specification files (source specs) into a single bundled specification file (target spec).
This can be used for API docs generation purposes. This approach allows you to:
`@kbn/openapi-bundler` is a tool for transforming multiple OpenAPI specification files (source specs) into a bundled specification file(s) (target spec). The number of resulting bundles depends on a number of versions
used in the OpenAPI specification files. The package can be used for API documentation generation purposes. This approach allows you to:

- Abstract away the knowledge of where you keep your OpenAPI specs, how many specs there are, and how to find them. The Docs team should only know where a single file is located - the bundle.
- Abstract away the knowledge of where you keep your OpenAPI specs, how many specs are there, and how to find them. Consumer should only know where result files are located - the bundles.
- Omit internal API endpoints from the bundle.
- Omit API endpoints that are hidden behind a feature flag and haven't been released yet.
- Omit parts of schemas that are hidden behind a feature flag (e.g. a new property added to an existing response schema).
- Omit custom OpenAPI attributes from the bundle, such as `x-codegen-enabled`, `x-internal`, and `x-modify` (see below).
- Transform the target schema according to the custom OpenAPI attributes, such as `x-modify`.
- Resolve references and inline some of them for better readability. The bundled file contains only local references and paths.
- Resolve references, inline some of them and merge allOf object schemas for better readability. The bundled file contains only local references and paths.

## Getting started

Expand All @@ -22,16 +22,22 @@ Currently package supports only programmatic API. As the next step you need to c
```ts
require('../../../../../src/setup_node_env');
const { bundle } = require('@kbn/openapi-bundler');
const { resolve } = require('path');
const { join, resolve } = require('path');

// define ROOT as `my-plugin` instead of `my-plugin/scripts/openapi`
// pay attention to this constant when your script's location is different
const ROOT = resolve(__dirname, '../..');

bundle({
rootDir: ROOT, // Root path e.g. plugin root directory
sourceGlob: './**/*.schema.yaml', // Glob pattern to find OpenAPI specification files
outputFilePath: './target/openapi/my-plugin.bundled.schema.yaml', //
// Root path e.g. plugin root directory
rootDir: ROOT,
// Glob pattern to find OpenAPI specification files, relative to `rootDir`
sourceGlob: './**/*.schema.yaml',
// Output file path. Absolute or related to the node.js working directory.
// It may contain `{version}` placeholder which is optional. `{version}` placeholder
// will be replaced with the bundled specs version or filename will be prepended with
// version when placeholder is omitted, e.g. `2023-10-31-my-plugin.bundled.schema.yaml`.
outputFilePath: join(ROOT, 'target/openapi/my-plugin-{version}.bundled.schema.yaml'),
});
```

Expand Down