[Security Solution] Adjust OpenAPI specs bundler for doc requirements#181944
[Security Solution] Adjust OpenAPI specs bundler for doc requirements#181944maximpn merged 37 commits intoelastic:mainfrom
Conversation
0dc5fa6 to
473f05c
Compare
|
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
|
Pinging @elastic/security-solution (Team: SecuritySolution) |
|
Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management) |
d2584d2 to
6aedaf1
Compare
xcrzx
left a comment
There was a problem hiding this comment.
Thank you, @maximpn, for this awesome improvement to the bundler, it's really huge 🎉 I tested the PR locally, and the bundled Security Solution APIs look correct. I was able to easily export all our APIs at once to Postman, and this is 🔥🔥🔥 It's a big step forward for our tooling.
I left several comments regarding tests that produce invalid OpenAPI, but that doesn't seem to affect our API bundle, though. Maybe it's just the tests themselves that need to be fixed. Also, I've made a couple of comments regarding the readability and maintainability of the bundler code, so please take a look, and I'll be happy to discuss this in more detail if needed.
...i-bundler/src/bundler/document_processors/reduce_all_of_items/flatten_folded_all_of_items.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Why is this method called leave? It is somewhat confusing because it's used to modify a node. Let's rename it to something more straightforward, like modify.
There was a problem hiding this comment.
There are two phased at which OpenAPI document is traversed.
- At the first phase diving from root to leaves happens (like event's capture phase in DOM). It means we
entera subtree. Processing isn't happening here so it's convenient to analyze not yet processed nodes. For example understand which nodes should be inlined. - At the second phase bubbling from leaves to root happens (like event's bubble phase in DOM). It means we
leaves subtree. It's possible to modify a node during this phase while it's not necessary.
This naming highlights the flexibility. enter and leave methods could be used to collect metrics or analyze the document. Current implementation doesn't have such functionality but it could be added without any effort.
I extended a comment for DocumentNodeProcessor in packages/kbn-openapi-bundler/src/bundler/types.ts. While we don't expose DocumentNodeProcessor API I think package README shouldn't be updated.
...i-bundler/src/bundler/document_processors/reduce_all_of_items/flatten_folded_all_of_items.ts
Outdated
Show resolved
Hide resolved
...er/src/bundler/document_processors/reduce_all_of_items/merge_non_conflicting_all_of_items.ts
Outdated
Show resolved
Hide resolved
...er/src/bundler/document_processors/reduce_all_of_items/merge_non_conflicting_all_of_items.ts
Outdated
Show resolved
Hide resolved
...uce_all_of/merge_all_of_items_with_inlined_refs_in_different_document_branches/expected.yaml
Outdated
Show resolved
Hide resolved
..._all_of/merge_all_of_items_with_inlined_refs_in_different_document_branches/spec.schema.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Let's remove the commented code and the recursive_spec files
There was a problem hiding this comment.
I managed to uncomment the test by allowing to write documents with circular references by modifying writeYamlDocument.
There was a problem hiding this comment.
Should we also check that other x- properties are getting removed?
There was a problem hiding this comment.
I've added extra tests.
There was a problem hiding this comment.
Getting to the last test in this file, I started understanding that this snapshot-like testing requires quite a lot of concentration and effort to read through and understand what is being covered. For each test, you need to read the description here, then navigate to the test folder, locate the source files and the expected YAML, then open them side by side, and compare their content to see if the input matches the expected output. This process is pretty error-prone, and as we've seen above, snapshots just captured invalid output, leaving it up to humans to verify its correctness.
I wonder what options we have to improve this experience. Maybe we could inline some of the test cases that are simple enough so the input and output are easily visible and reduce the boilerplate in the test files? What else could we do?
6aedaf1 to
b0c93da
Compare
49e35c6 to
810d5bc
Compare
|
After syncing with @xcrzx via Zoom we discussed improvements to maintainability. The following has been decided and addressed
|
9c70c5e to
ee0c313
Compare
machadoum
left a comment
There was a problem hiding this comment.
Entity Analytics changes LGTM!
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: cc @maximpn |
Addresses: https://github.com/elastic/security-team/issues/7981
Relates to: #171526
Summary
This PR adjusts OpenAPI Bundler (
kbn-openapi-bundlerpackage) based on Docs Engineering team requirements. Main requirements include producing one valid OpenAPI spec bundle file. After adjustments OpenAPI Bundler one valid OpenAPI spec bundle file per API version e.g.2023-10-31-my-oas.bundled.schema.yaml.Details
This PR further improves #171526 to satisfy Docs Engineering team requirements and includes the following adjustments and improvements
outputFilePathindependent fromrootDiroutputFilePathcan be an absolute or relative to node.js working directory path. Additionally it can contain{version}placeholder to adjust where API version is placed in the result bundle file name. API prepends the result bundle file name if{version}is omitted.allOfitemsInlined schemas lead to
allOffolder into each other as well as having multiple object schemas which could be merged. Docs Engineering team stated potential problems related to foldedallOfitems.3.0.3and3.1.0summary,descriptionandpropertiesschemas)Besides the changes above PR contains minor bug fixing and improvements.
Note: It intentionally doesn't include bundling configuration changes like integration it into PR's build pipeline and focuses only on functional changes. Bundling configuration will be addressed separately to avoid spreading reviewers focus.