Skip to content

Files

Latest commit

021cfbb · May 3, 2023

History

History
633 lines (566 loc) · 15.9 KB

api-report.md

File metadata and controls

633 lines (566 loc) · 15.9 KB

API Report File for "@backstage/backend-openapi-utils"

Do not edit this file. It is a report generated by API Extractor.

import type { ContentObject } from 'openapi3-ts';
import type core from 'express-serve-static-core';
import { FromSchema } from 'json-schema-to-ts';
import { JSONSchema7 } from 'json-schema-to-ts';
import type { OpenAPIObject } from 'openapi3-ts';
import type { ParameterObject } from 'openapi3-ts';
import type { ReferenceObject } from 'openapi3-ts';
import type { RequestBodyObject } from 'openapi3-ts';
import type { ResponseObject } from 'openapi3-ts';
import { Router } from 'express';
import type { SchemaObject } from 'openapi3-ts';

// @public
export interface ApiRouter<Doc extends RequiredDoc> extends Router {
  // (undocumented)
  all: DocRequestMatcher<Doc, this, 'all'>;
  // (undocumented)
  delete: DocRequestMatcher<Doc, this, 'delete'>;
  // (undocumented)
  get: DocRequestMatcher<Doc, this, 'get'>;
  // (undocumented)
  head: DocRequestMatcher<Doc, this, 'head'>;
  // (undocumented)
  options: DocRequestMatcher<Doc, this, 'options'>;
  // (undocumented)
  patch: DocRequestMatcher<Doc, this, 'patch'>;
  // (undocumented)
  post: DocRequestMatcher<Doc, this, 'post'>;
  // (undocumented)
  put: DocRequestMatcher<Doc, this, 'put'>;
}

// @public (undocumented)
type ComponentRef<
  Doc extends RequiredDoc,
  Type extends ComponentTypes<Doc>,
  Ref extends ImmutableReferenceObject,
> = Ref extends {
  $ref: `#/components/${Type}/${infer Name}`;
}
  ? Name extends keyof Doc['components'][Type]
    ? Doc['components'][Type][Name] extends ImmutableReferenceObject
      ? ComponentRef<Doc, Type, Doc['components'][Type][Name]>
      : Doc['components'][Type][Name]
    : never
  : never;

// @public (undocumented)
type ComponentTypes<Doc extends RequiredDoc> = Extract<
  keyof Doc['components'],
  string
>;

// @public (undocumented)
type ConvertAll<T, R extends ReadonlyArray<unknown> = []> = T extends [
  infer First extends JSONSchema7,
  ...infer Rest,
]
  ? ConvertAll<Rest, [...R, FromSchema<First>]>
  : R;

// @public (undocumented)
interface CookieObject extends ParameterObject {
  // (undocumented)
  in: 'cookie';
  // (undocumented)
  style?: 'form';
}

// @public (undocumented)
type CookieSchema<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathMethod<Doc, Path>,
> = ParametersSchema<Doc, DocPath<Doc, Path>, Method, ImmutableCookieObject>;

// @public (undocumented)
type DiscriminateUnion<T, K extends keyof T, V extends T[K]> = Extract<
  T,
  Record<K, V>
>;

// @public (undocumented)
type DocOperation<
  Doc extends RequiredDoc,
  Path extends keyof Doc['paths'],
  Method extends keyof Doc['paths'][Path],
> = Doc['paths'][Path][Method];

// @public (undocumented)
type DocParameter<
  Doc extends RequiredDoc,
  Path extends Extract<keyof Doc['paths'], string>,
  Method extends keyof Doc['paths'][Path],
  Parameter extends keyof Doc['paths'][Path][Method]['parameters'],
> = DocOperation<
  Doc,
  Path,
  Method
>['parameters'][Parameter] extends ImmutableReferenceObject
  ? 'parameters' extends ComponentTypes<Doc>
    ? ComponentRef<
        Doc,
        'parameters',
        DocOperation<Doc, Path, Method>['parameters'][Parameter]
      >
    : never
  : DocOperation<Doc, Path, Method>['parameters'][Parameter];

// @public (undocumented)
type DocParameters<
  Doc extends RequiredDoc,
  Path extends Extract<keyof Doc['paths'], string>,
  Method extends keyof Doc['paths'][Path],
> = DocOperation<Doc, Path, Method>['parameters'] extends ReadonlyArray<any>
  ? {
      [Index in keyof DocOperation<
        Doc,
        Path,
        Method
      >['parameters']]: DocParameter<Doc, Path, Method, Index>;
    }
  : never;

// @public
type DocPath<
  Doc extends PathDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
> = ValueOf<{
  [Template in Extract<
    keyof Doc['paths'],
    string
  >]: Path extends PathTemplate<Template> ? Template : never;
}>;

