contractdiff/openapi-typescript
Every export of contractdiff/openapi-typescript, with its signature and doc comment: openapiTS, astToString, COMMENT_HEADER, createRef, isEnumSchema, makeApiPathsEnum and 12 more, plus 2 types.
import openapiTS from 'contractdiff/openapi-typescript';
import { astToString, COMMENT_HEADER, createRef, … } from 'contractdiff/openapi-typescript';Functions
default
The default export, declared as openapiTS.
Converts an OpenAPI 3.x document to TypeScript, as the text openapi-typescript 7.13.0 writes.
function openapiTS(source: Source, options?: GenerateOptions): Promise<string>;| Parameter | Type |
|---|---|
source | Source |
options (optional) | GenerateOptions |
Returns Promise<string>
Constants
astToString
Prints what openapiTS returned. It is already text.
const astToString: (value: unknown) => string;COMMENT_HEADER
The comment upstream's CLI writes above the generated types. generate does not add it.
const COMMENT_HEADER = "/**\n * This file was auto-generated by openapi-typescript.\n * Do not make direct changes to the file.\n */\n\n";createRef
Join parts into one pointer. A part that is itself a pointer contributes its tokens.
const createRef: (parts: readonly (string | number | undefined)[]) => string;isEnumSchema
Whether a schema is an enum that enum: true turns into a TypeScript enum of its own, so that
rootTypes must not also export an alias under the same name.
const isEnumSchema: (schema: unknown) => boolean;makeApiPathsEnum
The ApiPaths enum of a Paths Object.
const makeApiPathsEnum: (paths: unknown) => string;resolveRef
What a local reference points at, following references to references; undefined when it leads nowhere.
const resolveRef: (document: unknown, ref: string, visited?: ReadonlySet<string>) => unknown;scanDiscriminators
Every discriminator in document. The document is changed: mapped schemas gain their enum property.
const scanDiscriminators: (document: unknown) => Discriminators;transformComponentsObject
The Components Object, and the root aliases after it when rootTypes is on.
const transformComponentsObject: (components: unknown, ctx: Context) => string;transformHeaderObject
One Header Object.
const transformHeaderObject: (header: unknown, options: TransformOptions) => string;transformOperationObject
One Operation Object: its parameters, requestBody and responses members.
const transformOperationObject: (operation: unknown, options: TransformOptions) => string;transformPathItemObject
One Path Item Object.
const transformPathItemObject: (pathItem: unknown, options: TransformOptions) => string;transformPathsObject
The Paths Object.
const transformPathsObject: (paths: unknown, ctx: Context) => string;transformRequestBodyObject
One Request Body Object.
const transformRequestBodyObject: (requestBody: unknown, options: TransformOptions) => string;transformResponseObject
One Response Object.
const transformResponseObject: (response: unknown, options: TransformOptions) => string;transformSchema
The whole file for a document, under a context the caller built: discriminators are not scanned here.
const transformSchema: (root: unknown, ctx: Context) => string;transformSchemaObject
The schema type of one Schema Object.
const transformSchemaObject: (schema: unknown, options: TransformOptions) => string;transformWebhooksObject
The Webhooks Object.
const transformWebhooksObject: (webhooks: unknown, ctx: Context) => string;Interfaces
OpenAPITSOptions
openapi-typescript's data-only options, under the same names and defaults.
interface GenerateOptions {
/** Treat every object as open: add `[key: string]: unknown`. */
readonly additionalProperties?: boolean;
/** Sort members by name instead of keeping document order. */
readonly alphabetize?: boolean;
/** Turn `minItems`/`maxItems` into tuple types. */
readonly arrayLength?: boolean;
/** A property with a `default` is not optional. On by default. */
readonly defaultNonNullable?: boolean;
/** An object with no members is `Record<string, unknown>` instead of `Record<string, never>`. */
readonly emptyObjectsUnknown?: boolean;
/** Emit TypeScript enums instead of string unions. */
readonly enum?: boolean;
/** Emit each enum's values as an exported array. */
readonly enumValues?: boolean;
/** With `enum`, only convert schemas that carry `x-enum-*` metadata. */
readonly conditionalEnums?: boolean;
/** With `enum`, emit each distinct set of members once. */
readonly dedupeEnums?: boolean;
/** Leave deprecated members out. */
readonly excludeDeprecated?: boolean;
/** Emit `type` aliases instead of interfaces. */
readonly exportType?: boolean;
/** Mark every member and array `readonly`. */
readonly immutable?: boolean;
/** Emit an alias per component at the top level. */
readonly rootTypes?: boolean;
/** With `rootTypes`, drop the `Schema` prefix. */
readonly rootTypesNoSchemaPrefix?: boolean;
/** With `rootTypes`, keep schema names as written. */
readonly rootTypesKeepCasing?: boolean;
/** Key parameterised paths by a template literal type. */
readonly pathParamsAsTypes?: boolean;
/** A schema without `required` requires every property. */
readonly propertiesRequiredByDefault?: boolean;
/** Emit an `ApiPaths` enum of every path. */
readonly makePathsEnum?: boolean;
/** Add the path parameters a URL names but its operation does not declare. */
readonly generatePathParams?: boolean;
/** Wrap `readOnly`/`writeOnly` properties in `$Read<>`/`$Write<>`. */
readonly readWriteMarkers?: boolean;
/** TypeScript written above the generated types, as given: upstream parses and re-prints it. */
readonly inject?: string;
}Types
Source
What openapiTS reads: a parsed document, YAML or JSON text, a file: address, or a stream of text.
type Source = string | URL | Buffer | Readable | object;