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
120 changes: 87 additions & 33 deletions vue/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
"devDependencies": {
"@chromatic-com/storybook": "^5.2.1",
"@hey-api/openapi-ts": "^0.96.0",
"@hey-api/openapi-ts": "^0.99.0",
"@playwright/test": "^1.62.1",
"@storybook/addon-a11y": "^10.4.6",
"@storybook/addon-docs": "^10.4.6",
Expand Down Expand Up @@ -155,6 +155,9 @@
],
"overrides": {
"minimatch": "10.2.3",
"@parcel/watcher": "^2.6.0"
"@parcel/watcher": "^2.6.0",
"@hey-api/json-schema-ref-parser": {
"js-yaml": "^4.3.2"
}
}
}
17 changes: 6 additions & 11 deletions vue/src/demo/openapi/client.gen.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import type { ClientOptions } from './types.gen'
import {
type Config,
type ClientOptions as DefaultClientOptions,
createClient,
createConfig,
} from './client'
import { type Client, type ClientOptions, type Config, createClient, createConfig } from './client'
import type { ClientOptions as ClientOptions2 } from './types.gen'

/**
* The `createClientConfig()` function will be called on client initialization
Expand All @@ -16,8 +11,8 @@ import {
* `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 type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (
override?: Config<ClientOptions & T>
) => Config<Required<ClientOptions> & T>

export const client = createClient(createConfig<ClientOptions>())
export const client: Client = createClient(createConfig<ClientOptions2>())
27 changes: 17 additions & 10 deletions vue/src/demo/openapi/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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'

Expand Down Expand Up @@ -34,7 +35,13 @@ export const createClient = (config: Config = {}): Client => {
return getConfig()
}

const beforeRequest = async (options: RequestOptions) => {
const beforeRequest = async <
TData = unknown,
ThrowOnError extends boolean = boolean,
Url extends string = string,
>(
options: RequestOptions<TData, ThrowOnError, Url>
) => {
const opts = {
..._config,
...options,
Expand All @@ -43,17 +50,14 @@ export const createClient = (config: Config = {}): Client => {
}

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

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

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

Expand All @@ -64,7 +68,6 @@ export const createClient = (config: Config = {}): Client => {

// @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
Expand All @@ -73,8 +76,8 @@ export const createClient = (config: Config = {}): Client => {
const { auth, ...optsWithoutAuth } = opts
const response = await _axios({
...optsWithoutAuth,
baseURL: opts.baseURL as string,
data: opts.body,
baseURL: '', // the baseURL is already included in `url`
data: getValidRequestBody(opts),
headers: opts.headers as RawAxiosRequestHeaders,
// let `paramsSerializer()` handle query params if it exists
params: opts.paramsSerializer ? opts.query : undefined,
Expand Down Expand Up @@ -118,14 +121,18 @@ export const createClient = (config: Config = {}): Client => {
body: opts.body as BodyInit | null | undefined,
headers: opts.headers as Record<string, string>,
method,
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
// @ts-expect-error
signal: opts.signal,
url,
})
}

const _buildUrl: Client['buildUrl'] = (options) =>
buildUrl({ axios: instance, ..._config, ...options })

return {
buildUrl,
buildUrl: _buildUrl,
connect: makeMethodFn('CONNECT'),
delete: makeMethodFn('DELETE'),
get: makeMethodFn('GET'),
Expand Down
4 changes: 3 additions & 1 deletion vue/src/demo/openapi/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ export {
urlSearchParamsBodySerializer,
} from '../core/bodySerializer.gen'
export { buildClientParams } from '../core/params.gen'
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen'
export type { ServerSentEventsResult } from '../core/serverSentEvents.gen'
export type { ClientMeta } from '../core/types.gen'
export { createClient } from './client.gen'
export type {
Client,
ClientOptions,
Config,
CreateClientConfig,
Options,
OptionsLegacyParser,
RequestOptions,
RequestResult,
TDataShape,
Expand Down
Loading
Loading