Skip to content

OpenApi

39 exports Added in v1.0.0 Source

Annotations

annotations

Added in v1.0.0 Source

Signature

declare const annotations: (options: {
  readonly deprecated?: boolean;
  readonly description?: string;
  readonly exclude?: boolean;
  readonly externalDocs?: OpenAPISpecExternalDocs;
  readonly format?: string;
  readonly identifier?: string;
  readonly license?: OpenAPISpecLicense;
  readonly override?: Record<string, unknown>;
  readonly servers?: ReadonlyArray<OpenAPISpecServer>;
  readonly summary?: string;
  readonly title?: string;
  readonly transform?: (openApiSpec: Record<string, any>) => Record<string, any>;
  readonly version?: string;
}) => Context.Context<never>;

Deprecated

Added in v1.0.0 Source

Signature

declare class Deprecated extends any {
  constructor();
}

Description

Added in v1.0.0 Source

Signature

declare class Description extends any {
  constructor();
}

Exclude

Added in v1.0.0 Source

Signature

declare class Exclude extends any {
  constructor();
}

ExternalDocs

Added in v1.0.0 Source

Signature

declare class ExternalDocs extends any {
  constructor();
}

Format

Added in v1.0.0 Source

Signature

declare class Format extends any {
  constructor();
}

Identifier

Added in v1.0.0 Source

Signature

declare class Identifier extends any {
  constructor();
}

License

Added in v1.0.0 Source

Signature

declare class License extends any {
  constructor();
}

Override

Added in v1.0.0 Source

Signature

declare class Override extends any {
  constructor();
}

Servers

Added in v1.0.0 Source

Signature

declare class Servers extends any {
  constructor();
}

Summary

Added in v1.0.0 Source

Signature

declare class Summary extends any {
  constructor();
}

Title

Added in v1.0.0 Source

Signature

declare class Title extends any {
  constructor();
}

Transform

Added in v1.0.0 Source

Transforms the generated OpenAPI specification

Signature

declare class Transform extends any {
  constructor();
}

Version

Added in v1.0.0 Source

Signature

declare class Version extends any {
  constructor();
}

Constructors

fromApi

Added in v1.0.0 Source

Converts an HttpApi instance into an OpenAPI Specification object.

Details

This function takes an HttpApi instance, which defines a structured API, and generates an OpenAPI Specification (OpenAPISpec). The resulting spec adheres to the OpenAPI 3.1.0 standard and includes detailed metadata such as paths, operations, security schemes, and components. The function processes the API's annotations, middleware, groups, and endpoints to build a complete and accurate representation of the API in OpenAPI format.

The function also deduplicates schemas, applies transformations, and integrates annotations like descriptions, summaries, external documentation, and overrides. Cached results are used for better performance when the same HttpApi instance is processed multiple times.

Options

- additionalPropertiesStrategy: Controls the handling of additional properties. Possible values are: - "strict": Disallow additional properties (default behavior). - "allow": Allow additional properties.

Signature

declare function fromApi<Id extends string, Groups extends Any, E, R>(
  api: HttpApi<Id, Groups, E, R>,
  options?: {
    readonly additionalPropertiesStrategy?: AdditionalPropertiesStrategy;
  },
): OpenAPISpec;

Models

Signature

type AdditionalPropertiesStrategy = "allow" | "strict";

OpenAPIApiKeySecurityScheme interface

Added in v1.0.0 Source

Signature

interface OpenAPIApiKeySecurityScheme {
  description?: string;
  in: "header" | "query" | "cookie";
  name: string;
  readonly type: "apiKey";
}

OpenAPIComponents interface

Added in v1.0.0 Source

Signature

interface OpenAPIComponents {
  schemas: Record<string, JsonSchema.JsonSchema>;
  securitySchemes: Record<string, OpenAPISecurityScheme>;
}

OpenAPIHTTPSecurityScheme interface

Added in v1.0.0 Source

Signature

interface OpenAPIHTTPSecurityScheme {
  bearerFormat?: string;
  description?: string;
  scheme: string;
  readonly type: "http";
}

Signature

type OpenAPISecurityRequirement = Record<string, Array<string>>;

Signature

