Skip to content

Commit

Permalink
[OAS] Remove Elastic-Api-Version (elastic#202923)
Browse files Browse the repository at this point in the history
## Summary

Due to the much slower rate of versioning public APIs we have decided to
remove the Elastic-Api-Version body and header information from the spec
entirely.

This also cleans up the spec when rendered on our hosted OAS docs.

Removes:
1. `Elastic-Api-Version` from the request/response bodies for all public
APIs
2. `Elastic-Api-Version` header parameter from all public APIs

Docs for internal APIs will still have this included as they always
require a version environments.

## To revewers

Important changes are all in `packages/kbn-router-to-openapispec` and
`src/core/server/integration_tests/http/oas.test.ts`, the rest is very
minor or generated/snapshotted changes.

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
2 people authored and Samiul-TheSoccerFan committed Dec 10, 2024
1 parent c106f2c commit 06f16a7
Show file tree
Hide file tree
Showing 21 changed files with 994 additions and 6,614 deletions.
2,313 changes: 299 additions & 2,014 deletions oas_docs/bundle.json

Large diffs are not rendered by default.

2,243 changes: 294 additions & 1,949 deletions oas_docs/bundle.serverless.json

Large diffs are not rendered by default.

1,236 changes: 70 additions & 1,166 deletions oas_docs/output/kibana.serverless.yaml

Large diffs are not rendered by default.

1,158 changes: 11 additions & 1,147 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 @@ -339,7 +339,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 @@ -362,7 +362,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 06f16a7

Please sign in to comment.