Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ frontend TypeScript client, `nextjs-frontend`.
The backend and the frontend are versioned together, that is, they have the same version number.
When you update the backend, you should also update the frontend to the same version.

## 0.0.7 <small>October 24, 2025</small> {id="0.0.7"}

- Upgrade @hey-api/openapi-ts version to ^0.83.1

## 0.0.6 <small>September 1, 2025</small> {id="0.0.6"}

- Upgrade Next.js version to 15.5.0
Expand Down
24 changes: 24 additions & 0 deletions nextjs-frontend/app/openapi-client/client.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file is auto-generated by @hey-api/openapi-ts

import type { ClientOptions } from "./types.gen";
import {
type ClientOptions as DefaultClientOptions,
type Config,
createClient,
createConfig,
} from "./client";

/**
* The `createClientConfig()` function will be called on client initialization
* and the returned object will become the client's initial configuration.
*
* You may want to initialize your client this way instead of calling
* `setConfig()`. This is useful for example if you're using Next.js
* to ensure your client always has the correct values.
*/
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> =
(
override?: Config<DefaultClientOptions & T>,
) => Config<Required<DefaultClientOptions> & T>;

export const client = createClient(createConfig<ClientOptions>());
163 changes: 163 additions & 0 deletions nextjs-frontend/app/openapi-client/client/client.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// This file is auto-generated by @hey-api/openapi-ts

import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from "axios";
import axios from "axios";

import { createSseClient } from "../core/serverSentEvents.gen";
import type { HttpMethod } from "../core/types.gen";
import { getValidRequestBody } from "../core/utils.gen";
import type { Client, Config, RequestOptions } from "./types.gen";
import {
buildUrl,
createConfig,
mergeConfigs,
mergeHeaders,
setAuthParams,
} from "./utils.gen";

export const createClient = (config: Config = {}): Client => {
let _config = mergeConfigs(createConfig(), config);

let instance: AxiosInstance;

if (_config.axios && !("Axios" in _config.axios)) {
instance = _config.axios;
} else {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { auth, ...configWithoutAuth } = _config;
instance = axios.create(configWithoutAuth);
}

const getConfig = (): Config => ({ ..._config });

const setConfig = (config: Config): Config => {
_config = mergeConfigs(_config, config);
instance.defaults = {
...instance.defaults,
..._config,
// @ts-expect-error
headers: mergeHeaders(instance.defaults.headers, _config.headers),
};
return getConfig();
};

const beforeRequest = async (options: RequestOptions) => {
const opts = {
..._config,
...options,
axios: options.axios ?? _config.axios ?? instance,
headers: mergeHeaders(_config.headers, options.headers),
};

if (opts.security) {
await setAuthParams({
...opts,
security: opts.security,
});
}

if (opts.requestValidator) {
await opts.requestValidator(opts);
}

if (opts.body !== undefined && opts.bodySerializer) {
opts.body = opts.bodySerializer(opts.body);
}

const url = buildUrl(opts);

return { opts, url };
};

// @ts-expect-error
const request: Client["request"] = async (options) => {
// @ts-expect-error
const { opts, url } = await beforeRequest(options);
try {
// assign Axios here for consistency with fetch
const _axios = opts.axios!;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { auth, ...optsWithoutAuth } = opts;
const response = await _axios({
...optsWithoutAuth,
baseURL: opts.baseURL as string,
data: getValidRequestBody(opts),
headers: opts.headers as RawAxiosRequestHeaders,
// let `paramsSerializer()` handle query params if it exists
params: opts.paramsSerializer ? opts.query : undefined,
url,
});

let { data } = response;

if (opts.responseType === "json") {
if (opts.responseValidator) {
await opts.responseValidator(data);
}

if (opts.responseTransformer) {
data = await opts.responseTransformer(data);
}
}

return {
...response,
data: data ?? {},
};
} catch (error) {
const e = error as AxiosError;
if (opts.throwOnError) {
throw e;
}
// @ts-expect-error
e.error = e.response?.data ?? {};
return e;
}
};

const makeMethodFn =
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
request({ ...options, method });

const makeSseFn =
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
const { opts, url } = await beforeRequest(options);
return createSseClient({
...opts,
body: opts.body as BodyInit | null | undefined,
headers: opts.headers as Record<string, string>,
method,
// @ts-expect-error
signal: opts.signal,
url,
});
};

return {
buildUrl,
connect: makeMethodFn("CONNECT"),
delete: makeMethodFn("DELETE"),
get: makeMethodFn("GET"),
getConfig,
head: makeMethodFn("HEAD"),
instance,
options: makeMethodFn("OPTIONS"),
patch: makeMethodFn("PATCH"),
post: makeMethodFn("POST"),
put: makeMethodFn("PUT"),
request,
setConfig,
sse: {
connect: makeSseFn("CONNECT"),
delete: makeSseFn("DELETE"),
get: makeSseFn("GET"),
head: makeSseFn("HEAD"),
options: makeSseFn("OPTIONS"),
patch: makeSseFn("PATCH"),
post: makeSseFn("POST"),
put: makeSseFn("PUT"),
trace: makeSseFn("TRACE"),
},
trace: makeMethodFn("TRACE"),
} as Client;
};
23 changes: 23 additions & 0 deletions nextjs-frontend/app/openapi-client/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This file is auto-generated by @hey-api/openapi-ts

export type { Auth } from "../core/auth.gen";
export type { QuerySerializerOptions } from "../core/bodySerializer.gen";
export {
formDataBodySerializer,
jsonBodySerializer,
urlSearchParamsBodySerializer,
} from "../core/bodySerializer.gen";
export { buildClientParams } from "../core/params.gen";
export { createClient } from "./client.gen";
export type {
Client,
ClientOptions,
Config,
CreateClientConfig,
Options,
OptionsLegacyParser,
RequestOptions,
RequestResult,
TDataShape,
} from "./types.gen";
export { createConfig } from "./utils.gen";
Loading
Loading