// @public (undocumented)
type DocPathMethod<
  Doc extends Pick<RequiredDoc, 'paths'>,
  Path extends DocPathTemplate<Doc>,
> = keyof Doc['paths'][DocPath<Doc, Path>];

// @public (undocumented)
type DocPathTemplate<Doc extends PathDoc> = PathTemplate<
  Extract<keyof Doc['paths'], string>
>;

// @public
type DocRequestHandler<
  Doc extends RequiredDoc,
  Path extends DocPathTemplate<Doc>,
  Method extends keyof Doc['paths'][Path],
> = core.RequestHandler<
  PathSchema<Doc, Path, Method>,
  ResponseBodyToJsonSchema<Doc, Path, Method>,
  RequestBodyToJsonSchema<Doc, Path, Method>,
  QuerySchema<Doc, Path, Method>,
  Record<string, string>
>;

// @public
type DocRequestHandlerParams<
  Doc extends RequiredDoc,
  Path extends DocPathTemplate<Doc>,
  Method extends keyof Doc['paths'][Path],
> = core.RequestHandlerParams<
  PathSchema<Doc, Path, Method>,
  ResponseBodyToJsonSchema<Doc, Path, Method>,
  RequestBodyToJsonSchema<Doc, Path, Method>,
  QuerySchema<Doc, Path, Method>,
  Record<string, string>
>;

// @public
interface DocRequestMatcher<
  Doc extends RequiredDoc,
  T,
  Method extends
    | 'all'
    | 'get'
    | 'post'
    | 'put'
    | 'delete'
    | 'patch'
    | 'options'
    | 'head',
> {
  // (undocumented)
  <Path extends MethodAwareDocPath<Doc, DocPathTemplate<Doc>, Method>>(
    path: Path,
    ...handlers: Array<DocRequestHandler<Doc, Path, Method>>
  ): T;
  // (undocumented)
  <Path extends MethodAwareDocPath<Doc, DocPathTemplate<Doc>, Method>>(
    path: Path,
    ...handlers: Array<DocRequestHandlerParams<Doc, Path, Method>>
  ): T;
}

// @public (undocumented)
type Filter<T, U> = T extends U ? T : never;

// @public (undocumented)
type FullMap<
  T extends {
    [key: string]: any;
  },
> = RequiredMap<T> & OptionalMap<T>;

// @public (undocumented)
interface HeaderObject extends ParameterObject {
  // (undocumented)
  in: 'header';
  // (undocumented)
  style: 'simple';
}

// @public (undocumented)
type HeaderSchema<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathMethod<Doc, Path>,
> = ParametersSchema<Doc, DocPath<Doc, Path>, Method, ImmutableHeaderObject>;

// @public
type Immutable<T> = T extends
  | Function
  | boolean
  | number
  | string
  | null
  | undefined
  ? T
  : T extends Map<infer K, infer V>
  ? ReadonlyMap<Immutable<K>, Immutable<V>>
  : T extends Set<infer S>
  ? ReadonlySet<Immutable<S>>
  : {
      readonly [P in keyof T]: Immutable<T[P]>;
    };

// @public (undocumented)
type ImmutableContentObject = ImmutableObject<ContentObject>;

// @public (undocumented)
type ImmutableCookieObject = ImmutableObject<CookieObject>;

// @public (undocumented)
type ImmutableHeaderObject = ImmutableObject<HeaderObject>;

// @public (undocumented)
type ImmutableObject<T> = {
  readonly [K in keyof T]: Immutable<T[K]>;
};

// @public (undocumented)
type ImmutableOpenAPIObject = ImmutableObject<OpenAPIObject>;

// @public (undocumented)
type ImmutableParameterObject = ImmutableObject<ParameterObject>;

// @public (undocumented)
type ImmutablePathObject = ImmutableObject<PathObject>;

// @public (undocumented)
type ImmutableQueryObject = ImmutableObject<QueryObject>;

// @public (undocumented)
type ImmutableReferenceObject = ImmutableObject<ReferenceObject>;

// @public (undocumented)
type ImmutableRequestBodyObject = ImmutableObject<RequestBodyObject>;

// @public (undocumented)
type ImmutableResponseObject = ImmutableObject<ResponseObject>;

// @public (undocumented)
type ImmutableSchemaObject = ImmutableObject<SchemaObject>;

