Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion openapi/client.gen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import {
type Client,
type ClientOptions,
type Config,
createClient,
Expand All @@ -20,6 +21,6 @@ export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (
override?: Config<ClientOptions & T>,
) => Config<Required<ClientOptions> & T>;

export const client = createClient(
export const client: Client = createClient(
createConfig<ClientOptions2>({ baseUrl: "/api" }),
);
2 changes: 2 additions & 0 deletions openapi/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export {
} from "../core/bodySerializer.gen.js";
export { buildClientParams } from "../core/params.gen.js";
export { serializeQueryKeyValue } from "../core/queryKeySerializer.gen.js";
export type { ServerSentEventsResult } from "../core/serverSentEvents.gen.js";
export type { ClientMeta } from "../core/types.gen.js";
export { createClient } from "./client.gen.js";
export type {
Client,
Expand Down
4 changes: 2 additions & 2 deletions openapi/client/utils.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import type {
export const createQuerySerializer = <T = unknown>({
parameters = {},
...args
}: QuerySerializerOptions = {}) => {
const querySerializer = (queryParams: T) => {
}: QuerySerializerOptions = {}): ((queryParams: T) => string) => {
const querySerializer = (queryParams: T): string => {
const search: string[] = [];
if (queryParams && typeof queryParams === "object") {
for (const name in queryParams) {
Expand Down
7 changes: 7 additions & 0 deletions openapi/core/auth.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export interface Auth {
* @default 'header'
*/
in?: "header" | "query" | "cookie";
/**
* A unique identifier for the security scheme.
*
* Defined only when there are multiple security schemes whose `Auth`
* shape would otherwise be identical.
*/
key?: string;
/**
* Header or query parameter name.
*
Expand Down
37 changes: 22 additions & 15 deletions openapi/core/params.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type KeyMap = Map<
}
>;

const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
function buildKeyMap(fields: FieldsConfig, map?: KeyMap): KeyMap {
if (!map) {
map = new Map();
}
Expand All @@ -85,17 +85,18 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
}

return map;
};
}

interface Params {
body: unknown;
body?: unknown;
headers: Record<string, unknown>;
path: Record<string, unknown>;
query: Record<string, unknown>;
}

const stripEmptySlots = (params: Params) => {
function stripEmptySlots(params: Params): void {
for (const [slot, value] of Object.entries(params)) {
if (slot === "body") continue;
if (
value &&
typeof value === "object" &&
Expand All @@ -105,21 +106,29 @@ const stripEmptySlots = (params: Params) => {
delete params[slot as Slot];
}
}
};
}

export const buildClientParams = (
export function buildClientParams(
args: ReadonlyArray<unknown>,
fields: FieldsConfig,
) => {
): Params {
const params: Params = {
body: Object.create(null),
headers: Object.create(null),
path: Object.create(null),
query: Object.create(null),
};

const map = buildKeyMap(fields);

function writeSlot(slot: Slot, key: string, value: unknown): void {
let record = params[slot] as Record<string, unknown> | undefined;
if (record === undefined) {
record = Object.create(null) as Record<string, unknown>;
params[slot] = record;
}
record[key] = value;
}

let config: FieldsConfig[number] | undefined;

for (const [index, arg] of args.entries()) {
Expand All @@ -136,7 +145,7 @@ export const buildClientParams = (
const field = map.get(config.key)!;
const name = field.map || config.key;
if (field.in) {
(params[field.in] as Record<string, unknown>)[name] = arg;
writeSlot(field.in, name, arg);
}
} else {
params.body = arg;
Expand All @@ -148,7 +157,7 @@ export const buildClientParams = (
if (field) {
if (field.in) {
const name = field.map || key;
(params[field.in] as Record<string, unknown>)[name] = value;
writeSlot(field.in, name, value);
} else {
params[field.map] = value;
}
Expand All @@ -159,13 +168,11 @@ export const buildClientParams = (

if (extra) {
const [prefix, slot] = extra;
(params[slot] as Record<string, unknown>)[
key.slice(prefix.length)
] = value;
writeSlot(slot, key.slice(prefix.length), value);
} else if ("allowExtra" in config && config.allowExtra) {
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
if (allowed) {
(params[slot as Slot] as Record<string, unknown>)[key] = value;
writeSlot(slot as Slot, key, value);
break;
}
}
Expand All @@ -178,4 +185,4 @@ export const buildClientParams = (
stripEmptySlots(params);

return params;
};
}
18 changes: 12 additions & 6 deletions openapi/core/pathSerializer.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ interface SerializePrimitiveParam extends SerializePrimitiveOptions {
value: string;
}

export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
export const separatorArrayExplode = (
style: ArraySeparatorStyle,
): "." | ";" | "," | "&" => {
switch (style) {
case "label":
return ".";
Expand All @@ -39,7 +41,9 @@ export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
}
};

export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
export const separatorArrayNoExplode = (
style: ArraySeparatorStyle,
): "," | "|" | "%20" => {
switch (style) {
case "form":
return ",";
Expand All @@ -52,7 +56,9 @@ export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
}
};

export const separatorObjectExplode = (style: ObjectSeparatorStyle) => {
export const separatorObjectExplode = (
style: ObjectSeparatorStyle,
): "." | ";" | "," | "&" => {
switch (style) {
case "label":
return ".";
Expand All @@ -73,7 +79,7 @@ export const serializeArrayParam = ({
value,
}: SerializeOptions<ArraySeparatorStyle> & {
value: unknown[];
}) => {
}): string => {
if (!explode) {
const joinedValues = (
allowReserved ? value : value.map((v) => encodeURIComponent(v as string))
Expand Down Expand Up @@ -113,7 +119,7 @@ export const serializePrimitiveParam = ({
allowReserved,
name,
value,
}: SerializePrimitiveParam) => {
}: SerializePrimitiveParam): string => {
if (value === undefined || value === null) {
return "";
}
Expand All @@ -137,7 +143,7 @@ export const serializeObjectParam = ({
}: SerializeOptions<ObjectSeparatorStyle> & {
value: Record<string, unknown> | Date;
valueOnly?: boolean;
}) => {
}): string => {
if (value instanceof Date) {
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
}
Expand Down
5 changes: 4 additions & 1 deletion openapi/core/queryKeySerializer.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export type JsonValue =
/**
* Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
*/
export const queryKeyJsonReplacer = (_key: string, value: unknown) => {
export const queryKeyJsonReplacer = (
_key: string,
value: unknown,
): unknown | undefined => {
if (
value === undefined ||
typeof value === "function" ||
Expand Down
6 changes: 6 additions & 0 deletions openapi/core/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export interface Config {
responseValidator?: (data: unknown) => Promise<unknown>;
}

/**
* Arbitrary metadata passed through the `meta` request option.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface ClientMeta {}

type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never]
? true
: [T] extends [never | undefined]
Expand Down
11 changes: 7 additions & 4 deletions openapi/core/utils.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ export interface PathSerializer {
url: string;
}

export const PATH_PARAM_RE = /\{[^{}]+\}/g;
export const PATH_PARAM_RE: RegExp = /\{[^{}]+\}/g;

export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
export const defaultPathSerializer = ({
path,
url: _url,
}: PathSerializer): string => {
let url = _url;
const matches = _url.match(PATH_PARAM_RE);
if (matches) {
Expand Down Expand Up @@ -97,7 +100,7 @@ export const getUrl = ({
query?: Record<string, unknown>;
querySerializer: QuerySerializer;
url: string;
}) => {
}): string => {
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
let url = (baseUrl ?? "") + pathUrl;
if (path) {
Expand All @@ -117,7 +120,7 @@ export function getValidRequestBody(options: {
body?: unknown;
bodySerializer?: BodySerializer | null;
serializedBody?: unknown;
}) {
}): unknown {
const hasBody = options.body !== undefined;
const isSerializedBody = hasBody && options.bodySerializer;

Expand Down
Loading
Loading