-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[HTTP/OAS] Ability to exclude routes from introspection #192675
[HTTP/OAS] Ability to exclude routes from introspection #192675
Conversation
/ci |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Public APIs missing comments
Unknown metric groupsAPI count
To update your PR or re-run it, just comment with: |
/ci |
let filters: GenerateOpenApiDocumentOptionsFilters; | ||
let query: TypeOf<typeof querySchema>; | ||
try { | ||
query = querySchema.validate(req.query); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor to using config-schema
, just cleanup
packages/core/http/core-http-router-server-internal/src/router.ts
Outdated
Show resolved
Hide resolved
Pinging @elastic/kibana-core (Team:Core) |
>( | ||
routes: R[], | ||
filters: GenerateOpenApiDocumentOptionsFilters = {} | ||
): R[] => { | ||
if (Object.getOwnPropertyNames(filters).length === 0) return routes; | ||
return routes.filter((route) => { | ||
if (route.options.excludeFromOAS) return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where we actually exclude routes from OAS docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a nit you can ignore or address as you see fit. otherwise LGTM
@@ -237,7 +238,7 @@ export class Router<Context extends RequestHandlerContextBase = RequestHandlerCo | |||
if (excludeVersionedRoutes) { | |||
return this.routes.filter((route) => !route.isVersioned); | |||
} | |||
return [...this.routes]; | |||
return this.routes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably unnecessary but this might remove a potential mutation guard we accedentaly had
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah man, I somehow missed this. That's a good point, will fix.
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Public APIs missing comments
Unknown metric groupsAPI count
History
|
Starting backport for target branches: 8.x https://github.com/elastic/kibana/actions/runs/11259199758 |
(cherry picked from commit 2327681)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
… (#195652) # Backport This will backport the following commits from `main` to `8.x`: - [[HTTP/OAS] Ability to exclude routes from introspection (#192675)](#192675) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jean-Louis Leysens","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-09T16:31:42Z","message":"[HTTP/OAS] Ability to exclude routes from introspection (#192675)","sha":"2327681de7306c20bcca69fe77660c0a586c979d","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","v9.0.0","Feature:OAS","v8.16.0","backport:version"],"title":"[HTTP/OAS] Ability to exclude routes from introspection","number":192675,"url":"https://github.com/elastic/kibana/pull/192675","mergeCommit":{"message":"[HTTP/OAS] Ability to exclude routes from introspection (#192675)","sha":"2327681de7306c20bcca69fe77660c0a586c979d"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192675","number":192675,"mergeCommit":{"message":"[HTTP/OAS] Ability to exclude routes from introspection (#192675)","sha":"2327681de7306c20bcca69fe77660c0a586c979d"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Jean-Louis Leysens <[email protected]>
## Summary Small follow up based on #192675 (comment)
## Summary Small follow up based on elastic#192675 (comment) (cherry picked from commit a481da6)
…195714) # Backport This will backport the following commits from `main` to `8.x`: - [[HTTP] Copy array returned by `getRoutes` (#195647)](#195647) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jean-Louis Leysens","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-10T08:53:59Z","message":"[HTTP] Copy array returned by `getRoutes` (#195647)\n\n## Summary\r\n\r\nSmall follow up based on\r\nhttps://github.com//pull/192675#discussion_r1793601519","sha":"a481da68e58cb20d6407c9866c1511717addfdb0","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:http","Team:Core","release_note:skip","v9.0.0","v8.16.0","backport:version"],"title":"[HTTP] Copy array returned by `getRoutes`","number":195647,"url":"https://github.com/elastic/kibana/pull/195647","mergeCommit":{"message":"[HTTP] Copy array returned by `getRoutes` (#195647)\n\n## Summary\r\n\r\nSmall follow up based on\r\nhttps://github.com//pull/192675#discussion_r1793601519","sha":"a481da68e58cb20d6407c9866c1511717addfdb0"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195647","number":195647,"mergeCommit":{"message":"[HTTP] Copy array returned by `getRoutes` (#195647)\n\n## Summary\r\n\r\nSmall follow up based on\r\nhttps://github.com//pull/192675#discussion_r1793601519","sha":"a481da68e58cb20d6407c9866c1511717addfdb0"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Jean-Louis Leysens <[email protected]>
…#195940) ## Summary Follow up on #195464 Adds public route registrar option `httpResource` to distinguish API routes from routes intended to be used for loading resources, [for ex](https://github.com/elastic/kibana/blob/bd22f1370fc55179ea6f2737176570176f700b6e/x-pack/plugins/security/server/routes/authentication/oidc.ts#L36). This enables us to avoid returning the version header `elastic-api-version` for HTTP resource routes. It's still possible for API authors to use the versioned router for things that should be HTTP resources, but it's assumed that all routes registered through HTTP resources services are: 1. Public 2. Not versioned (focus of this PR) 3. Not documented (done in #192675) ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <[email protected]>
…elastic#195940) ## Summary Follow up on elastic#195464 Adds public route registrar option `httpResource` to distinguish API routes from routes intended to be used for loading resources, [for ex](https://github.com/elastic/kibana/blob/bd22f1370fc55179ea6f2737176570176f700b6e/x-pack/plugins/security/server/routes/authentication/oidc.ts#L36). This enables us to avoid returning the version header `elastic-api-version` for HTTP resource routes. It's still possible for API authors to use the versioned router for things that should be HTTP resources, but it's assumed that all routes registered through HTTP resources services are: 1. Public 2. Not versioned (focus of this PR) 3. Not documented (done in elastic#192675) ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit 72f3d2d)
…header (#195940) (#196324) # Backport This will backport the following commits from `main` to `8.x`: - [[Http] Make HTTP resource routes respond without the versioned header (#195940)](#195940) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jean-Louis Leysens","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-15T14:09:42Z","message":"[Http] Make HTTP resource routes respond without the versioned header (#195940)\n\n## Summary\r\n\r\nFollow up on https://github.com/elastic/kibana/pull/195464\r\n\r\nAdds public route registrar option `httpResource` to distinguish API\r\nroutes from routes intended to be used for loading resources, [for\r\nex](https://github.com/elastic/kibana/blob/bd22f1370fc55179ea6f2737176570176f700b6e/x-pack/plugins/security/server/routes/authentication/oidc.ts#L36).\r\n\r\nThis enables us to avoid returning the version header\r\n`elastic-api-version` for HTTP resource routes.\r\n\r\nIt's still possible for API authors to use the versioned router for\r\nthings that should be HTTP resources, but it's assumed that all routes\r\nregistered through HTTP resources services are:\r\n\r\n1. Public\r\n2. Not versioned (focus of this PR)\r\n3. Not documented (done in\r\nhttps://github.com//pull/192675)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"72f3d2d3491f6da4b0c9147e766635e9dbb9cbe8","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:http","Team:Core","release_note:skip","v9.0.0","v8.16.0","backport:version"],"title":"[Http] Make HTTP resource routes respond without the versioned header","number":195940,"url":"https://github.com/elastic/kibana/pull/195940","mergeCommit":{"message":"[Http] Make HTTP resource routes respond without the versioned header (#195940)\n\n## Summary\r\n\r\nFollow up on https://github.com/elastic/kibana/pull/195464\r\n\r\nAdds public route registrar option `httpResource` to distinguish API\r\nroutes from routes intended to be used for loading resources, [for\r\nex](https://github.com/elastic/kibana/blob/bd22f1370fc55179ea6f2737176570176f700b6e/x-pack/plugins/security/server/routes/authentication/oidc.ts#L36).\r\n\r\nThis enables us to avoid returning the version header\r\n`elastic-api-version` for HTTP resource routes.\r\n\r\nIt's still possible for API authors to use the versioned router for\r\nthings that should be HTTP resources, but it's assumed that all routes\r\nregistered through HTTP resources services are:\r\n\r\n1. Public\r\n2. Not versioned (focus of this PR)\r\n3. Not documented (done in\r\nhttps://github.com//pull/192675)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"72f3d2d3491f6da4b0c9147e766635e9dbb9cbe8"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195940","number":195940,"mergeCommit":{"message":"[Http] Make HTTP resource routes respond without the versioned header (#195940)\n\n## Summary\r\n\r\nFollow up on https://github.com/elastic/kibana/pull/195464\r\n\r\nAdds public route registrar option `httpResource` to distinguish API\r\nroutes from routes intended to be used for loading resources, [for\r\nex](https://github.com/elastic/kibana/blob/bd22f1370fc55179ea6f2737176570176f700b6e/x-pack/plugins/security/server/routes/authentication/oidc.ts#L36).\r\n\r\nThis enables us to avoid returning the version header\r\n`elastic-api-version` for HTTP resource routes.\r\n\r\nIt's still possible for API authors to use the versioned router for\r\nthings that should be HTTP resources, but it's assumed that all routes\r\nregistered through HTTP resources services are:\r\n\r\n1. Public\r\n2. Not versioned (focus of this PR)\r\n3. Not documented (done in\r\nhttps://github.com//pull/192675)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"72f3d2d3491f6da4b0c9147e766635e9dbb9cbe8"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Jean-Louis Leysens <[email protected]>
Summary
Certain routes, like "system" routes should be excludable from introspection. Among these are also "HTTP resource" routes that are intended to server rendered HTML, CSS or JS.
To this end a new registration option was added:
excludeFromOAS: boolean
that will exclude routes from OAS documents created by Kibana.