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

[8.15] [Security Assistant] Aligning API Schemas (#188704) #189077

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

kibanamachine
Copy link
Contributor

Backport

This will backport the following commits from main to 8.15:

Questions ?

Please refer to the Backport tool documentation

## Summary

This PR aims to address elastic#183825
to ensure all our public API's have a corresponding OpenAPI spec and to
ensure that they are documented as intended.

I've updated the kbn-elastic-assistant-common `yarn openapi:bundle`
script to generate both `ess` and `serverless` artifacts (as per [this
issue](elastic/security-team#9516), which are
now created within the package (instead of `target`), and so are checked
in to `x-pack/packages/kbn-elastic-assistant-common/docs/openapi/`.

This also includes:

- [X] Create OpenAPI specs for the endpoints listed above (see
[issue](elastic#183825)).
  - They had already existed
- [X] Check if there are any other public endpoints that you own that
don't have OpenAPI specs and add them to the list above.
- All endpoints (public/internal) had specs, but did need to update the
`path`'s to make sure they were consistent with what was registered.
- [X] Make sure the specs you add are valid OpenAPI documents.
- [X] Make sure the specs you add match the actual API contract defined
in the code.
- [X] Mark the endpoints as available in ESS, or Serverless, or in both
offerings.

---
Initial evaluation of routes listed as missing specs in
elastic#183825:

- [X] `POST
/api/elastic_assistant/current_user/conversations/{id}/messages`
Latest/Actual Route:
`/internal/elastic_assistant/current_user/conversations/{id}/messages`
Route Handler:
https://github.com/elastic/kibana/blob/bae84d4569870dcecfd0cef346d2e0d38ac92160/x-pack/plugins/elastic_assistant/server/routes/user_conversations/append_conversation_messages_route.ts#L22
Schema:
https://github.com/elastic/kibana/blob/bae84d4569870dcecfd0cef346d2e0d38ac92160/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/crud_conversation_route.schema.yaml#L151-L191

- [X]  `POST /api/elastic_assistant/current_user/conversations`
Updated Route: `/api/security_ai_assistant/current_user/conversations`
Route Handler:
https://github.com/elastic/kibana/blob/1d4e9b9b53b5b6dcdc88c08ae5d9858daa483fe0/x-pack/plugins/elastic_assistant/server/routes/user_conversations/create_route.ts#L21
Schema:
https://github.com/elastic/kibana/blob/bae84d4569870dcecfd0cef346d2e0d38ac92160/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/crud_conversation_route.schema.yaml#L6-L39

- [X]  GET /api/elastic_assistant/current_user/conversations/_find
Updated Route:
`/api/security_ai_assistant/current_user/conversations/_find`
Route Handler:
https://github.com/elastic/kibana/blob/1d4e9b9b53b5b6dcdc88c08ae5d9858daa483fe0/x-pack/plugins/elastic_assistant/server/routes/user_conversations/find_route.ts#L26
Schema:
https://github.com/elastic/kibana/blob/1b872fbf9dc90d3c82a569a9faef9e360fc41171/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/find_conversations_route.schema.yaml#L94-L180

- [X]  DELETE /api/elastic_assistant/current_user/conversations/{id}
Updated Route:
`/api/security_ai_assistant/current_user/conversations/{id}`
Route Handler:
https://github.com/elastic/kibana/blob/1d5cf48a9700ee769f64256c23278fcfd8cecc5d/x-pack/plugins/elastic_assistant/server/routes/user_conversations/delete_route.ts#L19
Schema:
https://github.com/elastic/kibana/blob/bae84d4569870dcecfd0cef346d2e0d38ac92160/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/crud_conversation_route.schema.yaml#L116-L149

- [X] GET /api/elastic_assistant/current_user/conversations/{id}
Updated Route:
`/api/security_ai_assistant/current_user/conversations/{id}`
Route Handler:
https://github.com/elastic/kibana/blob/1d5cf48a9700ee769f64256c23278fcfd8cecc5d/x-pack/plugins/elastic_assistant/server/routes/user_conversations/read_route.ts#L21
Schema:
https://github.com/elastic/kibana/blob/bae84d4569870dcecfd0cef346d2e0d38ac92160/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/crud_conversation_route.schema.yaml#L42-L75

- [X]  PUT /api/elastic_assistant/current_user/conversations/{id}
Updated Route:
`/api/security_ai_assistant/current_user/conversations/{id}`
Route Handler:
https://github.com/elastic/kibana/blob/1d5cf48a9700ee769f64256c23278fcfd8cecc5d/x-pack/plugins/elastic_assistant/server/routes/user_conversations/update_route.ts#L24
Schema:
https://github.com/elastic/kibana/blob/bae84d4569870dcecfd0cef346d2e0d38ac92160/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/conversations/crud_conversation_route.schema.yaml#L76-L115

To continue with remaining public routes....

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit a51b775)
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/elastic-assistant-common 337 332 -5
Unknown metric groups

API count

id before after diff
@kbn/elastic-assistant-common 363 358 -5

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @spong

@kibanamachine kibanamachine merged commit 58e20ed into elastic:8.15 Jul 24, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants