Skip to content

Commit

Permalink
[8.x] [OAS] Remove Elastic-Api-Version (#202923) (#203223)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[OAS] Remove `Elastic-Api-Version`
(#202923)](#202923)

<!--- Backport version: 8.9.8 -->

### 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-12-05T16:05:42Z","message":"[OAS]
Remove `Elastic-Api-Version` (#202923)\n\n## Summary\r\n\r\nDue to the
much slower rate of versioning public APIs we have decided to\r\nremove
the Elastic-Api-Version body and header information from the
spec\r\nentirely.\r\n\r\nThis also cleans up the spec when rendered on
our hosted OAS docs.\r\n\r\nRemoves:\r\n1. `Elastic-Api-Version` from
the request/response bodies for all public\r\nAPIs\r\n2.
`Elastic-Api-Version` header parameter from all public APIs\r\n\r\nDocs
for internal APIs will still have this included as they
always\r\nrequire a version environments.\r\n\r\n## To
revewers\r\n\r\nImportant changes are all in
`packages/kbn-router-to-openapispec`
and\r\n`src/core/server/integration_tests/http/oas.test.ts`, the rest is
very\r\nminor or generated/snapshotted
changes.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"53b0015340ab69768363b096647bbf14e33936ef","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","v9.0.0","Feature:OAS","backport:version","v8.18.0"],"number":202923,"url":"https://github.com/elastic/kibana/pull/202923","mergeCommit":{"message":"[OAS]
Remove `Elastic-Api-Version` (#202923)\n\n## Summary\r\n\r\nDue to the
much slower rate of versioning public APIs we have decided to\r\nremove
the Elastic-Api-Version body and header information from the
spec\r\nentirely.\r\n\r\nThis also cleans up the spec when rendered on
our hosted OAS docs.\r\n\r\nRemoves:\r\n1. `Elastic-Api-Version` from
the request/response bodies for all public\r\nAPIs\r\n2.
`Elastic-Api-Version` header parameter from all public APIs\r\n\r\nDocs
for internal APIs will still have this included as they
always\r\nrequire a version environments.\r\n\r\n## To
revewers\r\n\r\nImportant changes are all in
`packages/kbn-router-to-openapispec`
and\r\n`src/core/server/integration_tests/http/oas.test.ts`, the rest is
very\r\nminor or generated/snapshotted
changes.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"53b0015340ab69768363b096647bbf14e33936ef"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202923","number":202923,"mergeCommit":{"message":"[OAS]
Remove `Elastic-Api-Version` (#202923)\n\n## Summary\r\n\r\nDue to the
much slower rate of versioning public APIs we have decided to\r\nremove
the Elastic-Api-Version body and header information from the
spec\r\nentirely.\r\n\r\nThis also cleans up the spec when rendered on
our hosted OAS docs.\r\n\r\nRemoves:\r\n1. `Elastic-Api-Version` from
the request/response bodies for all public\r\nAPIs\r\n2.
`Elastic-Api-Version` header parameter from all public APIs\r\n\r\nDocs
for internal APIs will still have this included as they
always\r\nrequire a version environments.\r\n\r\n## To
revewers\r\n\r\nImportant changes are all in
`packages/kbn-router-to-openapispec`
and\r\n`src/core/server/integration_tests/http/oas.test.ts`, the rest is
very\r\nminor or generated/snapshotted
changes.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"53b0015340ab69768363b096647bbf14e33936ef"}},{"branch":"8.x","label":"v8.18.0","labelRegex":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
jloleysens and kibanamachine authored Dec 9, 2024
1 parent cfae193 commit a6884f8
Show file tree
Hide file tree
Showing 19 changed files with 358 additions and 1,219 deletions.
577 changes: 35 additions & 542 deletions oas_docs/bundle.json

Large diffs are not rendered by default.

342 changes: 3 additions & 339 deletions oas_docs/output/kibana.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export { filterHeaders } from './src/headers';
export {
versionHandlerResolvers,
CoreVersionedRouter,
ALLOWED_PUBLIC_VERSION,
BASE_PUBLIC_VERSION,
unwrapVersionedResponseBodyValidation,
type HandlerResolutionStrategy,
} from './src/versioned_router';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { validBodyOutput, getRequestValidation } from '@kbn/core-http-server';
import type { RouteSecurityGetter } from '@kbn/core-http-server';
import type { DeepPartial } from '@kbn/utility-types';
import { RouteValidator } from './validator';
import { ALLOWED_PUBLIC_VERSION, CoreVersionedRouter } from './versioned_router';
import { BASE_PUBLIC_VERSION, CoreVersionedRouter } from './versioned_router';
import { CoreKibanaRequest } from './request';
import { kibanaResponseFactory } from './response';
import { HapiResponseAdapter } from './response_adapter';
Expand Down Expand Up @@ -344,7 +344,7 @@ export class Router<Context extends RequestHandlerContextBase = RequestHandlerCo
if (isPublicUnversionedRoute) {
response.output.headers = {
...response.output.headers,
...getVersionHeader(ALLOWED_PUBLIC_VERSION),
...getVersionHeader(BASE_PUBLIC_VERSION),
};
}

Expand All @@ -367,7 +367,7 @@ export class Router<Context extends RequestHandlerContextBase = RequestHandlerCo
try {
const kibanaResponse = await handler(kibanaRequest, kibanaResponseFactory);
if (isPublicUnversionedRoute) {
injectVersionHeader(ALLOWED_PUBLIC_VERSION, kibanaResponse);
injectVersionHeader(BASE_PUBLIC_VERSION, kibanaResponse);
}
if (kibanaRequest.protocol === 'http2' && kibanaResponse.options.headers) {
kibanaResponse.options.headers = stripIllegalHttp2Headers({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
export { resolvers as versionHandlerResolvers } from './handler_resolvers';
export { CoreVersionedRouter } from './core_versioned_router';
export type { HandlerResolutionStrategy } from './types';
export { ALLOWED_PUBLIC_VERSION } from './route_version_utils';
export { BASE_PUBLIC_VERSION } from './route_version_utils';
export { unwrapVersionedResponseBodyValidation } from './util';
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const INTERNAL_VERSION_REGEX = /^[1-9][0-9]*$/;
* release date we only allow one public version temporarily.
* @internal
*/
export const ALLOWED_PUBLIC_VERSION = '2023-10-31';
export const BASE_PUBLIC_VERSION = '2023-10-31';

export function isAllowedPublicVersion(version: string): undefined | string {
if (ALLOWED_PUBLIC_VERSION !== version) {
return `Invalid public version, for now please use "${ALLOWED_PUBLIC_VERSION}" as the version for all public routes. Received "${version}".}"`;
if (BASE_PUBLIC_VERSION !== version) {
return `Invalid public version, for now please use "${BASE_PUBLIC_VERSION}" as the version for all public routes. Received "${version}".}"`;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,13 @@ export class HttpService
schema.arrayOf(schema.string()),
]);
const querySchema = schema.object({
access: schema.maybe(schema.oneOf([schema.literal('public'), schema.literal('internal')])),
access: schema.oneOf([schema.literal('public'), schema.literal('internal')], {
defaultValue: 'public' as const,
}),
version: schema.maybe(schema.string()),
excludePathsMatching: schema.maybe(stringOrStringArraySchema),
pathStartsWith: schema.maybe(stringOrStringArraySchema),
pluginId: schema.maybe(schema.string()),
version: schema.maybe(schema.string()),
});

server.route({
Expand Down
Loading

0 comments on commit a6884f8

Please sign in to comment.