OpenApi
Annotations
annotations
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
Signature
declare class Deprecated extends any {
constructor();
}Description
Signature
declare class Description extends any {
constructor();
}Signature
declare class Exclude extends any {
constructor();
}ExternalDocs
Signature
declare class ExternalDocs extends any {
constructor();
}Signature
declare class Format extends any {
constructor();
}Identifier
Signature
declare class Identifier extends any {
constructor();
}Signature
declare class License extends any {
constructor();
}Signature
declare class Override extends any {
constructor();
}Signature
declare class Servers extends any {
constructor();
}Signature
declare class Summary extends any {
constructor();
}Signature
declare class Title extends any {
constructor();
}Signature
declare class Transform extends any {
constructor();
}Signature
declare class Version extends any {
constructor();
}Constructors
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
AdditionalPropertiesStrategy type
Signature
type AdditionalPropertiesStrategy = "allow" | "strict";OpenAPIApiKeySecurityScheme interface
Signature
interface OpenAPIApiKeySecurityScheme {
description?: string;
in: "header" | "query" | "cookie";
name: string;
readonly type: "apiKey";
}OpenAPIComponents interface
Signature
interface OpenAPIComponents {
schemas: Record<string, JsonSchema.JsonSchema>;
securitySchemes: Record<string, OpenAPISecurityScheme>;
}OpenAPIHTTPSecurityScheme interface
Signature
interface OpenAPIHTTPSecurityScheme {
bearerFormat?: string;
description?: string;
scheme: string;
readonly type: "http";
}OpenAPISecurityRequirement type
Signature
type OpenAPISecurityRequirement = Record<string, Array<string>>;OpenAPISecurityScheme type
Signature
type OpenAPISecurityScheme = OpenAPIHTTPSecurityScheme | OpenAPIApiKeySecurityScheme;OpenAPISpec interface
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
Signature
type OpenApiSpecContent = { [K in OpenApiSpecContentType]: OpenApiSpecMediaType };OpenApiSpecContentType type
Signature
type OpenApiSpecContentType =
| "application/json"
| "application/xml"
| "application/x-www-form-urlencoded"
| "multipart/form-data"
| "text/plain";OpenAPISpecExternalDocs interface
Signature
interface OpenAPISpecExternalDocs {
description?: string;
url: string;
}OpenAPISpecInfo interface
Signature
interface OpenAPISpecInfo {
description?: string;
license?: OpenAPISpecLicense;
summary?: string;
title: string;
version: string;
}OpenAPISpecLicense interface
Signature
interface OpenAPISpecLicense {
name: string;
url?: string;
}OpenApiSpecMediaType interface
Signature
interface OpenApiSpecMediaType {
schema: JsonSchema;
}OpenAPISpecMethodName type
Signature
type OpenAPISpecMethodName =
| "get"
| "put"
| "post"
| "delete"
| "options"
| "head"
| "patch"
| "trace";OpenAPISpecOperation interface
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
Signature
interface OpenAPISpecParameter {
description?: string;
in: "header" | "query" | "cookie" | "path";
name: string;
required: boolean;
schema: JsonSchema;
}OpenAPISpecPathItem type
Signature
type OpenAPISpecPathItem = { [K in OpenAPISpecMethodName]: OpenAPISpecOperation };OpenAPISpecPaths type
Signature
type OpenAPISpecPaths = Record<string, OpenAPISpecPathItem>;OpenAPISpecRequestBody interface
Signature
interface OpenAPISpecRequestBody {
content: OpenApiSpecContent;
required: true;
}OpenApiSpecResponse interface
Signature
interface OpenApiSpecResponse {
content?: OpenApiSpecContent;
description: string;
}OpenAPISpecResponses type
Signature
type OpenAPISpecResponses = Record<number, OpenApiSpecResponse>;OpenAPISpecServer interface
Signature
interface OpenAPISpecServer {
description?: string;
url: string;
variables?: Record<string, OpenAPISpecServerVariable>;
}OpenAPISpecServerVariable interface
Signature
interface OpenAPISpecServerVariable {
default: string;
description?: string;
enum?: [string, ...Array<string>];
}OpenAPISpecTag interface
Signature
interface OpenAPISpecTag {
description?: string;
externalDocs?: OpenAPISpecExternalDocs;
name: string;
}
Transforms the generated OpenAPI specification