OpenApi
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>Signature
declare class Deprecated extends any { constructor();}Signature
declare class Description extends any { constructor();}Signature
declare class Exclude extends any { constructor();}Signature
declare class ExternalDocs extends any { constructor();}Signature
declare class Format extends any { constructor();}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();}Transforms the generated OpenAPI specification
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;}): OpenAPISpecExample
import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "@effect/platform"import { Schema } from "effect"
const api = HttpApi.make("api").add( HttpApiGroup.make("group").add( HttpApiEndpoint.get("get", "/items") .addSuccess(Schema.Array(Schema.String)) ))
const spec = OpenApi.fromApi(api)
console.log(JSON.stringify(spec, null, 2))// Output: OpenAPI specification in JSON formatModels
Signature
type AdditionalPropertiesStrategy = "allow" | "strict"OpenAPIApiKeySecurityScheme
interfaceSignature
interface OpenAPIApiKeySecurityScheme { description?: string; in: "header" | "query" | "cookie"; name: string; readonly type: "apiKey";}OpenAPIComponents
interfaceSignature
interface OpenAPIComponents { schemas: Record<string, JsonSchema.JsonSchema>; securitySchemes: Record<string, OpenAPISecurityScheme>;}OpenAPIHTTPSecurityScheme
interfaceSignature
interface OpenAPIHTTPSecurityScheme { bearerFormat?: string; description?: string; scheme: string; readonly type: "http";}Signature
type OpenAPISecurityRequirement = Record<string, Array<string>>Signature
type OpenAPISecurityScheme = OpenAPIHTTPSecurityScheme | OpenAPIApiKeySecuritySchemeOpenAPISpec
interfaceThis 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
typeSignature
type OpenApiSpecContent = { [K in OpenApiSpecContentType]: OpenApiSpecMediaType }Signature
type OpenApiSpecContentType = "application/json" | "application/xml" | "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain"OpenAPISpecExternalDocs
interfaceSignature
interface OpenAPISpecExternalDocs { description?: string; url: string;}OpenAPISpecInfo
interfaceSignature
interface OpenAPISpecInfo { description?: string; license?: OpenAPISpecLicense; summary?: string; title: string; version: string;}OpenAPISpecLicense
interfaceSignature
interface OpenAPISpecLicense { name: string; url?: string;}OpenApiSpecMediaType
interfaceSignature
interface OpenApiSpecMediaType { schema: JsonSchema;}Signature
type OpenAPISpecMethodName = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace"OpenAPISpecOperation
interfaceSignature
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
interfaceSignature
interface OpenAPISpecParameter { description?: string; in: "header" | "query" | "cookie" | "path"; name: string; required: boolean; schema: JsonSchema;}OpenAPISpecPathItem
typeSignature
type OpenAPISpecPathItem = { [K in OpenAPISpecMethodName]: OpenAPISpecOperation }OpenAPISpecPaths
typeSignature
type OpenAPISpecPaths = Record<string, OpenAPISpecPathItem>OpenAPISpecRequestBody
interfaceSignature
interface OpenAPISpecRequestBody { content: OpenApiSpecContent; required: true;}OpenApiSpecResponse
interfaceSignature
interface OpenApiSpecResponse { content?: OpenApiSpecContent; description: string;}OpenAPISpecResponses
typeSignature
type OpenAPISpecResponses = Record<number, OpenApiSpecResponse>OpenAPISpecServer
interfaceSignature
interface OpenAPISpecServer { description?: string; url: string; variables?: Record<string, OpenAPISpecServerVariable>;}OpenAPISpecServerVariable
interfaceSignature
interface OpenAPISpecServerVariable { default: string; description?: string; enum?: [string, ...Array<string>];}OpenAPISpecTag
interfaceSignature
interface OpenAPISpecTag { description?: string; externalDocs?: OpenAPISpecExternalDocs; name: string;}