declare namespace internal {
  export {
    RequiredDoc,
    PathDoc,
    ValueOf,
    PathTemplate,
    DocPath,
    DocPathTemplate,
    DocPathMethod,
    MethodAwareDocPath,
    DocOperation,
    ComponentTypes,
    ComponentRef,
    SchemaRef,
    ObjectWithContentSchema,
    UnionToIntersection,
    LastOf,
    Push,
    TuplifyUnion,
    ConvertAll,
    UnknownIfNever,
    ToTypeSafe,
    DiscriminateUnion,
    MapDiscriminatedUnion,
    PickOptionalKeys,
    PickRequiredKeys,
    OptionalMap,
    RequiredMap,
    FullMap,
    Filter,
    DocRequestHandler,
    DocRequestHandlerParams,
    DocRequestMatcher,
    Immutable,
    ImmutableObject,
    ImmutableReferenceObject,
    ImmutableOpenAPIObject,
    ImmutableContentObject,
    ImmutableRequestBodyObject,
    ImmutableResponseObject,
    ImmutableParameterObject,
    HeaderObject,
    ImmutableHeaderObject,
    CookieObject,
    ImmutableCookieObject,
    QueryObject,
    ImmutableQueryObject,
    PathObject,
    ImmutablePathObject,
    ImmutableSchemaObject,
    DocParameter,
    DocParameters,
    ParameterSchema,
    MapToSchema,
    ParametersSchema,
    HeaderSchema,
    CookieSchema,
    PathSchema,
    QuerySchema,
    RequestBody,
    RequestBodySchema,
    RequestBodyToJsonSchema,
    Response_2 as Response,
    ResponseSchemas,
    ResponseBodyToJsonSchema,
  };
}
export { internal };

// @public (undocumented)
type LastOf<T> = UnionToIntersection<
  T extends any ? () => T : never
> extends () => infer R
  ? R
  : never;

// @public (undocumented)
type MapDiscriminatedUnion<T extends Record<K, string>, K extends keyof T> = {
  [V in T[K]]: DiscriminateUnion<T, K, V>;
};

// @public (undocumented)
type MapToSchema<
  Doc extends RequiredDoc,
  T extends Record<string, ImmutableParameterObject>,
> = {
  [V in keyof T]: NonNullable<T[V]> extends ImmutableParameterObject
    ? ParameterSchema<Doc, NonNullable<T[V]>['schema']>
    : never;
};

// @public (undocumented)
type MethodAwareDocPath<
  Doc extends PathDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends keyof Doc['paths'][Path],
> = ValueOf<{
  [Template in Extract<
    keyof Doc['paths'],
    string
  >]: Path extends PathTemplate<Template>
    ? Method extends DocPathMethod<Doc, Path>
      ? PathTemplate<Template>
      : never
    : never;
}>;

// @public (undocumented)
type ObjectWithContentSchema<
  Doc extends RequiredDoc,
  Object extends {
    content?: ImmutableContentObject;
  },
> = Object['content'] extends ImmutableContentObject
  ? SchemaRef<Doc, Object['content']['application/json']['schema']>
  : never;

// @public (undocumented)
type OptionalMap<
  T extends {
    [key: string]: any;
  },
> = {
  [P in Exclude<PickOptionalKeys<T>, undefined>]?: NonNullable<T[P]>;
};

// @public (undocumented)
type ParameterSchema<
  Doc extends RequiredDoc,
  Schema extends ImmutableParameterObject['schema'],
> = SchemaRef<Doc, Schema> extends infer R
  ? R extends ImmutableSchemaObject
    ? R extends JSONSchema7
      ? FromSchema<R>
      : never
    : never
  : never;

// @public (undocumented)
type ParametersSchema<
  Doc extends RequiredDoc,
  Path extends Extract<keyof Doc['paths'], string>,
  Method extends keyof Doc['paths'][Path],
  FilterType extends ImmutableParameterObject,
> = number extends keyof DocParameters<Doc, Path, Method>
  ? MapToSchema<
      Doc,
      FullMap<
        MapDiscriminatedUnion<
          Filter<DocParameters<Doc, Path, Method>[number], FilterType>,
          'name'
        >
      >
    >
  : never;

// @public (undocumented)
type PathDoc = Pick<ImmutableOpenAPIObject, 'paths'>;

// @public (undocumented)
interface PathObject extends ParameterObject {
  // (undocumented)
  in: 'path';
  // (undocumented)
  style?: 'simple' | 'label' | 'matrix';
}

// @public (undocumented)
type PathSchema<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathMethod<Doc, Path>,
> = ParametersSchema<Doc, DocPath<Doc, Path>, Method, ImmutablePathObject>;

// @public
type PathTemplate<Path extends string> =
  Path extends `${infer Prefix}{${infer PathName}}${infer Suffix}`
    ? `${Prefix}:${PathName}${PathTemplate<Suffix>}`
    : Path;

// @public (undocumented)
type PickOptionalKeys<
  T extends {
    [key: string]: any;
  },
> = {
  [K in keyof T]: true extends T[K]['required'] ? never : K;
}[keyof T];

