···11// This file is auto-generated by @hey-api/openapi-ts
2233import {
44- type ClientOptions as DefaultClientOptions,
44+ type ClientOptions,
55 type Config,
66 createClient,
77 createConfig,
88} from './client';
99-import type { ClientOptions } from './types.gen';
99+import type { ClientOptions as ClientOptions2 } from './types.gen';
10101111/**
1212 * The `createClientConfig()` function will be called on client initialization
···1616 * `setConfig()`. This is useful for example if you're using Next.js
1717 * to ensure your client always has the correct values.
1818 */
1919-export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> =
2020- (
2121- override?: Config<DefaultClientOptions & T>,
2222- ) => Config<Required<DefaultClientOptions> & T>;
1919+export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (
2020+ override?: Config<ClientOptions & T>,
2121+) => Config<Required<ClientOptions> & T>;
23222423export const client = createClient(
2525- createConfig<ClientOptions>({
2424+ createConfig<ClientOptions2>({
2625 baseURL: 'https://petstore3.swagger.io/api/v3',
2726 }),
2827);
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+import type { BodySerializer, QuerySerializer } from './bodySerializer.gen';
44+import {
55+ type ArraySeparatorStyle,
66+ serializeArrayParam,
77+ serializeObjectParam,
88+ serializePrimitiveParam,
99+} from './pathSerializer.gen';
1010+1111+export interface PathSerializer {
1212+ path: Record<string, unknown>;
1313+ url: string;
1414+}
1515+1616+export const PATH_PARAM_RE = /\{[^{}]+\}/g;
1717+1818+export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
1919+ let url = _url;
2020+ const matches = _url.match(PATH_PARAM_RE);
2121+ if (matches) {
2222+ for (const match of matches) {
2323+ let explode = false;
2424+ let name = match.substring(1, match.length - 1);
2525+ let style: ArraySeparatorStyle = 'simple';
2626+2727+ if (name.endsWith('*')) {
2828+ explode = true;
2929+ name = name.substring(0, name.length - 1);
3030+ }
3131+3232+ if (name.startsWith('.')) {
3333+ name = name.substring(1);
3434+ style = 'label';
3535+ } else if (name.startsWith(';')) {
3636+ name = name.substring(1);
3737+ style = 'matrix';
3838+ }
3939+4040+ const value = path[name];
4141+4242+ if (value === undefined || value === null) {
4343+ continue;
4444+ }
4545+4646+ if (Array.isArray(value)) {
4747+ url = url.replace(
4848+ match,
4949+ serializeArrayParam({ explode, name, style, value }),
5050+ );
5151+ continue;
5252+ }
5353+5454+ if (typeof value === 'object') {
5555+ url = url.replace(
5656+ match,
5757+ serializeObjectParam({
5858+ explode,
5959+ name,
6060+ style,
6161+ value: value as Record<string, unknown>,
6262+ valueOnly: true,
6363+ }),
6464+ );
6565+ continue;
6666+ }
6767+6868+ if (style === 'matrix') {
6969+ url = url.replace(
7070+ match,
7171+ `;${serializePrimitiveParam({
7272+ name,
7373+ value: value as string,
7474+ })}`,
7575+ );
7676+ continue;
7777+ }
7878+7979+ const replaceValue = encodeURIComponent(
8080+ style === 'label' ? `.${value as string}` : (value as string),
8181+ );
8282+ url = url.replace(match, replaceValue);
8383+ }
8484+ }
8585+ return url;
8686+};
8787+8888+export const getUrl = ({
8989+ baseUrl,
9090+ path,
9191+ query,
9292+ querySerializer,
9393+ url: _url,
9494+}: {
9595+ baseUrl?: string;
9696+ path?: Record<string, unknown>;
9797+ query?: Record<string, unknown>;
9898+ querySerializer: QuerySerializer;
9999+ url: string;
100100+}) => {
101101+ const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
102102+ let url = (baseUrl ?? '') + pathUrl;
103103+ if (path) {
104104+ url = defaultPathSerializer({ path, url });
105105+ }
106106+ let search = query ? querySerializer(query) : '';
107107+ if (search.startsWith('?')) {
108108+ search = search.substring(1);
109109+ }
110110+ if (search) {
111111+ url += `?${search}`;
112112+ }
113113+ return url;
114114+};
115115+116116+export function getValidRequestBody(options: {
117117+ body?: unknown;
118118+ bodySerializer?: BodySerializer | null;
119119+ serializedBody?: unknown;
120120+}) {
121121+ const hasBody = options.body !== undefined;
122122+ const isSerializedBody = hasBody && options.bodySerializer;
123123+124124+ if (isSerializedBody) {
125125+ if ('serializedBody' in options) {
126126+ const hasSerializedBody =
127127+ options.serializedBody !== undefined && options.serializedBody !== '';
128128+129129+ return hasSerializedBody ? options.serializedBody : null;
130130+ }
131131+132132+ // not all clients implement a serializedBody property (i.e. client-axios)
133133+ return options.body !== '' ? options.body : null;
134134+ }
135135+136136+ // plain/text body
137137+ if (hasBody) {
138138+ return options.body;
139139+ }
140140+141141+ // no body was provided
142142+ return undefined;
143143+}
+2-1
examples/openapi-ts-axios/src/client/index.ts
···11// This file is auto-generated by @hey-api/openapi-ts
22+23export * from './sdk.gen';
33-export * from './types.gen';
44+export type * from './types.gen';
+41-26
examples/openapi-ts-axios/src/client/sdk.gen.ts
···11// This file is auto-generated by @hey-api/openapi-ts
2233-import type { Client, Options as ClientOptions, TDataShape } from './client';
44-import { client as _heyApiClient } from './client.gen';
33+import type { Client, Options as Options2, TDataShape } from './client';
44+import { client } from './client.gen';
55import type {
66 AddPetData,
77 AddPetErrors,
···6565export type Options<
6666 TData extends TDataShape = TDataShape,
6767 ThrowOnError extends boolean = boolean,
6868-> = ClientOptions<TData, ThrowOnError> & {
6868+> = Options2<TData, ThrowOnError> & {
6969 /**
7070 * You can provide a client instance returned by `createClient()` instead of
7171 * individual options. This might be also useful if you want to implement a
···81818282/**
8383 * Add a new pet to the store.
8484+ *
8485 * Add a new pet to the store.
8586 */
8687export const addPet = <ThrowOnError extends boolean = false>(
8788 options: Options<AddPetData, ThrowOnError>,
8889) =>
8989- (options.client ?? _heyApiClient).post<
9090- AddPetResponses,
9191- AddPetErrors,
9292- ThrowOnError
9393- >({
9090+ (options.client ?? client).post<AddPetResponses, AddPetErrors, ThrowOnError>({
9491 responseType: 'json',
9592 security: [
9693 {
···108105109106/**
110107 * Update an existing pet.
108108+ *
111109 * Update an existing pet by Id.
112110 */
113111export const updatePet = <ThrowOnError extends boolean = false>(
114112 options: Options<UpdatePetData, ThrowOnError>,
115113) =>
116116- (options.client ?? _heyApiClient).put<
114114+ (options.client ?? client).put<
117115 UpdatePetResponses,
118116 UpdatePetErrors,
119117 ThrowOnError
···135133136134/**
137135 * Finds Pets by status.
136136+ *
138137 * Multiple status values can be provided with comma separated strings.
139138 */
140139export const findPetsByStatus = <ThrowOnError extends boolean = false>(
141140 options: Options<FindPetsByStatusData, ThrowOnError>,
142141) =>
143143- (options.client ?? _heyApiClient).get<
142142+ (options.client ?? client).get<
144143 FindPetsByStatusResponses,
145144 FindPetsByStatusErrors,
146145 ThrowOnError
···158157159158/**
160159 * Finds Pets by tags.
160160+ *
161161 * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
162162 */
163163export const findPetsByTags = <ThrowOnError extends boolean = false>(
164164 options: Options<FindPetsByTagsData, ThrowOnError>,
165165) =>
166166- (options.client ?? _heyApiClient).get<
166166+ (options.client ?? client).get<
167167 FindPetsByTagsResponses,
168168 FindPetsByTagsErrors,
169169 ThrowOnError
···181181182182/**
183183 * Deletes a pet.
184184+ *
184185 * Delete a pet.
185186 */
186187export const deletePet = <ThrowOnError extends boolean = false>(
187188 options: Options<DeletePetData, ThrowOnError>,
188189) =>
189189- (options.client ?? _heyApiClient).delete<
190190+ (options.client ?? client).delete<
190191 DeletePetResponses,
191192 DeletePetErrors,
192193 ThrowOnError
···203204204205/**
205206 * Find pet by ID.
207207+ *
206208 * Returns a single pet.
207209 */
208210export const getPetById = <ThrowOnError extends boolean = false>(
209211 options: Options<GetPetByIdData, ThrowOnError>,
210212) =>
211211- (options.client ?? _heyApiClient).get<
213213+ (options.client ?? client).get<
212214 GetPetByIdResponses,
213215 GetPetByIdErrors,
214216 ThrowOnError
···230232231233/**
232234 * Updates a pet in the store with form data.
235235+ *
233236 * Updates a pet resource based on the form data.
234237 */
235238export const updatePetWithForm = <ThrowOnError extends boolean = false>(
236239 options: Options<UpdatePetWithFormData, ThrowOnError>,
237240) =>
238238- (options.client ?? _heyApiClient).post<
241241+ (options.client ?? client).post<
239242 UpdatePetWithFormResponses,
240243 UpdatePetWithFormErrors,
241244 ThrowOnError
···253256254257/**
255258 * Uploads an image.
259259+ *
256260 * Upload image of the pet.
257261 */
258262export const uploadFile = <ThrowOnError extends boolean = false>(
259263 options: Options<UploadFileData, ThrowOnError>,
260264) =>
261261- (options.client ?? _heyApiClient).post<
265265+ (options.client ?? client).post<
262266 UploadFileResponses,
263267 UploadFileErrors,
264268 ThrowOnError
···281285282286/**
283287 * Returns pet inventories by status.
288288+ *
284289 * Returns a map of status codes to quantities.
285290 */
286291export const getInventory = <ThrowOnError extends boolean = false>(
287292 options?: Options<GetInventoryData, ThrowOnError>,
288293) =>
289289- (options?.client ?? _heyApiClient).get<
294294+ (options?.client ?? client).get<
290295 GetInventoryResponses,
291296 GetInventoryErrors,
292297 ThrowOnError
···304309305310/**
306311 * Place an order for a pet.
312312+ *
307313 * Place a new order in the store.
308314 */
309315export const placeOrder = <ThrowOnError extends boolean = false>(
310316 options?: Options<PlaceOrderData, ThrowOnError>,
311317) =>
312312- (options?.client ?? _heyApiClient).post<
318318+ (options?.client ?? client).post<
313319 PlaceOrderResponses,
314320 PlaceOrderErrors,
315321 ThrowOnError
···325331326332/**
327333 * Delete purchase order by identifier.
334334+ *
328335 * For valid response try integer IDs with value < 1000. Anything above 1000 or non-integers will generate API errors.
329336 */
330337export const deleteOrder = <ThrowOnError extends boolean = false>(
331338 options: Options<DeleteOrderData, ThrowOnError>,
332339) =>
333333- (options.client ?? _heyApiClient).delete<
340340+ (options.client ?? client).delete<
334341 DeleteOrderResponses,
335342 DeleteOrderErrors,
336343 ThrowOnError
···341348342349/**
343350 * Find purchase order by ID.
351351+ *
344352 * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
345353 */
346354export const getOrderById = <ThrowOnError extends boolean = false>(
347355 options: Options<GetOrderByIdData, ThrowOnError>,
348356) =>
349349- (options.client ?? _heyApiClient).get<
357357+ (options.client ?? client).get<
350358 GetOrderByIdResponses,
351359 GetOrderByIdErrors,
352360 ThrowOnError
···358366359367/**
360368 * Create user.
369369+ *
361370 * This can only be done by the logged in user.
362371 */
363372export const createUser = <ThrowOnError extends boolean = false>(
364373 options?: Options<CreateUserData, ThrowOnError>,
365374) =>
366366- (options?.client ?? _heyApiClient).post<
375375+ (options?.client ?? client).post<
367376 CreateUserResponses,
368377 CreateUserErrors,
369378 ThrowOnError
···379388380389/**
381390 * Creates list of users with given input array.
391391+ *
382392 * Creates list of users with given input array.
383393 */
384394export const createUsersWithListInput = <ThrowOnError extends boolean = false>(
385395 options?: Options<CreateUsersWithListInputData, ThrowOnError>,
386396) =>
387387- (options?.client ?? _heyApiClient).post<
397397+ (options?.client ?? client).post<
388398 CreateUsersWithListInputResponses,
389399 CreateUsersWithListInputErrors,
390400 ThrowOnError
···400410401411/**
402412 * Logs user into the system.
413413+ *
403414 * Log into the system.
404415 */
405416export const loginUser = <ThrowOnError extends boolean = false>(
406417 options?: Options<LoginUserData, ThrowOnError>,
407418) =>
408408- (options?.client ?? _heyApiClient).get<
419419+ (options?.client ?? client).get<
409420 LoginUserResponses,
410421 LoginUserErrors,
411422 ThrowOnError
···417428418429/**
419430 * Logs out current logged in user session.
431431+ *
420432 * Log user out of the system.
421433 */
422434export const logoutUser = <ThrowOnError extends boolean = false>(
423435 options?: Options<LogoutUserData, ThrowOnError>,
424436) =>
425425- (options?.client ?? _heyApiClient).get<
437437+ (options?.client ?? client).get<
426438 LogoutUserResponses,
427439 LogoutUserErrors,
428440 ThrowOnError
···433445434446/**
435447 * Delete user resource.
448448+ *
436449 * This can only be done by the logged in user.
437450 */
438451export const deleteUser = <ThrowOnError extends boolean = false>(
439452 options: Options<DeleteUserData, ThrowOnError>,
440453) =>
441441- (options.client ?? _heyApiClient).delete<
454454+ (options.client ?? client).delete<
442455 DeleteUserResponses,
443456 DeleteUserErrors,
444457 ThrowOnError
···449462450463/**
451464 * Get user by user name.
465465+ *
452466 * Get user detail based on username.
453467 */
454468export const getUserByName = <ThrowOnError extends boolean = false>(
455469 options: Options<GetUserByNameData, ThrowOnError>,
456470) =>
457457- (options.client ?? _heyApiClient).get<
471471+ (options.client ?? client).get<
458472 GetUserByNameResponses,
459473 GetUserByNameErrors,
460474 ThrowOnError
···466480467481/**
468482 * Update user resource.
483483+ *
469484 * This can only be done by the logged in user.
470485 */
471486export const updateUser = <ThrowOnError extends boolean = false>(
472487 options: Options<UpdateUserData, ThrowOnError>,
473488) =>
474474- (options.client ?? _heyApiClient).put<
489489+ (options.client ?? client).put<
475490 UpdateUserResponses,
476491 UpdateUserErrors,
477492 ThrowOnError
+4-4
examples/openapi-ts-axios/src/client/types.gen.ts
···11// This file is auto-generated by @hey-api/openapi-ts
2233+export type ClientOptions = {
44+ baseURL: 'https://petstore3.swagger.io/api/v3' | (string & {});
55+};
66+37export type Order = {
48 complete?: boolean;
59 id?: number;
···693697 */
694698 200: unknown;
695699};
696696-697697-export type ClientOptions = {
698698- baseURL: 'https://petstore3.swagger.io/api/v3' | (string & {});
699699-};