Skip to content

Commit

Permalink
refactor names of some versioning specific types
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Mar 28, 2023
1 parent 9ae403e commit abb110d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/core/http/core-http-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ export type {

export type {
AddVersionOpts,
RequestValidation,
ResponseValidation,
Version,
VersionedRouteRequestValidation,
VersionedRouteResponseValidation,
ApiVersion,
VersionedRoute,
VersionedRouteConfig,
VersionedRouteRegistrar,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/http/core-http-server/src/versioning/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*/

export type {
Version,
ApiVersion,
AddVersionOpts,
RequestValidation,
ResponseValidation,
VersionedRouteRequestValidation,
VersionedRouteResponseValidation,
VersionedRoute,
VersionedRouteConfig,
VersionedRouteRegistrar,
Expand Down
12 changes: 6 additions & 6 deletions packages/core/http/core-http-server/src/versioning/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type RqCtx = RequestHandlerContextBase;
* Assuming that version will be a monotonically increasing number where: version > 0.
* @experimental
*/
export type Version = `${number}`;
export type ApiVersion = `${number}`;

/**
* Configuration for a versioned route
Expand Down Expand Up @@ -156,10 +156,10 @@ export interface VersionedRouter<Ctx extends RqCtx = RqCtx> {
}

/** @experimental */
export type RequestValidation<P, Q, B> = RouteValidatorFullConfig<P, Q, B>;
export type VersionedRouteRequestValidation<P, Q, B> = RouteValidatorFullConfig<P, Q, B>;

/** @experimental */
export interface ResponseValidation<R> {
export interface VersionedRouteResponseValidation<R> {
[statusCode: number]: { body: RouteValidationFunction<R> | Type<R> };
unsafe?: { body?: boolean };
}
Expand All @@ -173,14 +173,14 @@ interface FullValidationConfig<P, Q, B, R> {
* Validation to run against route inputs: params, query and body
* @experimental
*/
request?: RequestValidation<P, Q, B>;
request?: VersionedRouteRequestValidation<P, Q, B>;
/**
* Validation to run against route output
* @note This validation is only intended to run in development. Do not use this
* for setting default values!
* @experimental
*/
response?: ResponseValidation<R>;
response?: VersionedRouteResponseValidation<R>;
}

/**
Expand All @@ -193,7 +193,7 @@ export interface AddVersionOpts<P, Q, B, R> {
* Version to assign to this route
* @experimental
*/
version: Version;
version: ApiVersion;
/**
* Validation for this version of a route
* @experimental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
KibanaResponseFactory,
} from '@kbn/core-http-server';
import type {
Version,
ApiVersion,
AddVersionOpts,
VersionedRoute,
VersionedRouteConfig,
Expand All @@ -36,7 +36,7 @@ const passThroughValidation = { body: schema.any(), params: schema.any(), query:

export class CoreVersionedRoute implements VersionedRoute {
private readonly handlers = new Map<
Version,
ApiVersion,
{
fn: RequestHandler;
options: Options;
Expand Down Expand Up @@ -85,7 +85,7 @@ export class CoreVersionedRoute implements VersionedRoute {
req: KibanaRequest,
res: KibanaResponseFactory
) => {
const version = req.headers[VERSION_HEADER] as undefined | Version;
const version = req.headers[VERSION_HEADER] as undefined | ApiVersion;
if (!version) {
return res.custom({
statusCode: 406,
Expand Down

0 comments on commit abb110d

Please sign in to comment.