// @public (undocumented)
type PickRequiredKeys<
  T extends {
    [key: string]: any;
  },
> = {
  [K in keyof T]: true extends T[K]['required'] ? K : never;
}[keyof T];

// @public (undocumented)
type Push<T extends any[], V> = [...T, V];

// @public (undocumented)
interface QueryObject extends ParameterObject {
  // (undocumented)
  in: 'query';
  // (undocumented)
  style?: 'form' | 'deepObject' | 'pipeDelimited' | 'spaceDelimited';
}

// @public (undocumented)
type QuerySchema<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathMethod<Doc, Path>,
> = ParametersSchema<Doc, DocPath<Doc, Path>, Method, ImmutableQueryObject>;

// @public (undocumented)
type RequestBody<
  Doc extends RequiredDoc,
  Path extends Extract<keyof Doc['paths'], string>,
  Method extends keyof Doc['paths'][Path],
> = DocOperation<
  Doc,
  Path,
  Method
>['requestBody'] extends ImmutableReferenceObject
  ? 'requestBodies' extends ComponentTypes<Doc>
    ? ComponentRef<
        Doc,
        'requestBodies',
        DocOperation<Doc, Path, Method>['requestBody']
      >
    : never
  : DocOperation<Doc, Path, Method>['requestBody'];

// @public (undocumented)
type RequestBodySchema<
  Doc extends RequiredDoc,
  Path extends DocPathTemplate<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = RequestBody<
  Doc,
  DocPath<Doc, Path>,
  Method
> extends ImmutableRequestBodyObject
  ? ObjectWithContentSchema<Doc, RequestBody<Doc, DocPath<Doc, Path>, Method>>
  : never;

// @public
type RequestBodyToJsonSchema<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathMethod<Doc, Path>,
> = ToTypeSafe<RequestBodySchema<Doc, Path, Method>>;

// @public
type RequiredDoc = Pick<ImmutableOpenAPIObject, 'paths' | 'components'>;

// @public (undocumented)
type RequiredMap<
  T extends {
    [key: string]: any;
  },
> = {
  [P in Exclude<PickRequiredKeys<T>, undefined>]: NonNullable<T[P]>;
};

// @public (undocumented)
type Response_2<
  Doc extends RequiredDoc,
  Path extends keyof Doc['paths'],
  Method extends keyof Doc['paths'][Path],
  StatusCode extends keyof DocOperation<Doc, Path, Method>['responses'],
> = DocOperation<
  Doc,
  Path,
  Method
>['responses'][StatusCode] extends ImmutableReferenceObject
  ? 'responses' extends ComponentTypes<Doc>
    ? ComponentRef<
        Doc,
        'responses',
        DocOperation<Doc, Path, Method>['responses'][StatusCode]
      >
    : never
  : DocOperation<Doc, Path, Method>['responses'][StatusCode];

// @public
type ResponseBodyToJsonSchema<
  Doc extends RequiredDoc,
  Path extends PathTemplate<Extract<keyof Doc['paths'], string>>,
  Method extends DocPathMethod<Doc, Path>,
> = ToTypeSafe<ValueOf<ResponseSchemas<Doc, Path, Method>>>;

// @public (undocumented)
type ResponseSchemas<
  Doc extends RequiredDoc,
  Path extends DocPathTemplate<Doc>,
  Method extends DocPathMethod<Doc, Path>,
> = {
  [StatusCode in keyof DocOperation<
    Doc,
    Path,
    Method
  >['responses']]: Response_2<
    Doc,
    Path,
    Method,
    StatusCode
  > extends ImmutableResponseObject
    ? ObjectWithContentSchema<Doc, Response_2<Doc, Path, Method, StatusCode>>
    : never;
};

// @public (undocumented)
type SchemaRef<Doc extends RequiredDoc, Schema> = Schema extends {
  $ref: `#/components/schemas/${infer Name}`;
}
  ? 'schemas' extends keyof Doc['components']
    ? Name extends keyof Doc['components']['schemas']
      ? SchemaRef<Doc, Doc['components']['schemas'][Name]>
      : never
    : never
  : {
      [Key in keyof Schema]: SchemaRef<Doc, Schema[Key]>;
    };

// @public (undocumented)
type ToTypeSafe<T> = UnknownIfNever<ConvertAll<TuplifyUnion<T>>[number]>;

// @public (undocumented)
type TuplifyUnion<
  T,
  L = LastOf<T>,
  N = [T] extends [never] ? true : false,
> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>;

// @public
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
  k: infer I,
) => void
  ? I
  : never;

// @public (undocumented)
type UnknownIfNever<P> = [P] extends [never] ? unknown : P;

// @public
type ValueOf<T> = T[keyof T];