@zerolith/client/generate
Import from @zerolith/client/generate. Generated from the source; every signature below is what the published types declare.
Functions
generateClient
function generateClient(document: OpenApiDocument, options?: GenerateOptions): stringGenerates the contract module for an OpenAPI 3.x document given as a
parsed object (JSON; convert YAML first). Schemas under
components.schemas become exported types, every operation becomes an
entry of the Api interface named by its operationId (or by its
method and path), and routes carries the method and path of each.
Header and cookie parameters, security, and non-local references are
left out; the client sends headers through its options. A schema whose
type name would clash is written under the first free name with a
number added, as Record2, with a comment that says why, and every
$ref to it uses that name: one that another schema takes first, as
note-item and note_item both give NoteItem, one named like the
interface of the operations or the RouteTable the module imports, and
one named like a built-in type the module writes, such as Record for
an object of free keys or Blob for a binary response. A schema named
like a built-in the module does not write keeps its name.
Source: packages/client/src/generate.ts:669
Interfaces
SchemaObject
interface SchemaObjectA JSON Schema object as OpenAPI 3.1 and later carry it (draft 2020-12 plus the OAS vocabulary).
$ref?: string: A reference to#/components/schemas/<name>, rendered as that component's generated type, intersected with the keywords beside it that shape a type, such asproperties, as OpenAPI 3.1 allows; any other target fails generation.type?: string | string[]: The JSON type, or since OpenAPI 3.1 an array of types rendered as a union;integerrenders asnumber, and when it is absent the object or array keywords imply one, else the type isunknown.nullable?: boolean: The OpenAPI 3.0 flag that also allowsnull; whentrue,nulljoins the type.enum?: unknown[]: The allowed values, rendered as a union of their literal types; it takes precedence overtype, and intersects with a composition keyword or$refbeside it.const?: unknown: The single allowed value (OpenAPI 3.1 and later), rendered as its literal type; it takes precedence overenumandtype, and intersects with a composition keyword or$refbeside it.properties?: Record<string, SchemaObject>: The object's properties, each generated as a member that is optional unlessrequiredlists it, with the property'sdescriptionas its doc comment.required?: string[]: The names inpropertiesthat must be present; every other property is generated as optional.additionalProperties?: boolean | SchemaObject: The schema of keys beyondproperties, rendered as aRecord<string, ...>joined to them with&;trueallowsunknownvalues, andfalsemakes an object without propertiesRecord<string, never>.items?: SchemaObject: The schema of each array element, rendered asT[], orunknown[]without it; besideprefixItemsit types the elements after the tuple.prefixItems?: SchemaObject[]: The schemas of the leading array elements by position (OpenAPI 3.1 and later), rendered as a tuple; withoutitemsthe tuple has no rest element.oneOf?: SchemaObject[]: Alternatives of which exactly one matches, rendered as a union; it takes precedence overanyOfandallOf, and the keywords beside it that shape a type, such asproperties, intersect with it.anyOf?: SchemaObject[]: Alternatives of which at least one matches, rendered as a union unlessoneOfis present; the keywords beside it that shape a type, such asproperties, intersect with it.allOf?: SchemaObject[]: Schemas that all match, rendered as an intersection unlessoneOforanyOfis present; the keywords beside it that shape a type, such asproperties, join the intersection.description?: string: Becomes the doc comment on a component schema's generated type, ahead oftitle, and on an object property's member.title?: string: The doc comment on a component schema's generated type whendescriptionis absent; the type's name comes from the component's key, not fromtitle.
Source: packages/client/src/generate.ts:8
ParameterObject
interface ParameterObjectA Parameter Object or a reference to one.
$ref?: string: A reference to#/components/parameters/<name>, which replaces this object; any other target, or a missing one, fails generation.name?: string: The member's key in the generatedparamsorquery, matching the{name}placeholder for a path parameter; a parameter withoutnameorinfails generation.in?: "query" | "querystring" | "header" | "path" | "cookie": Where the parameter travels:pathfillsparams,queryadds a member toquery,querystring(OpenAPI 3.2) letsquerytake any key, andheaderandcookieare left out.required?: boolean: Makes a query parameter's member, and the wholequeryinput, required; path parameters are generated as required either way, since OpenAPI demandstruefor them.description?: string: The doc comment on the parameter's generated member.schema?: SchemaObject: The schema of the value, rendered as the member's type; without it orcontent, the type isunknown.content?: Record<string, MediaTypeObject>: The single media type entry OpenAPI allows in place ofschema; whenschemais absent, the entry'sschemagives the member's type.
Source: packages/client/src/generate.ts:43
MediaTypeObject
interface MediaTypeObjectA Media Type Object.
schema?: SchemaObject: The content's schema, read for a JSON media type in a body and for any media type in a parameter'scontent; when absent, the type isunknown.
Source: packages/client/src/generate.ts:62
RequestBodyObject
interface RequestBodyObjectA Request Body Object or a reference to one.
$ref?: string: A reference to#/components/requestBodies/<name>, which replaces this object; any other target, or a missing one, fails generation.description?: string: A brief description of the body; the generator does not carry it into the output.required?: boolean: Makes the generatedbodyinput required; OpenAPI's default isfalse, which generates it as optional.content?: Record<string, MediaTypeObject>: The body by media type, where a JSON type takes precedence and gives its schema's type; otherwisemultipart/form-datagivesFormData,application/x-www-form-urlencodedgivesURLSearchParams,text/*givesstring, and any other type givesBodyInit.
Source: packages/client/src/generate.ts:69
ResponseObject
interface ResponseObjectA Response Object or a reference to one.
$ref?: string: A reference to#/components/responses/<name>, which replaces this object; any other target, or a missing one, fails generation.description?: string: A description of the response; the generator does not carry it into the output.content?: Record<string, MediaTypeObject>: The response body by media type: a JSON type, when present, gives its schema's type,text/*givesstring, any other type givesBlob, as the client reads it, and no content givesundefined.
Source: packages/client/src/generate.ts:82
OperationObject
interface OperationObjectAn Operation Object.
operationId?: string: Names the operation's entry inApiandroutes, in camelCase; without it the name comes from the method and path, such asputNotesByIdforPUT /notes/{id}, and two entries with one name fail generation.summary?: string: The first paragraph of the doc comment on the operation's entry inApi.description?: string: Followssummaryin the doc comment on the operation's entry inApi.deprecated?: boolean: Whentrue, the doc comment on the operation's entry ends with@deprecated.parameters?: ParameterObject[]: The operation's parameters, merged with the path item's; one with the samenameandinas a path item parameter replaces it.requestBody?: RequestBodyObject: The request body, generated as the entry'sbodyinput; without it the entry has nobody.responses?: Record<string, ResponseObject>: The responses by status code;outputis the union of every 2xx response, including2XX, or ofdefaultwhen there is none, andunknownwithout either.
Source: packages/client/src/generate.ts:93
PathItemObject
interface PathItemObjectA Path Item Object.
$ref?: string: A reference to#/components/pathItems/<name>, which replaces this item; any other target, or a missing one, fails generation.summary?: string: A summary meant for every operation on the path; the generator does not carry it into the output.description?: string: A description meant for every operation on the path; the generator does not carry it into the output.parameters?: ParameterObject[]: Parameters shared by every operation on the path; an operation's own parameter with the samenameandinreplaces one.get?: OperationObject: TheGEToperation on this path.put?: OperationObject: ThePUToperation on this path.post?: OperationObject: ThePOSToperation on this path.delete?: OperationObject: TheDELETEoperation on this path.options?: OperationObject: TheOPTIONSoperation on this path.head?: OperationObject: TheHEADoperation on this path.patch?: OperationObject: ThePATCHoperation on this path.trace?: OperationObject: TheTRACEoperation on this path.query?: OperationObject: TheQUERYoperation on this path (OpenAPI 3.2): a safe, idempotent request that carries a body.additionalOperations?: Record<string, OperationObject>: Operations for other HTTP methods (OpenAPI 3.2), keyed by method name such asCOPY; each key is lowercased, and one that is not a valid method token fails generation.
Source: packages/client/src/generate.ts:112
OpenApiDocument
interface OpenApiDocumentThe parts of an OpenAPI document the generator reads.
openapi: string: The OpenAPI version, such as3.1.0; a value that does not start with3.fails generation.info?: { title?: string; version?: string }: The API's title and version, which the generated file's header comment names as its source.paths?: Record<string, PathItemObject>: Path templates mapped to their items; every operation under them becomes an entry ofApiandroutes, sorted by path.components?: { schemas?: Record<string, SchemaObject>; parameters?: Record<string, ParameterObject>; requestBodies?: Record<string, RequestBodyObject>; responses?: Record<string, ResponseObject>; pathItems?: Record<string, PathItemObject> }: Reusable objects: each entry ofschemasbecomes an exported type named after its key, and$refvalues resolve into the other sections.
Source: packages/client/src/generate.ts:145
GenerateOptions
interface GenerateOptionsOptions for generateClient.
clientSpecifier?: string: The module the generated file importsRouteTablefrom. Defaults to@zerolith/client.apiName?: string: The name of the generated contract interface. Defaults toApi.
Source: packages/client/src/generate.ts:164