Skip to main content

OpenApiGenerateContext

Shared mutable context object threaded through every mapper call during a single OpenApiDocumentFactory.generate() run. Holds the target version, the components.schemas map being filled in, name-collision bookkeeping, and the warnings list.

import { OpenApiGenerateContext } from '@opra/openapi';

This class is used internally by OpenApiDocumentFactory. You only need it directly if you are writing custom mapper extensions.


Constructor​

new OpenApiGenerateContext(options?: { version?: '3.0' | '3.1'; scope?: string })
ParameterTypeDefaultDescription
version'3.0' | '3.1''3.0'Target OpenAPI version.
scopestringundefinedScope filter applied to types and fields.

Properties​

PropertyTypeDescription
version'3.0' | '3.1'The target OpenAPI version.
scopestring | undefinedThe scope filter.
schemasRecord<string, OpenApi.SchemaObject>The components.schemas map being built.
warningsstring[]Warnings accumulated during generation.

Methods​

getSchemaName(dataType)​

getSchemaName(dataType: DataType): string | undefined

Returns the $ref-safe component name for a named DataType, registering it on first use and deduplicating collisions by appending a numeric suffix. Returns undefined for anonymous types — callers inline those instead of referencing.

hasSchema(name)​

hasSchema(name: string): boolean

Returns true if a schema with the given name is already registered in components.schemas.

warn(message)​

warn(message: string): void

Appends a warning string to the warnings array.