type OpenAPISecurityScheme = OpenAPIHTTPSecurityScheme | OpenAPIApiKeySecurityScheme;

OpenAPISpec interface

Added in v1.0.0 Source

This model describes the OpenAPI specification (version 3.1.0) returned by fromApi. It is not intended to describe the entire OpenAPI specification, only the output of fromApi.

Signature

interface OpenAPISpec {
  components: OpenAPIComponents;
  info: OpenAPISpecInfo;
  openapi: "3.1.0";
  paths: OpenAPISpecPaths;
  security: Array<OpenAPISecurityRequirement>;
  servers?: Array<OpenAPISpecServer>;
  tags: Array<OpenAPISpecTag>;
}

OpenApiSpecContent type

Added in v1.0.0 Source

Signature

type OpenApiSpecContent = { [K in OpenApiSpecContentType]: OpenApiSpecMediaType };

Signature

type OpenApiSpecContentType =
  | "application/json"
  | "application/xml"
  | "application/x-www-form-urlencoded"
  | "multipart/form-data"
  | "text/plain";

OpenAPISpecExternalDocs interface

Added in v1.0.0 Source

Signature

interface OpenAPISpecExternalDocs {
  description?: string;
  url: string;
}

OpenAPISpecInfo interface

Added in v1.0.0 Source

Signature

interface OpenAPISpecInfo {
  description?: string;
  license?: OpenAPISpecLicense;
  summary?: string;
  title: string;
  version: string;
}

OpenAPISpecLicense interface

Added in v1.0.0 Source

Signature

interface OpenAPISpecLicense {
  name: string;
  url?: string;
}

OpenApiSpecMediaType interface

Added in v1.0.0 Source

Signature

interface OpenApiSpecMediaType {
  schema: JsonSchema;
}

Signature

type OpenAPISpecMethodName =
  | "get"
  | "put"
  | "post"
  | "delete"
  | "options"
  | "head"
  | "patch"
  | "trace";

OpenAPISpecOperation interface

Added in v1.0.0 Source

Signature

interface OpenAPISpecOperation {
  deprecated?: boolean;
  description?: string;
  externalDocs?: OpenAPISpecExternalDocs;
  operationId: string;
  parameters: Array<OpenAPISpecParameter>;
  requestBody?: OpenAPISpecRequestBody;
  responses: OpenAPISpecResponses;
  security: Array<OpenAPISecurityRequirement>;
  summary?: string;
  tags: [string, ...Array<string>];
}

OpenAPISpecParameter interface

Added in v1.0.0 Source

Signature

interface OpenAPISpecParameter {
  description?: string;
  in: "header" | "query" | "cookie" | "path";
  name: string;
  required: boolean;
  schema: JsonSchema;
}

OpenAPISpecPathItem type

Added in v1.0.0 Source

Signature

type OpenAPISpecPathItem = { [K in OpenAPISpecMethodName]: OpenAPISpecOperation };

OpenAPISpecPaths type

Added in v1.0.0 Source

Signature

type OpenAPISpecPaths = Record<string, OpenAPISpecPathItem>;

OpenAPISpecRequestBody interface

Added in v1.0.0 Source

Signature

interface OpenAPISpecRequestBody {
  content: OpenApiSpecContent;
  required: true;
}

OpenApiSpecResponse interface

Added in v1.0.0 Source

Signature

interface OpenApiSpecResponse {
  content?: OpenApiSpecContent;
  description: string;
}

OpenAPISpecResponses type

Added in v1.0.0 Source

Signature

type OpenAPISpecResponses = Record<number, OpenApiSpecResponse>;

OpenAPISpecServer interface

Added in v1.0.0 Source

Signature

interface OpenAPISpecServer {
  description?: string;
  url: string;
  variables?: Record<string, OpenAPISpecServerVariable>;
}

OpenAPISpecServerVariable interface

Added in v1.0.0 Source

Signature

interface OpenAPISpecServerVariable {
  default: string;
  description?: string;
  enum?: [string, ...Array<string>];
}

OpenAPISpecTag interface

Added in v1.0.0 Source

Signature

interface OpenAPISpecTag {
  description?: string;
  externalDocs?: OpenAPISpecExternalDocs;
  name: string;
}